tags:

views:

69

answers:

4

Hello. I have the following php code:

<?php session_start();
....
$result=$db->query($query);
$row=$result->fetch_assoc();
$_SESSION['id']=$row['id'];
header('Location: http://www.blabla.com/successLoginPage.php');

php code on: successLoginPage.php

<?php session_start();
echo $_SESSION['id'];

Here is problem. When i do all things, i see nothing in successLoginPage.php, after approximately 10 minutes i refresh the page and see correct variable. I tried to clear the cache, ctrl+f5, shutdown the browser and computer, but nothing changes - still need to wait 10 minutes. This problem is exists in chrome and ie8.

How can i solve this problem?

Thanks in advance.

*Edit 1:

I add logout.php page with the following code: session_start();session_destroy();unset($_SESSION); When i log in successfully and receive the proper echo, i push logout link and then log in using another account - all great. 1st question - can i log in via 1st account for the 1st time and via 2nd account for the 2nd time? Is this ok? 2nd question - when i failed to log in, there again i see freeze. If i try to log in with proper account after this, i will see old information about fail login. What i need to do?

A: 

Have you tried session_write_close(); after setting your session variable?

this is unnecessary. session would have been committed when the script terminated at the time of redirection.
stillstanding
still the same :(
dsplatonov
What does `ini_get('register_globals')`; return?
@lotsoffreetime return 1
dsplatonov
A: 

It may be somewhat obvious but... is $row['id'] actually a number/string, not NULL? :p You could try

var_dump($_SESSION['id']);

instead of

echo $_SESSION['id'];
Robus
Thanks for the reply. var_dump showed Null or string(2) "13" (it is id of session). Nothing changes.
dsplatonov
A: 

First of all, you are not showing the entire code and in this case it is very important.

<?php session_start();
....
$result=$db->query($query);
$row=$result->fetch_assoc();
$_SESSION['id']=$row['id'];
header('Location: http://www.blabla.com/successLoginPage.php');
// Mystery ???

When you are calling header('Location: xxx'), it doesn't stop the script, so everything after your header is executed.

You could add the function die to prevent any other code to execute after the redirection.

<?php session_start();
....
$result=$db->query($query);
$row=$result->fetch_assoc();
$_SESSION['id']=$row['id'];
header('Location: http://www.blabla.com/successLoginPage.php');
die(); // No more code executed after this //
HoLyVieR
Thanks for the reply. I used exit() method insted of die - is it the same?
dsplatonov
@dsplatonov yes
HoLyVieR
A: 

Solved the problem. I deleted all login files and rewrite it from scratch and all seems to work now. Don't know where bug was.

dsplatonov