Forum Moderators: coopster

Message Too Old, No Replies

mystery session variable check

Just impossible to evaluate it to TRUE

         

dbarasuk

3:22 pm on Jul 7, 2010 (gmt 0)

10+ Year Member



Hello dear friends,

I have a script creating a session on one page. When i move to another page, i used to echo an unordered list after checking that a session variable exists.

Now, that is not only impossible on my PC but also impossible on the hosting server. I cant figure out whats wrong at all

This is how the script looks like:

session_start();
echo '<ul><li><a

href="annonce_definitive.php">Retour aux

annonces</a></li>';
if(isset($_SESSION['user']))
{

if($_SESSION['user'] ==

'dbarasuk')
{
echo "<li><a

href='confirmer_suppression.php?immo_id=".$immo_

id."'>Supprimer cette annonce</a></li>
<li><a

href='annonce_definitive_modifier.php?immo_id=".

$immo_id."'>Modifier cette annonce</a></li>
<li><a

href=logout.php>Log out</a></li>";
}
}
echo "</ul>";
}

The $_SESSION['user'] key is previously created on a login page

The problem is that everything inside the if control structure is totally ignored, but i know that it evaluates to 'TRUE' because if i echo the session key at the very beginning of the page, it echoes faultlessy the value.

Can someone help me please?

Matthew1980

3:35 pm on Jul 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there dbarasuk,

How are you setting the $_SESSION in the first place?

Also would it not be easier to say this with the if clause:-

if(isset($_SESSION['user']) && ($_SESSION['user'] == "dbarasuk")){//or whatever its meant to be :)
echo "its set";
}
else{
echo "it's not set";
}

Other wise, just make sure that the key & values are correctly referenced by using:-

echo "<pre>";
print_r($_SESSION);
echo "</pre>";

Just use that to clear up any typo's in the key names etc ;)

Hope that helps a little.

Cheers,
MRb

dbarasuk

3:39 pm on Jul 7, 2010 (gmt 0)

10+ Year Member



i set up the session variable after the login succeeds and eqwalizing it to the username.

I did your suggestion but things did not improve which is strange since one day ago it worked with no problem. i am starting to think if there is no invisible code preventing from working since i am sending the code online to the server.

Matthew1980

7:52 pm on Jul 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there dbarasuk,

>>one day ago it worked with no problem

Begs the question - what did you do to it, or what has changed in that period of time?

Have you tried doing another *simple script* to see if you can carry data from one page to another? If even a simple script doesn't work, then there is something wrong in the ini file somewhere.

Did you try echoing the $_SESSION array in the receiver script to see if the data was as expected?

Also try turning on error reporting to see if there is anything else going on behind the scenes? :-

<?php
error_reporting(E_ALL);

Sorry I can't be more constructive.

Cheers,
MRb

dbarasuk

11:55 am on Jul 8, 2010 (gmt 0)

10+ Year Member



I found out that it was a css problem. Everything was ok except that one table was hiding the list i was looking for(problem of css positionning).
thank you for the help

Matthew1980

12:25 pm on Jul 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there dbarasuk,

Well, at least that's that sorted out :) I didn't think as it was a php related issue as every 'box was checked' for setting $_SESSION up and you were checking it correctly.

CSS can be confusing sometimes especially when the browser caches the file, as I found out a few days ago, I was having to force a refresh (CTRL+F5) from the server in order for the 'updated' file to be referenced. Irritating.

Happy coding :)

Cheers,
MRb