A method in PHP that enables sessions to run across Windows

Source: Internet
Author: User
Tags sessions

This would have been the basic use of the session, but in PHP is not the spirit. However, we can register the session variable as "global variable across Windows." But there is a condition that you want to send a variable named Session_name () with a value of session_id () to a window that needs to use the session variable, using the form or following the URL? Take it with you. and call Session_Start () at the beginning of the page that uses the session variable.

Examples are as follows:

login.php file:



< HTML >
< Head >
< Meta HTTP - equiv = " Content-type " content = " text/html; charset=utf-8. "   />
< title > Landing Screen </ title >
</ Head >
< Body >
< Form Action = " result.php " method = " Post " >
< Table Width = " 100% " Border = " 0 " >
< TR >
< TD Align = " Center " valign = " Middle " >< P > Test System ----- Landing Screen </ P >
< Table Width = " the " style = " border-collapse:collapse border-color: #000000 "
Border = " 1 " cellpadding = " 2 " cellspacing = " 2 " >
< TR >
< TD Width = " 30% " > User : </ TD >
< TD >< Input Name = " username " type = " text " style = " width:150px " /></ TD >
</ TR >
< TR >
< TD > Password : </ TD >
< TD >< Input Name = " Password " type = " Password " style = " width:150px " /></ TD >
</ TR >
< TR >
< TD colspan = " 2 " Align = " Center " >< input type = " Submit " value = " Landing " /></ TD >
</ TR >
</ Table >
</ TD >
</ TR >
</ Table >
</ form >
</ Body >
</ HTML >

result.php file:



< HTML >
< Head >
< Meta HTTP - equiv = " Content-type " content = " text/html; charset=utf-8. "   />
< title > Results Screen </ title >
</ Head >
< Body >
< form method = " Post " >
Welcome you,
? PHP
@ Session_Start ();
if ( isset ( $_post [ " username " ])){
$username   =   Htmlspecialchars ( $_post [ " username " ]);
$_session [ '' username '' ]  =   $username ;
}  Else {
$username   =   $_session [ '' username '' ];
}
Echo   $username ;
?>
< BR />
< BR />
< a href = " login.php " > return </ a >
< a href = " database.php? " . Session_name () . " = " . session_id () . " "> Database Test </a>

</form>
</body>

database.php file:



< HTML >
< Head >
< Meta HTTP - equiv = " Content-type " content = " text/html; charset=utf-8. "   />
< title > Results Screen </ title >
</ Head >
< Body >
< form method = " Post " >
Email:
? PHP
@ Session_Start ();

$conn   = Mssql_pconnect ( '' localhost '' ,   '' SA '' ,   '' SA '' );
mssql_select_db ( '' Netstore '' );
$query   = Mssql_query ( '' SELECT * from CUSTOMER '' ,   $conn );
$name   = Mssql_result ( $query ,   0 ,   '' Email '' );
Echo   $name ;
?>
< BR />
< BR />
< a href = " result.php? " . Session_name () . " = " . session_id () . " "> Return </a>
</form>
</body>




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.