2

My session variables are empty when I login users and use a header redirect.

/* Login page */
session_register("myusername");
session_register("mypassword");

$_SESSION['myusername'] = $_POST['myusername'];

header("location:page.php");

/* page.php */

<?php echo $_SESSION[myusername]; ?>
2
  • 3
    session_register function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0. Commented Dec 17, 2012 at 10:27
  • u need to session_start() on every pages ! including the page on which you register the session. Commented Dec 17, 2012 at 10:29

5 Answers 5

5

You should not use session_register function when you use $_SESSION superglobal array and you did not start your session. Try

/* Login page */
session_start();

$_SESSION['myusername'] = $_POST['myusername'];

header("location:page.php");

/* page.php */

session_start();

<?php echo $_SESSION[myusername]; ?>
Sign up to request clarification or add additional context in comments.

Comments

3

Try to use session_start(); in starting of the page..

Comments

2

You forgot to add session_start(); in top of the page

Comments

1

add a

session_start() 

as first!

Comments

1

Did you include session_start() call at the start of the script page?,that is the most common issue i'm aware of with sessions in php.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.