PHP after landing to jump to the landing page before the realization of ideas and code _php skills

Source: Internet
Author: User
Tags php programming
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 \ ">";

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.