Recently hand a small project let me contact with PHP programming, simple landing function has been OK. But in actual use when found a problem: User A To send a link to the user B,b open page prompts landing, but after the successful landing, but jump to the home page, not a send link. In order to have a better user experience, B Landing after the successful should automatically jump to the link before landing. Check the PHP help manual and use $_server global variables to achieve this functionality.
$_server is a super global variable for PHP, and a detailed explanation of $_server variables can be referred to: http://www.php.net/manual/zh/reserved.variables.server.php
The realization method is: When prompts the user to log in, in the session or the Cookie records the request page the URL, after the login authentication succeeds jumps back to this URL.
checklogin.php
Copy Code code as follows:
Session_Start ();
if (!isset ($_session[' LOGIN_OK '))
{
echo "<script language=javascript>alert (' the page to be accessed needs to be logged in first. ');</script> ";
$_session[' userurl '] = $_server[' Request_uri '];
Echo ' <script language=javascript>window.location.href= ' login.php ' </script> ';
}
login.php
Copy Code code as follows:
Session_Start ();
The Account password verification code is omitted here, verify OK and then execute the following code
if (Isset ($_session[' Userurl '))
{
There are pages to jump in the session
$url = $_session[' Userurl '];
}
Else
{
There are no pages to jump, then go to the first page
$url = "home.php";
}
0.5s after jump
echo "<meta http-equiv=\" refresh\ "content=\" 0.5;url= $url \ ">";