kickoutbettman Posted April 8, 2009 Share Posted April 8, 2009 Hi everyone. I'm having a problem with my PHP session vars getting lost or not writing info at all. So here's a couple of information. 1. IT IS WORKING on my localhost NT machine. 2. Where it's not working it's on my client host server. (FATCOW host at fatcow.com) 3. Host server is using PHP : 4.4.8 So basically I have a html login page (login.php) Then login.php send info to (login-exec.php) (Here I check my database to see if username exist and if so redirect using header... Then the redirection goes to a "member page" where I require('auth.php') to check if session exist if no I get redirected to ACCESS DENIED PAGE And there's the problem, it always give me the access denied page. So here's my code. login-exec.php # <?php # //Start session # session_start(); # # //Include database connection details # require_once('../Connections/golf_stats.php'); # # //Array to store validation errors # $errmsg_arr = array(); # # //Validation error flag # $errflag = false; # # //Connect to mysql server # $link = mysql_connect($hostname_golf, $username_golf_stats, $password_golf_stats); # if(!$link) { # die('Failed to connect to server: ' . mysql_error()); # } # # //Select database # $db = mysql_select_db($database_golf_stats, $golf_stats); # if(!$db) { # die("Unable to select database"); # } # # //Function to sanitize values received from the form. Prevents SQL injection # function clean($str) { # $str = @trim($str); # if(get_magic_quotes_gpc()) { # $str = stripslashes($str); # } # return mysql_real_escape_string($str); # } # # //Sanitize the POST values # # $login = clean($_POST['login']); # $password = clean($_POST['password']); # # //Input Validations # if($login == '') { # $errmsg_arr[] = 'Login ID missing'; # $errflag = true; # } # if($password == '') { # $errmsg_arr[] = 'Password missing'; # $errflag = true; # } # # //If there are input validations, redirect back to the login form # if($errflag) { # $_SESSION['ERRMSG_ARR'] = $errmsg_arr; # session_write_close(); # header("location: login.php"); # exit(); # } # # //Create query # mysql_select_db($database_golf_stats, $golf_stats); # $query_members = "SELECT * FROM members WHERE username = '$login'"; # $list_members = mysql_query($query_members, $golf_stats) or die(mysql_error()); # $row_members = mysql_fetch_assoc($list_members); # $totalRows_members = mysql_num_rows($list_members); # # //Check whether the query was successful or not # if($list_members) { # if($totalRows_members == 1) { # //Login Successful # $_SESSION['SESS_MEMBER_USERNAME'] = $row_members['username']; # $_SESSION['SESS_JOUEUR_ID'] = $row_members['idJoueur']; # $_SESSION['SESS_JOUEUR_NAME'] = $row_members['name']; # # session_write_close(); # header("location: ../members/members-index.php"); # exit(); # }else { # //Login failed # header("location: login-failed.php"); # exit(); # } # }else { # die("Queryisfailed"); # } # ?> And here's my AUTH.php file # <?php # session_start(); # # //Check whether the session variable SESS_MEMBER_ID is present or not # if(!isset($_SESSION['SESS_MEMBER_USERNAME'])) { # header("location: ../login/access-denied.php"); # exit(); # } # ?> I've seen 1000 of posts with people having the same problem, but I can't resolve my issue. I did use session_write_close(); before the header redirection. I did use session_start() for every pages that uses $SESSION['xxx'] Again like I said, it works on my localhost machine. Thank you very much in advance for your help. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/ Share on other sites More sharing options...
revraz Posted April 8, 2009 Share Posted April 8, 2009 Check your host's php.ini file and verify the session save path is valid. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804737 Share on other sites More sharing options...
kickoutbettman Posted April 8, 2009 Author Share Posted April 8, 2009 Thanks for your quick answer This is what phpinfo() tells me : session.save_path /var/php_sessions What should it be ? Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804742 Share on other sites More sharing options...
schilly Posted April 8, 2009 Share Posted April 8, 2009 Put a print_r($_SESSION) on your access denied page to see if anything is in your session. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804782 Share on other sites More sharing options...
kickoutbettman Posted April 8, 2009 Author Share Posted April 8, 2009 Doesn't seem to return anything. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804796 Share on other sites More sharing options...
revraz Posted April 8, 2009 Share Posted April 8, 2009 First determine if it's a logic issue or a actual session issue. In your first code, setting your session depends on: if($list_members) { if($totalRows_members == 1) { So create two new pages, first page, start your session, set a session variable. Second page, read that session variable. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804803 Share on other sites More sharing options...
kickoutbettman Posted April 8, 2009 Author Share Posted April 8, 2009 I'm not a php expert, but I don't see how it could be a logic issue since it's working on my local machine (localhost). But I did try to do what you said : if($list_members) { if($totalRows_members == 1) { header("location: test1.php"); exit(); Then on test1.php <?php session_start(); $_SESSION['test'] = "this is a test"; session_write_close(); ?> <a href="test2.php">link to test 2</a> And then test2.php <?php session_start();s echo $_SESSION['test']; ?> RESULT : BLANK, nothing is returned. BTW thanks for trying to help, very appreciated Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804825 Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2009 Share Posted April 8, 2009 Put the following two lines immediately after your first opening <?php tag (before the session_start() statements) on both pages - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804826 Share on other sites More sharing options...
Maq Posted April 8, 2009 Share Posted April 8, 2009 session_start();s You have an extra 's' in test2.php, is that a typo? Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804831 Share on other sites More sharing options...
kickoutbettman Posted April 8, 2009 Author Share Posted April 8, 2009 MAQ yes it's a typo. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804858 Share on other sites More sharing options...
Maq Posted April 8, 2009 Share Posted April 8, 2009 MAQ yes it's a typo. Haha, ok just making sure! A blank page usually means syntax errors that are being suppressed, please do what PFMaBiSmAd suggested and report back the results. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804859 Share on other sites More sharing options...
kickoutbettman Posted April 8, 2009 Author Share Posted April 8, 2009 Alright, this is what I get on first page. ??? Warning: session_start() [function.session-start]: open(/var/php_sessions/sess_82828398b35afdfe0dc9fc4b5310cd36, O_RDWR) failed: No such file or directory (2) in /hermes/web10/b2762/moo.kickoutbettman/golf/login/test1.php on line 4 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/web10/b2762/moo.kickoutbettman/golf/login/test1.php:4) in /hermes/web10/b2762/moo.kickoutbettman/golf/login/test1.php on line 4 Warning: session_write_close() [function.session-write-close]: open(/var/php_sessions/sess_82828398b35afdfe0dc9fc4b5310cd36, O_RDWR) failed: No such file or directory (2) in /hermes/web10/b2762/moo.kickoutbettman/golf/login/test1.php on line 6 Warning: session_write_close() [function.session-write-close]: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/php_sessions) in /hermes/web10/b2762/moo.kickoutbettman/golf/login/test1.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804869 Share on other sites More sharing options...
revraz Posted April 8, 2009 Share Posted April 8, 2009 Means your session file path is not valid. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804873 Share on other sites More sharing options...
kenrbnsn Posted April 8, 2009 Share Posted April 8, 2009 That's saying that the directory "/var/php_sessions/" doesn't exist. Check with your host provider. Ken Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804874 Share on other sites More sharing options...
kickoutbettman Posted April 8, 2009 Author Share Posted April 8, 2009 This is where I get confuse..... phpinfo() returns : session.save_path = /var/php_sessions How come it's not something set by default on my host server. I'm not the first using session variables. Why would I have to have my host to make a change. On my local machine I get : session.save_path = /tmp Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804888 Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2009 Share Posted April 8, 2009 How come it's not something set by default on my host server. It should be, that's why kenrbnsn instructed you to check with your hosting provider. We cannot answer that question, your host can. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804891 Share on other sites More sharing options...
revraz Posted April 8, 2009 Share Posted April 8, 2009 My Host had the wrong path by default as well, it just has to be changed to a valid path. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804908 Share on other sites More sharing options...
kickoutbettman Posted April 8, 2009 Author Share Posted April 8, 2009 Can anyone tell me what path I should ask them to change it to ? By the way thank you all for your answer, it seems I getting close to fix my issue. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804910 Share on other sites More sharing options...
revraz Posted April 8, 2009 Share Posted April 8, 2009 You ask them what it should be set to. It needs to be a path on in your area you can write to. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804912 Share on other sites More sharing options...
kickoutbettman Posted April 8, 2009 Author Share Posted April 8, 2009 thanks guys, I'll ask them right away and let you know the answer. Maybe this should remain open until then. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804917 Share on other sites More sharing options...
revraz Posted April 8, 2009 Share Posted April 8, 2009 Up to you on that, but once you get the path resolved, it should work fine. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804919 Share on other sites More sharing options...
kickoutbettman Posted April 8, 2009 Author Share Posted April 8, 2009 I sent them the error message They ask me to wait 2 min. and retry. It works now...amazing... But I have no idea what they changed it to. Thank you all. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804929 Share on other sites More sharing options...
revraz Posted April 8, 2009 Share Posted April 8, 2009 They probably just fixed the folder to have the correct rights. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804932 Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2009 Share Posted April 8, 2009 A permissions problem does not give a "No such file or directory" error. You can use a phpinfo() statement to find out what it is set to. Quote Link to comment https://forums.phpfreaks.com/topic/153196-php-session-var-getting-lost/#findComment-804938 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.