Jump to content


Check out our Community Blogs

Jmancuso

Member Since 14 Feb 2012
Offline Last Active Apr 05 2015 04:08 AM
-----

#637814 index.php?

Posted by Jmancuso on 05 September 2012 - 06:38 AM

If you're running php from a page it generally needs to have a .php extension. You can use htaccess to run html pages as php, but I don't recommend this because its a needlessly complicated solution.


he answered your question here. For a shorter answer, if you are going to have php in any type of file, you have to use a .php extension or it will not execute the php code properly
  • 1


#622415 Email Validation -- Facebooks Beginnings

Posted by Jmancuso on 22 February 2012 - 03:01 PM

Jmancuso Tutorials

Most of us programmers have scene The Social Network and know about Facebook. In the humble beginning of facebook, you could only have a Harvard.edu email address in order to join "thefacebook.com". But now why couldnt someone just sign up with any email address? This is what i will show you:

Mark Zuckerberg ("creater of facebook") used Pearl as a language of choice, but in this case, i will show you how to do it in PHP.

The built in ereg() and eregi() functions will help you with this. these functions are called regular expressions. Regular expressions in PHP is pretty much its own language inside of PHP and ill tell you why.



//lets say you have an input feild called email

echo "<input type='text' name='email' /> ";

//now to make it a little easier, lets make the html a little more php friendly

$email = $_POST['email'];

//perfect! now lets make a regular expression. pay attention!

$confirmation = ereg("^.+@.+\..+", $email);

//above is the email confirmation, this ensures that the email address should look pretty similar to an email address.
//now lets make an if statement:

if ($confirmation){
//insert all your database insertion here.
}



that is basic email validation. its not that confusing. ill even tell you what it means in human language.
starting in the ereg() function:

the carat(^) simply means look for - the ".+" means all white space and that @ symbol means @. so so far we have "look for all whitespace, and an @ symbol" now after that @ symbol, we have once again the ".+" signs. which of course means all white space. the "\" symbol means literally. so "\." means litterally look for a period. and then you know what the ".+" means.

so in human terms: look for(^) any whitespace (.+), an @ symbol(@), more whitespace(.+), a period (\.) and then more whitespace(.+)"
in display terms it looks for: whitespace@whitespace.whitespace. now obviously this isnt perfect.

we can make it better:
quick definition: ereg() means regular expressions, eregi() means regular expression non case sensitive, so if you want it to looks for [a-z], it would also look for [A-Z]


//this is what mark zuckerberg used when he was writing code for facebook, he used pearl as a language of chocie but this is the php version:

$email = $_POST['email'];
$confirmation = eregi("^.+@harvard.edu", $email);

//means look for(^) any whitespace(.+) @ harvard.edu. its that simple.

//and when he expanded into other universities:
$confirmation = eregi("^.+@( harvard | standford | columbia ).edu", $email);

//by now you should know what the pipe symbol (|) means, it just means OR. like if (a == a || a==b){}


if you want to validate numbers:


$homephone_confirmation = ereg("^[0-9]{0,1}\-?[0-9]{0,2}\-?[0-9]{0,2}\-?[0-9]{0,3}", $homephone);

//this will check a phone number in this order: 1-482-555-9837 and if they do or dont put hyphens, it doesnt matter.
//if you have a confirmation of a city and state like this: Raleigh North Carolina, 11762 (not sure why you would) but:

$address_confirmation = eregi("^[a-z]\,?[a-z]\,?[0-9]{0,4}", $address)
//this will look for that format, and a 5 digit zipcode at the end (im pretty sure all zip codes are 5 digits)


the brackets just mean hope many numbers are expected.

i hope this helps anyone in the future. now that you have the basic understanding of regular expressions, other tutorials will seem much easier.
  • 1


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download