Jump to content

[SOLVED] unable to read sessions


max_w1

Recommended Posts

hi, i have a login page which looks like this

if(isset($remember))

{

setcookie('username', $username, time()+1209600);

setcookie('password', base64_encode ($password), 0);

setcookie('remember', $remember, 0);

setcookie('ipaddress', $ipaddress, 0);

session_start();

//remove the anti-hacking cookie

setcookie ('tries', '', time()-60, '/', '', 0);

$_SESSION['loggedin'] = $_POST['username'];

$_SESSION['time'] = time();

header ('Location: /members.php');

echo("hi $username you are now logged in");

header("Location: members.php");

$loggedsuck = TRUE;

}

else

{

session_start();

//remove the anti-hacking cookie

setcookie ('tries', '', time()-60, '/', '', 0);

$_SESSION['loggedin'] = $_POST['username'];

$_SESSION['time'] = time();

header ('Location: members.php');

}

                }

i dont have any problem with my login page but when it redirects to memebers.php i am unable to echo

session. i am using the following code in my memebers.php page:

<?php $welcome = $_SESSION['loggedin'];

echo "$welcome";

?>

i will be glad to receve any help!

Link to comment
https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/
Share on other sites

<?php session_start();

$welcome = $_SESSION['loggedin'];

echo "$welcome";

?></div>

i did that buy it does not work.

i think there is a problem in the code which sets session.

one more thing... there is a index.html page which POSTs data to login.php and login.php sets the session and redirects us to members.php, so can members.php display session? ??? if yes please help me!!

 

thankyou in advance ;)

Your session_start on the first page is after your cookies, move it to the top.

 

Also, all those cookies that you are setting that doesn't have a time on it, will expire once you close the browser.  Not sure if you know that or not.

there is no white space the code looks like this:

<?php 
ob_start();
session_start();    
/////////////////////////////////////////////////////////////////////////////////////////////
/**//**//**/require ("config.php");/**//**//**//**//**//**//**//**//**//**//**//**//**//**///
/////////////////////////////////////////////////////////////////////////////////////////////	
if (isset ($_COOKIE['password']) || isset ($_COOKIE['rempassword'])) 
{
echo("you are already logged in");
}
else
{

on login.php but the following:

<?php
  session_start();
  print "SESSION ID: ".session_id();
  print "\nSession module: ".session_module_name();
  print "\nSession save path: ".session_save_path();
  $_SESSION['loggedin'] = 'testuser';
  $_SESSION['time'] = time();
  print "\nSession data: ";
  print_r($_SESSION);
?>

 

and on members.php put:

<?php
  session_start();
  print "SESSION ID: ".session_id();
  print "\nSession data: ";
  print_r($_SESSION);
?>

 

and let us know what happens

yes ;D

login.php says:

SESSION ID: fdfd98a60c5942fb5b4b07fbb933795d Session module: files Session save path: C:\Program Files\YellowTip/tmp Session data: Array ( [loggedin] => testuser [time] => 1201804153 )

 

and members.php says:

SESSION ID: fdfd98a60c5942fb5b4b07fbb933795d Session data: Array ( [loggedin] => testuser [time] => 1201804153 )

 

what does that mean?? i dont understand.... 

that is a very good thing...

 

how are you submitting the user/password data to login.php?

 

try this on login.php, and leave members.php alone for now

<?php
  session_start();
  if(isset($remember)){
    setcookie('username', $username, time()+1209600);
    setcookie('password', base64_encode ($password), 0);
    setcookie('remember', $remember, 0);
    setcookie('ipaddress', $ipaddress, 0);
  }
  //remove the anti-hacking cookie
  setcookie ('tries', '', time()-60, '/', '', 0);
  $_SESSION['loggedin'] = $_POST['username'];
  $_SESSION['time'] = time();
  header ('Location: /members.php');
  exit;
?>

the entire login.php looks like this

<?php 
ob_start();
  print "SESSION ID: ".session_id();
  print "\nSession module: ".session_module_name();
  print "\nSession save path: ".session_save_path();
  $_SESSION['loggedin'] = 'testuser';
  $_SESSION['time'] = time();
  print "\nSession data: ";
  print_r($_SESSION);

////////////////////////////////////////////////////////////////////////////////////////////
/**//**//**/require ("config.php");/**//**//**//**//**//**//**//**//**//**//**//**//**//**///
/////////////////////////////////////////////////////////////////////////////////////////////	
if (isset ($_COOKIE['password']) || isset ($_COOKIE['rempassword'])) 
{
echo("you are already logged in");
}
else
{

      // Variables that data come from the form
      $username = $_POST["username"];
      $password = $_POST["password"];
      $login    = $_POST["login"]; 
  $ipaddress = $REMOTE_ADDR;
  $remember  = $_POST["remem"];
      // Check if username and password where submitted
    	
  if(isset($login))
  {
  if(isset($login))
  {
  if (!$username) {
          echo "Please enter username"; exit;
      }
      if (!$password) {
          echo "Please enter password"; exit;
      }

     
     
    
      $issuchusername = mysql_query("SELECT * FROM users WHERE username = '$username'");
      $usernamelogin = mysql_num_rows($issuchusername);

    
      if ($usernamelogin == 1) {
  

          $issuchpassword = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
          $passwordlogin = mysql_num_rows($issuchpassword);

         
          if ($passwordlogin == 1) {
	 if(isset($remember))
				 {
				 if(isset($remember)){
    setcookie('username', $username, time()+1209600);
    setcookie('password', base64_encode ($password), 0);
    setcookie('remember', $remember, 0);
    setcookie('ipaddress', $ipaddress, 0);
  }
  //remove the anti-hacking cookie
  setcookie ('tries', '', time()-60, '/', '', 0);
  $_SESSION['loggedin'] = $_POST['username'];
  $_SESSION['time'] = time();
  header ('Location: /members.php');
  exit;
				 }
				 else 
				 {
				 session_start();
		//remove the anti-hacking cookie
		setcookie ('tries', '', time()-60, '/', '', 0);
		$_SESSION['loggedin'] = $_POST['username'];
		$_SESSION['time'] = time();
		header ('Location: members.php');
				 }
                 }
					           
          }
          else {
              echo "Incorrect username/password1";
              header("Location: index.php?error=true");
		  exit;
          }
      }
      if(!$usernamelogin)
  {
  echo "incorrect username or password";
  header("Location: index.php?error=true");
  exit;
}
  }
} 
?> 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.