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>