NameSilo

Php Sessions - Can't spot my problem.

Spaceship Spaceship
Watch

pixelbypixel

Established Member
Impact
38
Hey,

I am having a problem with sessions, I am failing to see how and why it is not working, I am doing everything exactly the same as usual. O_o.

login.php (page with login form)
Code:
...
<form class="centered_200" method="post" action="app/include/log-functions.php">
	<h2><img src="http://www.namepros.com/images/username.jpg" alt="Username" /></h2>
	<input type="text" value="username" name="loginname" />
	<h2><img src="http://www.namepros.com/images/password.jpg" alt="Password" /></h2>
	<input type="password" value="password" name="passkey" />
	<input type="hidden" value="login" name="request" />
	<p><input class="loginbutton" type="submit" value="Login" /></p>
</form>
...

log-functions.php (does the logging in)
Code:
...
if($var=="login"){
	session_start();
	$_SESSION['oams'] = 1;
	header('Location: ../index.php');	/** sends user to /app/index.php */
}
...

/app/index.php (page being sent to after login)
Code:
	require_once('./config/settings.php');
		require('./include/functions.php');
		require('./include/db.php');
		$con = new db();
		session_start();
		if(!isset($_SESSION['oams'])){header('Location: ../index.php'); exit;} /** THIS IS MY PROBLEM LINE */
                 $this->display();


Right, simply, I am creating a new session, setting ['oams'] to 1 (or whatever I want), and when it sends me to /app/index.php it kicks in saying that $_SESSION['oams']) is not set, thus sending me back to the main index page.

If i echo $_SESSION['oams']) in my log-functions.php file, it works fine, it seems to empty/lose my session data when it moves page.

If I remove the check for it being set, it lets me go to the right page, so something is wrong with the session starting or continuing when a page changes.

Anyone know a reason for this?

Thanks
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
i've never had this problem with my sessions, however try in /app/index.php

instead of session_start(); put:

if (!isset($_SESSION)) {
session_start();
}

it could be possible that you are creating a separate session with the second start.
 
0
•••
Could it be the 2nd session_start(); in /app/index.php canceling $_SESSION['oams'] = 1; ?
 
0
•••
0
•••
Thanks, it was not the solution but...

OH MY GOD.

Talk about schoolboy errors.

My php.ini had register_globals = Off.
my phpinfo() just told me it was set to On.

Logged into my hosting, opened php.ini.. sure enough it said it was Off.. So i saved it exactly as it was before.. then my phpinfo updated saying it was Off..

<_< talk about wasting my time

Thanks for the help though
 
0
•••
0
•••
I often put session_write_close(); after creating the session, especially before a header redirect.
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back