How to learn the seventh day of php in ten days

Source: Internet
Author: User
Objective: to learn more about the application SESSION of a SESSION, most of which is the transfer of variables between pages on the site. At the beginning of the page, we need session_start (); to enable the SESSION; then we can apply the SESSION variable. for example, to assign a value is $ _

Objective: to learn the application of SESSION

SESSION has many functions, most of which are the variable transfer between pages on the site. At the beginning of the page, we need session_start (); to enable SESSION;
Then the SESSION variable can be applied. for example, the value to be assigned is $ _ SESSION ['item'] = 'item1 '; the value to be obtained is $ item1 = $ _ SESSION ['item'];, which is very simple. Here we may apply some functions. for example, to determine whether a SESSION variable is null, we can write: empty ($ _ SESSION ['inum']) and return true or false.

Next, let's take a look at the above description to check whether the user name and password are correct.
The login form is as follows: login. php
<Table width = '20180101' height = '20180101' border = '0' align = 'center' cellpadding = '0' cellspacing = '0'>
<Tr>
<Form action = 'checklogin. php 'method = 'post'> <td align = 'center' valign = 'middle'> <table width = '000000' 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 case when processing files.
<?
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 like this:
<?
$ Conn = mysql_connect ('2017. 0.0.1 ','','');
Mysql_select_db ('shop ');
?>

Because $ _ SESSION ['adminname'] = $ username; we can write a file to verify whether the statement is logged on: checkadmin. asp.
<?
Session_start ();
If ($ _ SESSION ['adminname'] = '')
{
Echo '<script> alert ('Please Login First'); location. href = 'login. php'; </script> ';
}
?>

Let's talk about how to create a page tomorrow.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.