This verifies that cookies are useless.

Source: Internet
Author: User
Tags setcookie
Cookie validation

mysql_select_db ("Dhbase", $conn);
$sql = "SELECT * from Dh_admin where uname= ' $lname ' and upass= ' $ckpass ' and work=1 ';
$result =mysql_query ($sql, $conn);
if (mysql_num_rows ($result) <=0)
{
echo "Incorrect account information";
Exit
}
Else
{
$row =mysql_fetch_array ($result);
$lid = $row ["id"];
$ltime =date (' y-m-d h:i:s ', Time ());
$user _ip=@ ($_server["Http_via")? $_server["Http_x_forwarded_for"]:$_server["REMOTE_ADDR"];
$user _ip= ($user _ip)? $user _ip:$_server["REMOTE_ADDR"];
$lsql = "INSERT into Dh_alog (AID,LOGTIME,LOGIP) VALUES (' $lid ', ' $ltime ', ' $user _ip ')";
if (!mysql_query ($lsql, $conn))
{
Die (' Error: '. mysql_error ());
}
Setcookie ("uname", $lname, Time () +3600);
echo $_cookie["uname"];
echo "";
Exit
}
This login verifies and writes cookie output cookie is also normal
Then jump to index_home.php this page, the page called the verification page admin_chk.php
The code is as follows:
Session_Start ();
if (Isset ($_cookie["uname"))
{
echo $_cookie["uname"];
}
Else
{
echo "";
Exit
}
?>
Did you write this code wrong? I this debugging a login on the warm tip: Your permissions have timed out, please sign in again.
Ask for expert guidance, thank you


Reply to discussion (solution)

There's nothing wrong with the code, how you debug it. Tested with multiple browsers.

There's nothing wrong with the code, how you debug it. Tested with multiple browsers.
Thank you, but does PHP have something to do with the browser?

There's nothing wrong with the code, how you debug it. Tested with multiple browsers.
I changed the IE and Firefox or not the amount
I am directly in the admin_chk.php output $_cookie["uname"] it error said undefined.

What's going on? Oh, I've just learned this strange thing about PHP.

I don't know how your admin_chk.ph code is written.

Cookie path, right?

Header ("content-type:text/html; charset=gb2312 ");
Session_Start ();
if (!isset ($_cookie["uname"))
{
echo "";
Exit
}
?>

This is the admin_chk.php file

Where index_home.php and admin_chk.php are not in a directory
Index_home.asp References:
Include "inc/admin_chk.php"
?>
....


Has the great God eaten yet??

Index_home.php is that point of code, there is not before?

Document layout
index_home.php
inc/admin_chk.php

There are setcookie in inc/admin_chk.php ("uname", $lname, Time () +3600);

Is that right?

So
Setcookie ("uname", $lname, Time () +3600);
Should write
Setcookie ("uname", $lname, Time () +3600, '/');


Index_home.php is that point of code, there is not before?
No, there's some HTML code behind it.



Document layout
index_home.php
inc/admin_chk.php

There are setcookie in inc/admin_chk.php ("uname", $lname, Time () +3600);

Is that right?

So
Setcookie ("uname", $lname, Time () +3600);
Should write
Setcookie ("uname", $lname, Time () +3600, '/');

Setcookie ("uname", $lname, Time () +3600); It was written at the time of login verification login_ck.php.

The login interface is verified by Ajax asynchronous login_ck.php:

Header ("content-type:text/html; charset=gb2312 ");
Session_Start ();
$lname =$_post["Loname"];
if ($lname = = "")
{
echo "Please enter user name";
Exit ();
}
$lpass =$_post["Lopass"];
if ($lpass = = "") {
echo "Please enter password";
Exit ();
}
$lsx =$_post["Losx"];
if ($lsx = = "")
{
echo "Please enter Chitian";
Exit ();
}
if ($lsx! = "Dhsystem")
{
echo "Chitian error";
Exit ();
}
$lcode =strtolower ($_post["Locode"]);
if ($lcode = = "")
{
echo "Please enter the verification code";
Exit ();
}
if ($lcode!=strtolower ($_session["Randcode"))
{
echo "Verification code input error";
Exit ();
}
$ckpass =SUBSTR (MD5 ($lpass), 9,12);
$conn = mysql_connect ("localhost", "root", "*******");
if (! $conn)
{
Die (' Could not connect: '. Mysql_error ());
}
mysql_select_db ("Dhbase", $conn);
$sql = "SELECT * from Dh_admin where uname= ' $lname ' and upass= ' $ckpass ' and work=1 ';
$result =mysql_query ($sql, $conn);
if (mysql_num_rows ($result) <=0)
{
echo "Incorrect account information";
Exit
}
Else
{
$row =mysql_fetch_array ($result);
$lid = $row ["id"];
$ltime =date (' y-m-d h:i:s ', Time ());
$user _ip=@ ($_server["Http_via")? $_server["Http_x_forwarded_for"]:$_server["REMOTE_ADDR"];
$user _ip= ($user _ip)? $user _ip:$_server["REMOTE_ADDR"];
$lsql = "INSERT into Dh_alog (AID,LOGTIME,LOGIP) VALUES (' $lid ', ' $ltime ', ' $user _ip ')";
if (!mysql_query ($lsql, $conn))
{
Die (' Error: '. mysql_error ());
}
Setcookie ("uname", $lname, Time () +3600);
echo $_cookie["uname"];
echo "";
Exit
}

Mysql_close ($conn);
?>

This is login_ck.php.

Didn't your login request to inc/admin_chk.php?
Then the cookies set in inc/admin_chk.php are only valid in the INC directory

BOOL Setcookie (string name [, string value [, int expire [, String path [, string domain [, bool secure]]])

Parameter path
Indicates the valid path of the Cookie on the server side.
If this parameter is set to '/', the cookie is valid throughout domain, and if set to '/foo/', the cookie is only valid in the/foo/directory and its subdirectories under domain, such as/foo/bar/. The default value is the current directory where the cookie is set.



It's really a path problem. I used ASP PHP, this cookie still has a path problem.

Thank you, thank you.

Didn't your login request to inc/admin_chk.php?
Then the cookies set in inc/admin_chk.php are only valid in the INC directory

BOOL Setcookie (string name [, string value [, int expire [, String path [, string domain [, bool secure]]])

Parameter path
Indicates the valid path of the Cookie on the server side.
If this parameter is set to '/', the cookie is valid throughout domain, and if set to '/foo/', the cookie is only valid in the/foo/directory and its subdirectories under domain, such as/foo/bar/. The default value is the current directory where the cookie is set.

Thank you

I've also studied.

  • Related Article

    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.