Echoing session data not working

URL: blockvio.rf.gd

If I try to echo database data then it will just show as blank. But if I clarify it as text then it will display it.
What is going on?

check if the session started with session_start(); in your script

Yes, first start the php session, then dump all the session variables to see what you have

print_r($_SESSION)

3 Likes

I already have the bit that starts the session in there, the variables are in my login script but when I try

echo $username;

it doesn’t work

or echo ($username$);

did you save the session in this variable?

If it’s session data, shouldn’t it be echo $_SESSION['username']; instead?

3 Likes

Oh my god, I am so stupid! It works but I was trying echo $username because in login.php it sets it before redirecting to home page. Thank you so so so so much!

One last issue, When I close the page and go back to it, the php echo does not show, Is there a fix for this?

Most likely the session either timing out or deleting itself.

1 Like

I’m looking for some quick code if you have any, the .htaccess code it says does not work for it and it would probably affect my session thing to sign you out after a while of inactivity.

Note that it is hard to keep session data after closing the browser. I’m not sure if it is possible

Alright. Thanks anyways.

AFAIK It’s being removed after one day in this hosting, if you wonder how long your SESSDATA will stay , You can look for the expiration date of PHPSESSID cookie which belongs to the site.

It’s because you are giving the value of $_SESSION[‘username’] to $username doesn’t mean you can change value of $_SESSION[‘username’] by changing value of $username. $username variable will only and only stay at login.php and won’t move to other files.

4 Likes

Ah alright thanks!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.