Skip to content

Instantly share code, notes, and snippets.

@MikeRogers0
Created June 10, 2012 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeRogers0/2907496 to your computer and use it in GitHub Desktop.
Save MikeRogers0/2907496 to your computer and use it in GitHub Desktop.
Basic PHP Security
<?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.';
}
?>
<?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