0

i'm having some issues with PHP sessions. I'm pretty new to PHP so my apologies if i'm being completely stupid.

I have a login.php file that once the user name and password has been checked etc it has the following code:

if($pass === $row2['PSWD']){
    session_start();
    $_SESSION['test']="hello";
    mysql_close($con);
    header("Location: page.php");
}else{
    die('Wrong password');
}

then on page.php I have the following at the very top, about the tag:

<?php
session_start();
session_register(); //just in case...(should not be needed)
echo "Result:".$_SESSION['test'];
?>

And all I get at the top of the page is "Result:"

Any ideas? As from everything i've been reading it should be as simple as this?

Thanks in advance!

EDIT:

My error logs are showing:

Warning: session_start() [function.session-start]: open(/var/php_sessions/sess_b91f8653bcee6ef7c1e13ae8844f00da, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web261/b2617/ipg.craigfisk/webtest/login.php on line 28

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web261/b2617/ipg.craigfisk/webtest/login.php:28) in /hermes/bosweb/web261/b2617/ipg.craigfisk/webtest/login.php on line 28

Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web261/b2617/ipg.craigfisk/webtest/login.php:28) in /hermes/bosweb/web261/b2617/ipg.craigfisk/webtest/login.php on line 31

Warning: Unknown: open(/var/php_sessions/sess_b91f8653bcee6ef7c1e13ae8844f00da, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/php_sessions) in Unknown on line 0

10
  • Are you sure you have no output before session_start at both pages? Commented Feb 12, 2013 at 16:55
  • possible duplicate: stackoverflow.com/questions/3023353/… Commented Feb 12, 2013 at 16:56
  • Try calling session_write_close() before the header() redirect code. Also, add exit() after the header() redirect to be safe. Commented Feb 12, 2013 at 16:57
  • @John What do you mean by no output exactly? Commented Feb 12, 2013 at 16:59
  • 1
    @anton: write_close is not necessary. unless the script terminates with a fatal error, php will automatically close/save the session during cleanup. Commented Feb 12, 2013 at 17:25

2 Answers 2

1

You need to put exit(); after your header redirection, otherwise you have just loaded two pages of content into 1 page.

source: https://stackoverflow.com/a/3023479/710827

Sign up to request clarification or add additional context in comments.

Comments

0

after header location give exit();

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.