7 Replies - 786 Views - Last Post: 19 July 2011 - 10:21 AM Rate Topic: -----

#1 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 817
  • Joined: 16-September 09

Storing session data isn't working...

Posted 19 July 2011 - 10:12 AM

Hi guys! Again, probably another really simple answer here but I'm stumped...


Due to everyones amazing input, I got my signup scripts working and my login scripts look great too...now i have a new problem ...

When I login, I have a checksession.php file that is required and it keeps kicking me back to the login....here's my code


checksession.php
<?php
	if(!isset($_SESSION['userid'])){
	echo "Sorry, Please login and use this page ------ REDIRECTING";
	print "<script>";
	print " self.location='login.php';";
	print "</script>";
	exit;
	} 

	echo "Welcome!"
?>



newsession.php
<?php	
	session_start();
	$_SESSION['id']=session_id();
	$_SESSION['userid']=$userid;
?>



loginchk.php //Where I check the login credentials against the db
if($rec=mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username='$userid' AND password='$password'"))){
if(($rec['username']==$userid)&&($rec['password']==$password)){
include "/home/u395388955/public_html/newsession.php";
echo "<p class=data> <center>Successfully,Logged in<br>
<br><a href='logout.php'> Log OUT </a><br>
<br><a href=welcome.php>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>";
print "<script>";
print " self.location='login_index.php';"; // Comment this line if you don't want to redirect
print "</script>";



and of course, my login_index.php -- this is where the redirect has to be taking place..
<?php
			require '/home/u395388955/public_html/checksession.php'; 
?>	

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>



I figure I must be starting the session wrong but I posted a little bit of everything so you guys can tell me if I'm way off base...I get no errors, just a redirect and I am stummmmmpppeeedd here :?

As always, thanks in advance!! :)

Is This A Good Question/Topic? 0
  • +

Replies To: Storing session data isn't working...

#2 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Storing session data isn't working...

Posted 19 July 2011 - 10:13 AM

Have you tried adding session_start() to the top of checksession.php?
Was This Post Helpful? 0
  • +
  • -

#3 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 817
  • Joined: 16-September 09

Re: Storing session data isn't working...

Posted 19 July 2011 - 10:17 AM

Pardon if this comes off as stupid but wouldn't that start the session before I checked it?
Was This Post Helpful? 1
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2891
  • View blog
  • Posts: 10,020
  • Joined: 08-August 08

Re: Storing session data isn't working...

Posted 19 July 2011 - 10:19 AM

You need to start a session before you can do anything with it.
Was This Post Helpful? 2
  • +
  • -

#5 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Storing session data isn't working...

Posted 19 July 2011 - 10:19 AM

Well in order for you to check a session there must be one already.
Was This Post Helpful? 1
  • +
  • -

#6 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,044
  • Joined: 08-June 10

Re: Storing session data isn't working...

Posted 19 July 2011 - 10:20 AM

the PHP Manual said:

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

Was This Post Helpful? 1
  • +
  • -

#7 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Storing session data isn't working...

Posted 19 July 2011 - 10:20 AM

You should add session_start() to any page that you want a session to be created. Even a logout file.
Was This Post Helpful? 1
  • +
  • -

#8 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 817
  • Joined: 16-September 09

Re: Storing session data isn't working...

Posted 19 July 2011 - 10:21 AM

lol....wow....I got so into the problem, I over looked the solution...


Thanks guys....i get it..I thought I was starting the session from login but I was checking first....


Thanks for the help :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1