Created
June 10, 2012 22:10
-
-
Save MikeRogers0/2907496 to your computer and use it in GitHub Desktop.
Basic PHP Security
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Input must be a number | |
if(is_numeric($input)){ | |
echo 'Input is a number'; | |
} else { | |
echo 'Input is not a number'; | |
} | |
// Input can only contain numbers and letters. | |
if(preg_match('/([^A-z0-9])/', $input)){ | |
echo 'Input does not contain only numbers and letters.'; | |
} else { | |
echo 'Input contains only numbers and letters.'; | |
} | |
// Input must be an email | |
if(preg_match('/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/', $input)){ | |
echo 'Email Is Valid.'; | |
} else { | |
echo 'Email Is Invalid.'; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); // Start the session. Always put this at the top of your html. | |
// Set some sessions | |
$_SESSION['name'] = 'Example 1'; | |
// echo session data | |
echo $_SESSION['name']; | |
// Would return Example 1 | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment