Ten Days Learn the seventh day of PHP

xiaoxiao2021-03-06  37

Learning purpose: Society of sessions

There are many ways to use, and the most used is to transfer variables between the online page. Start in the page We want session_start (); open the session;

Then you can use the session variable, for example, you want to assign a value: $ _ session ['item'] = "item1"; to get the value is $ item1 = $ _ session ['item'] ;. very simple. Here we may use some functions, such as judgment is empty, you can write: Empty ($ _ session ['inum']) Returns true or false.

Let's take a look at us to see if a login program is correct.

The login form is like this: login.php

administrators login

UserName

Password

Processing file is like this

Require_once ('conn.php');

session_start ();

$ usrname = $ _ post ['username "];

$ Password = $ _ post ['password'];

$ exec = "select * from admin where username = '". $ usrname. "'";

IF ($ result = mysql_query))

{

IF ($ r = mysql_fetch_Object ($ result))

{

IF ($ RS-> Password == $ Password)

{

$ _SESSION ['Admin Hang "] = $ usrname;

Header ("Location: Index.php");

}

Else

{

echo "