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
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 ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
{

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.... 

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

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;
}
  }
} 
?> 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.