Learning Objective: To learn the use of SESSION
SESSION many of the role, with most of the site is within the pages of variable transmission. We must start the page session_start (); Open SESSION;
Then you can use SESSION variables, for example, is assigned to: $ _ SESSION [ ‘item’] = “item1″; need to get value is $ item1 = $ _SESSION [ ‘item’];, it is very simple. Here, we may use some function, for instance, judgement is not a SESSION variable is empty, so to write: empty ($ _SESSION [ ‘inum’]) to return to true or false.
Below the front comprehensive look at what we have a landing procedures, judge the user password is correct.
This form is landing: login.php
<table width=”100%” height=”100%” border=”0″ align=”center” cellpadding=”0″ cellspacing=”0″>
<tr>
<form action=”checklogin.php” method=”post”> <td align=”center” valign=”middle”> <table width = “400″ border = “0″ cellpadding = “5″ cellspacing = “1″ class = “tablebg”>
<tr class=”tdbg”>
<td colspan=”2″> <div align=”center”> Administrators Login </ div> </ td>
</ tr>
<tr class=”tdbg”>
<td> <div align=”center”> Username </ div> </ td>
<td> <div align=”center”>
<input name=”username” type=”text” id=”username”>
</ div> </ td>
</ tr>
<tr class=”tdbg”>
<td> <div align=”center”> Password </ div> </ td>
<td> <div align=”center”>
<input name=”password” type=”password” id=”password”>
</ div> </ td>
</ tr>
<tr class=”tdbg”>
<td colspan=”2″> <div align=”center”>
<input type=”submit” name=”Submit” value=”Submit”>
<input type=”reset” name=”Submit2″ value=”Clear”>
</ div> </ td>
</ tr>
</ table> </ td> </ form>
</ tr>
</ table>
This is the processing of documents
< »
require_once ( ‘conn.php’);
session_start ();
$ username = $ _POST [ ‘username’];
$ password = $ _POST [ ‘password’];
$ exec = “select * from admin where username =’”.$ username .”‘”;
if ($ result = mysql_query ($ exec))
(
if ($ rs = mysql_fetch_object ($ result))
(
if ($ rs-> password == $ password)
(
$ _SESSION [ ‘Adminname’] = $ username;
header ( “location: index.php”);
)
else
(
echo “<script> alert ( ‘Password Check Error!’); location.href = ‘login.php’; </ script>”;
)
)
else
(
echo “<script> alert ( ‘Username Check Error!’); location.href = ‘login.php’; </ script>”;
)
)
else
(
echo “<script> alert ( ‘Database Connection Error!’); location.href = ‘login.php’; </ script>”;
)
«>
conn.php is this:
< »
$ conn = mysql_connect ( “127.0.0.1″, “”, “”);
mysql_select_db ( “shop”);
«>
Because $ _ SESSION [ ‘adminname’] = $ username; written like this we can verify whether the documents landed statement: checkadmin.asp
< »
session_start ();
if ($ _SESSION [ ‘adminname’]==”)
(
echo “<script> alert ( ‘Please Login First’); location.href = ‘login.php’; </ script>”;
)
?>
RSS feed for comments on this post · TrackBack URI
Leave a reply