3

This is first time i try to create a session. Also, after success login i redirect the page using header() function, but then on the redirected page i dont have session any more. There is the code:

creating session:

function userLogin($user){
    session_start();
    $_SESSION['username'] = $user;
    header("Location: /~klemeno/vaja10?" . SID);
    exit;
}

When browser redirect me i try to echo session like this:

if(isset($_SESSION['username'])){   
    echo $_SESSION['username'];
}
else{
    echo "No session :(";
}

2 Answers 2

12

You need to call session_start(); in both scripts to start and resume the session.

See: http://php.net/manual/en/function.session-start.php

1
  • i have it, but on wordpress, session not working Feb 27 at 17:32
1

You have to add session_start(); at the top of your PHP script(s).

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.