max_w1 Posted January 31, 2008 Share Posted January 31, 2008 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 More sharing options...
Kingy Posted January 31, 2008 Share Posted January 31, 2008 session_start(); must be placed before any code. eg <?php session_start(); do the rest of the code ?> try that Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454183 Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 <?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 https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454552 Share on other sites More sharing options...
haku Posted January 31, 2008 Share Posted January 31, 2008 Did you set the code kingy told you at the top of both pages? Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454556 Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 yes i did, i noticed one more thing!,, i am able to read session from login.php page but not able to read it from members.php page Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454561 Share on other sites More sharing options...
revraz Posted January 31, 2008 Share Posted January 31, 2008 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 https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454563 Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 i tried moving it to top. and as i said before... i am able to display sessions from login.php page but unable to display it from members.php page. Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454565 Share on other sites More sharing options...
revraz Posted January 31, 2008 Share Posted January 31, 2008 You probably have whitespace before the session_start() Check the code with Notepad. Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454569 Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 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 https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454570 Share on other sites More sharing options...
revraz Posted January 31, 2008 Share Posted January 31, 2008 session_start(); has to be the First line after <?php Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454574 Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 noops :-\... its not working. Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454579 Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 i think there is a problem with my local server... i think it does not support sessions. thats why they are getting destroyed as soon as i leave the page. can i use cookies insted of using sessions??? because cookies are working perfectly? Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454587 Share on other sites More sharing options...
revraz Posted January 31, 2008 Share Posted January 31, 2008 Check the php.ini for the session save path Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454588 Share on other sites More sharing options...
rhodesa Posted January 31, 2008 Share Posted January 31, 2008 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 https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454593 Share on other sites More sharing options...
rhodesa Posted January 31, 2008 Share Posted January 31, 2008 Note: There is no header() forward in there, so just navigate your browser to login.php and then navigate to members.php Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454594 Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 i tried using those codes but nothing happens ... i am still not able to view session... what to do.. please help!!! Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454599 Share on other sites More sharing options...
revraz Posted January 31, 2008 Share Posted January 31, 2008 Read my post above what to do.. Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454604 Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 yes 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 https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454606 Share on other sites More sharing options...
rhodesa Posted January 31, 2008 Share Posted January 31, 2008 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 https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454611 Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 it's still not displaying the session in the members.php. i am using index.htm to submit data to login.php. Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454617 Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 Read my post above what to do.. how am i suppose to find it? php.ini is a very long page... Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454619 Share on other sites More sharing options...
rhodesa Posted January 31, 2008 Share Posted January 31, 2008 I assume the code we are discussing for login.php is only a snippet. Can you paste the entire file? Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454621 Share on other sites More sharing options...
revraz Posted January 31, 2008 Share Posted January 31, 2008 .htm won't parse .php by default. change the name to index.php it's still not displaying the session in the members.php. i am using index.htm to submit data to login.php. Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454625 Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 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 https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454626 Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 .htm won't parse .php by default. change the name to index.php :(i did it.. now index.htm is index.php but its giving me the same problem. Link to comment https://forums.phpfreaks.com/topic/88692-solved-unable-to-read-sessions/#findComment-454627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.