1/69
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
• $_SERVER
• $_GET
• $_POST
• $_REQUEST
• $_COOKIE
• $_SESSION
• $_ENV
Superglobal Variables
An array containing information such as headers, paths, and script locations
$_SERVER
entries were created by the web server
$_SERVER
Index 'PHP_SELF' contains the filename of the currently executing script
$_SERVER
Index '__' contains the filename of the currently executing script
PHP_SELF
An associative array variables passed to the current script via the URL parameters
$_GET
An associative array of variables passed to the current script via the HTTP POST method
$_POST
An associative array that by default contains the contents of $_GET, $_POST, and $_COOKIE
$_REQUEST
An associative array of variables passed to the current script via HTTP Cookies
$_COOKIE
An associative array containing session variables available to the script
$_SESSION
An associative array of variables passed to the current script via the environment method
$_ENV
Mechanism for storing data in the remote browser and thus tracking or identifying return users
Cookies
Small amount of information containing variable=value pair (user's computer)
Cookies
Users can refuse to accepts __
cookies
Managing cookies can be done using __ function
setcookie()
bool setcookie ( string $name [, string $value [, int
$expire = 0 [, string $path [, string $domain [, bool
$secure = false [, bool $httponly = false ]]]]]] )
syntax: setcookie()
Mechanism for storing data on the server itself
Session
The time that a user spends at your Web site
Session
More secure than cookies and can store much more information
Session
To open a session, use __ function
session_start()
Always set at the beginning of each Web page
session_start()
To close the session, use __ function
session_destroy()
Gets rid of all the session variable information that's stored in the session file
session_destroy()
The statement does not affect the variables set on the current page
session_destroy()
To unset session variables, use __ function
unset()
unset($_SESSION['varname']);
syntax: unset
Were used to efficiently search for patterns in a given text
Regular Expression
Also known as regex or regexp
Regular Expression
PHP implements __ __ __ __ (PCRE)
Percl Compatible Regular Expression
PCRE function starts with __
preg_
Performs a regular expression match
preg_match() function
int preg_match ( string $pattern , string
$subject [, array &$matches [, int $flags = 0 [, int
$offset = 0 ]]] )
syntax: preg_match()
Marks the start of a string
^
Marks the end of a string
$
Matches any single character
.
Boolean OR
|
Group elements
()
Item range (a, b or c)
[abc]
Not in range (every character except a, b, or c)
[^abc]
white-space character
\s
Zero or one 'a' character. Equals to a{0,1}
a?
Zero or more of 'a'
a*
One or more of 'a'
a+
Exactly two of 'a'
a{2}
Up to five of 'a'
a{,5}
Between five to ten of 'a'
a{5,10}
Any alpha numeric character plus underscore. Equals to [A-Za-z0-9_]
\w
Any non alpha numeric characters
\W
Any white-space character
\s
Any non white-space character
\S
Any digits. Equal to [0-9]
\d
Any non-digits. Equal to [^0-9]
\D
Ignore case
i
Multiline Mode
m
Extra analysis of pattern
S
Pattern is treated as UTF-8
u
It will match the word hello
'/hello/'
It will match hello at the start of a string. Possible matches are hello or helloworld, but not worldhello
'/^hello/'
It will match hello at the end of a string
'/hello$/'
It will match any character between he and o. Possible matches are heloor heyo, but not hello
'/he.o/'
It will match either llo or hello
'/he?llo/'
It will match hello one or more time. E.g. hello or hellohello
'/hello+/'
Matches llo, hello or hehello, but not hellooo
'/he*llo/'
It will either match the word hello or world
'/hello|world/'
Using it with the hyphen character, this pattern will match every uppercase character from A to Z. E.g. A, B, C...
'/(A-Z)/'
It will match any single character a, b or c
'/[abc]/'
Matches precisely one c character after the characters ab. E.g. matches abc, but not abcc
'/abc{1}/'
Matches one or more c character after the characters ab. E.g. matches abcor abcc
'/abc{1,}/'
Matches between two and four c character after the characters ab. E.g. matches abcc, abccc or abcccc, but not abc
'/abc{2,4}/'
<?php
function validate_email($email_address)
{
if( !preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+
([a-zA-Z0-9\._-]+)+$/", $email_address))
{
return false;
}
return true;
}
?>
Email Validation