First, Login Login Verification Steps:
1, assigns the value, uses the $_post to pass the ID and the password to the loginprocess.php login Authentication page.
2. Establish database connection $conn =mysql_connect ($host, $username, $password);
3, select Database mysql_select_db (empmanage);
4. Define SQL statement $sql = "Select password from admin";
5. Execute SQL statements and get results $res =mysql_query ($sql, $conn);
6, the comparison password (conditional statement)
If ($row =mysql_fetch_assco ($res)) {
If ($password = $row [' password ']) {
The validation succeeds and jumps to the specified page.
Header ("Location:emp.php");
Exit ();
}else{
Validation failed, return to landing page.
Header ("Location:login.php?error=1");
Exit ();
}
}
7. Release of resources mysql_free_result ($res);
8, close the connection (can be automatic) mysql_close ($conn);
Second, PHP several principles of writing:
1, where the resources from where to release from
2. Close the connection
3, layered thinking —————— very important.
4, the function can only return one result.
Third, object-oriented programming, packaging common tool classes.
(see php folder)
Four, Cookies Knowledge points
1. How to create a cookie?
The Setcookie () function is used to set cookies.
Note: the Setcookie () function must precede the
Grammar:
Setcookie (name, value, expire, path, domain);
Comments:
2. How do I retrieve the value of a Cookie?
PHP's $_cookie variable is used to retrieve the value of the COOKIE.
Example: In the following example, we use the Isset () function to confirm whether a cookie has been set:
<body>
<?php
if (Isset ($_cookie["user"))
echo "Welcome". $_cookie["User"]. "! <br/> "; The cookie itself is a hyper-global array;
Else
echo "Cookie no longer exists <br/>";
?>
</body>
3, if the input of Chinese, then the browser will be UrlEncode re-encoding, the same can be used to decode UrlDecode.
Example: <?php echo urldecode ("%c9%cf++%ba%a3");?>
Five, Time Zone Issues
Question: Using the date () function in PHP, why is it 8 hours apart from the current local time?
Method One:
Date_default_timezone_set (' PRC ');
no return value. It's OK to use the date function directly below
$time = Date (Y. ") Year ". M." Month ". D." Day ". G. " When ". I." Points ");
Method Two :
Modify php.ini; date.timezone = Date.timezone = "Asia/shanghai" (or change to Date.timezone = PRC) and remove the preceding semicolon and restart Apache.
PHP notes One