Jump to content

php SESSION var getting lost


kickoutbettman

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

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.