问题描述:

I am in trouble.in my login page i am using ajax.a pop come in my page for login an after authentication using ajax it returns to the same calling page.i am using session for tracking my login.but when i reload the page the session expires which i dont want.i need only session should expires when we close browser.How is it possible to?

part of code i used(from top to bottom)

request code

<?php

error_reporting(E_ALL);

ini_set('display_errors','1');

?>

<?php session_start();

if(isset($_SESSION["manager"]))

{

echo'<script>document.getElementById("accordion").style.display="block";</script>';

}

?>

response code

<?php

error_reporting(E_ALL);

ini_set('display_errors','1');

?>

<?php

if(isset($_GET["uname"])&&isset($_GET["upass"])){

$manager=preg_replace('#[^A-Za-z0-9]#i','',$_GET["uname"]);

$password=preg_replace('#[^A-Za-z0-9]#i','',$_GET["upass"]);

include"connect_to_mysql.php";

$sql=mysql_query("SELECT username FROM login WHERE username='$manager' AND password='$password' LIMIT 1");

$existCount=mysql_num_rows($sql);

if($existCount==1){

/*while($row=mysql_fetch_array($sql)){

$id=$row["id"];

}*/

//$_SESSION["id"]=$id;

$_SESSION["manager"]=$manager;

$_SESSION["password"]=$password;

echo("success");

}

else

{

echo("fail");

}

}

?>

网友答案:

You need to call session_start() at the beginning of both files.

网友答案:

You need to call session_start() at the beginning of both files. If you add session_start() in your connection file, please remove it.

Add it separately in the request code file and the response code file.

相关阅读:
Top