Phpsession for guidance

Source: Internet
Author: User
Want to be in the user login with the session to retain his user name, while in other PHP text calls, but how to write the wrong, who can guide?


Session_Start ();
Save 6 hours
$lifeTime = 6 * 3600;

Session_register ("Nowuser");
$username = Htmlspecialchars ($_post[' username ');
$nowuser = $username;
$password = $_post[' password ');
$lastdate = Date (' y-m-d ');
Include (' conn.php ');
mysql_query ("Set character set ' GBK '");
mysql_query ("Set names ' GBK '");

$sql = "SELECT * from user where username= '". $username. "' and password= '". $password. "' ";
$check _query=mysql_query ($sql);
$num =mysql_num_rows ($check _query);

if ($num >0)
{
echo "Hello. $username. Welcome to your space!";
echo "The last time you logged in is. $lastdate";
echo "Click to enter";
}
else {
Exit (' Login failed! Click here to return to retry ');
}


Reply to discussion (solution)

This function has been DEPRECATED as of PHP 5.3.0 and removed as of PHP 5.4.0.

Use $_session directly.

And your Session_register ("Nowuser"); , the Nowuser is empty.

My PHP version is still 4. More ....
and Nowuser not accept $username's assignment?

Starting with PHP 4.1.10, the session should be done with the $_session array
Now that you have useful $_post, your PHP version should be at 4.1.10

You only give settings except the session variable, and do not give a read
Session_Start ();
echo $_session[' Nowuser '];

If you want to echo $nowuser directly;
You need to open the register_globals switch

I do not want to read, I would like to in another PHP script to invoke the current login login user name, what to do.

You do not read how to know if the user name exists, what is it?

First use a PHP to receive the submitted form user name and password, if the user name and password are the same in the database, then I would like to Logi. PHP through the session to write down the user name of the user who is logged in, and then in the other PHP text called the user name, to achieve the next step I want to add information to the existing user's database table. Does this idea have a problem with the session? Or I misunderstood the use of the session. If misunderstood, can you provide me with a way to implement this function?

login.php
Save Session Value:
$_session[' uname ' = "admin";


Other page calls
Session_Start ();
echo $_session[' uname '];

I'm going to fill it all up:

Login.php (Save session value)
Session_Start ();
$_session[' uname ' = "admin";


Other page calls (Fetch session value)
Session_Start ();
echo $_session[' uname '];

You can think of Session_Start as opening a browser-scoped global variable $_session ...

Log in check page

 
  0) {$_session[' nowuser ' = $username; echo "Hello $username. Welcome to your space!"; echo "The last time you logged in is. $lastdate"; echo "click to enter";} else {ex It (' Login failed! Click here to return to retry '); }?>


Post-Login page:
 
  

Thank you, upstairs.

I'm going to fill it all up:

Login.php (Save session value)
Session_Start ();
$_session[' uname ' = "admin";


Other page calls (Fetch session value)
Session_Start ();
echo $_session[' uname '];

You can think of Session_Start as opening a browser-scoped global variable $_session ...



Positive solution, knot paste to the point bar

  • 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.