By BoLOBOSE payday loan

Check Email Function PHP

Just recently created this piece of code for dream in codes new framework.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function check_email($email, $rec = 'MX'){
//	1. clean up email
	$email = trim($email);
 
	$v1 = strstr($email, ' ');
	if($v1 != null){
		echo 'There is a space.';
		return false;
	}
//	2. check if it has the proper characters
	list($start, $domain) = split("@", $email);
	if(isset($start) && isset($domain) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email) > 0){
		echo  "good<br>";
 
		// 3. split email into two and check dns
		if(!empty($domain)) {
			if( $rec == '' ) $rec = "MX";
			exec("nslookup -type=$recType $hostName", $result);
			// check each line to find the one that starts with the host
			// name. If it exists then the function succeeded.
			foreach ($result as $line) {
				if(eregi("^$hostName",$line)) {
					echo "hostname is good";
					return true;
 
				}
		}
		// otherwise there was no mail handler for the domain
		return false;
	}return false;
    }return false;
}

The code isn’t exactly rocket science and thus I won’t be leaving you with any more information on this function.

Creating a Multi-Page Site From One Page Using GET

Creating a Multi-Page Site From One Page Using GET from Caleb Jonasson on Vimeo.

Source Code

Download Zip File

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
 
$t = $_GET['t'];
 
if($t == 'contact'){
	echo 'contact page';
}else if($t == 'about'){
	echo 'about page';
}else{
	echo 'index page';
	echo '<br> <a href="?t=about">about</a>';
}
?>

Adding The ‘Like’ Button to WordPress

Plugins can often slow down WordPress’ load times so it best to build into the theme if possible. This is why we are going to run through a quick tutorial were we will be adding a like button to a WordPress theme.

Getting The Like Button Code

The first thing that you are going to need is the like button code itself. I will be providing it for you but if you would like to go and get it yourself there are some more customization options by going to the Facebook developer page.

1
2
3
<iframe src="http://www.facebook.com/widgets/like.php?href=http://skorg.org/"
scrolling="no" frameborder="0"
style="border:none; width:480px; height:80px"></iframe>

Now we need to find a good place for our like button to go. I would recommend placing it below the post so once the user has completed reading through the article they can then like it. If you put it above there is a chance that they are going to miss the button and just move on.

The button is going to be added to the bottom of the post on the single.php page that you can find in your theme directory. Just go to ‘/wp-content/themes/your-theme-name/single.php’.

Now we will simply add the code in and tweak a couple of things so it will work on each page.

1
2
3
<iframe src="http://www.facebook.com/widgets/like.php?href=<?php the_permalink()?>"
scrolling="no" frameborder="0"
style="border:none; width:480px; height:80px"></iframe>

Adding the Code to Your Theme

The code will be inserted and your single page should look something more like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<div class="clear"></div>   
	<div class="meta-entry clear">
		<?php
			//full post
        	the_content(__('read more...', 'skorg-cwd1'));
        ?>
        <iframe src="http://www.facebook.com/widgets/like.php?href=<?php the_permalink()?>"
        scrolling="no" frameborder="0"
        style="border:none; width:480px; height:80px"></iframe>
 
       	<?php edit_post_link(__('Edit!', 'skorg-cwd1')); ?>
        <?php wp_link_pages(); ?>
    </div><!--end entry-->
	<div class="post-footer">

Notes

When inserting the post just look for something call the_content() then simply past the code bellow this and your like button should work without a flaw.

Updates & Ideas for the Future

It’s been a while since I have posted an update to this website since the majority of my time has been put towards iadbs.com, skorg.org and school.
There have been a lot of people that have been after tutorials relating to browser games that are backed by php. Since I have been seeing a lot of this and have received a lot of questions regarding the matter I have decided that I am going to create a series that will allow you to create a game from start to finish.

SQL: One To Many Using Inner Join

In this tutorial will be going through it as though we were about to create a browser game that involves units, players, stats, etc.

How Does an Inner Join Work?

Before we get to far into this and start making our own tables you need to first know how the tables are going to do what they do.  We are going to be using a join to connect two tables, this join is called an inner join, with this join type we will be able to link the tables together on a similar column. In this case it will be an ID.

In this game we are going to be needing some players and some units that they will be able to control. So, from within the units table we will have an id that will match the players id. This will allow us to merge the tables on a specific column.

What Will the Inner Join Tables Look Like?

Before we can get to the inner join table we will first need the players table. This will have a name, password and id. The id will have to be auto incremental in order to keep track of the id’s and keep them all unique.

Now that we have our users table we will need to merge them onto the units table to keep track of what units the player owns. The inner join will be performed on the user_id on the table below to the id on the table above.

Once the tables are merged together you will get the following results.

As you can see the table now consists of multiple players and the units. This method of table construction can be very powerful since you can then do another inner join from the units table to the singular unit table. This will allow you to link the individual health, strength, etc of a unit to the player.

SQL Query of an Inner Join

The sql query looks a little odd when you first look at it but once you go through what is going on you will begin to understand it a lot better.

1
2
3
4
5
SELECT
p.id p_id, p.name p_name,
u.user_id u_user_id, u.unit_id u_unit_id, u.id u_id
FROM players p
INNER JOIN units u ON p_id = u_user_id

You can also select all of the users based on the user id. This will involve using the previous statement but it will just require you to add the “WHERE” statement. Your code will now look like this.

1
2
3
4
5
6
SELECT
p.id p_id, p.name p_name,
u.user_id u_user_id, u.unit_id u_unit_id, u.id u_id
FROM players p
INNER JOIN units u ON p_id = u_user_id
WHERE u_id = '54'

This is now where the true one to many statement happens. one player to many units. And if you actually work on a game like this you can expand onwards and use a one to one unit or many to many using linking tables.

Query One To Many Using PHP

In order to query a one to many using PHP will just need to use the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//store the sql query in the variable $sql
$sql = "SELECT
p.id p_id, p.name p_name,
u.user_id u_user_id, u.unit_id u_unit_id, u.id u_id
FROM players p
INNER JOIN units u ON p_id = u_user_id
WHERE u_id = '2'";
 
//query the database and store the results into $t1. If query fails display the error and kill the page.
$t1 = mysql_query($sql)or die(mysql_error());
 
//This will loop through the results and display them for you
while($row = mysql_fetch_array($t1)){
	echo 'unit id: '.$row['u_unit_id'].'<br>';
}

Additional Notes:

When you are creating the tables keep in mind that every id field should be stored as an integer and should match the limit. If you expect to have a large game down the road make sure that all of your id’s have a length of 11 or 15. That number is up to you but it is best to keep them all at the same length.

Using Sessions To Handle Errors With PHP

Here is a 10 minute video tutorial that is all about handling errors with sessions. It will teach you how to use three simple functions to set and display error messages for your PHP website or application.

Using sessions to handle errors in php from Caleb Jonasson on Vimeo.

Sorry about the styling error, apparently I cannot type.

Demo

Download Source Files

Internet Audio Database

There is a new project that is currently being built. The idea behind the project is to log songs, artists, albums and the people behind them. So far the database is small but if you would like in please contact me through skorg.org. You can also visit the site and see how it is coming along through iadbs.com, internetaudiodatabase.com