Jump to content

Sessions in windows/linux


jamiehook01

Recommended Posts

Hello,

 

I am having problems with storing sessions on my website, I have copied the website over to a new server (windows) to do some development work but the sessions will not store I have tried this using Xampp on xp locally & on another 3rd party normal server.

The original location where it works is Linux, this is the only difference the code is identical.

 

 

Login.php5

<?php require_once("includes/session.php5");?>
<?php require_once("includes/functionsuni.php5");?>
<?php dbConnect();?>
<?php

                                $forgot = $_GET["forgot"];
                //update the page if the submit button has been pressed
                if (isset($_POST["login"])){
                                $queryStatus = "<b>The email or password you provided, was invalid, please try again.</b> <br><br>";
                                //validate post data
                                $postsToCheck = array("email","password");
                                $postsMinLength = array(6,6);
                                $postsMaxLength = array(60,60);
                                $errors = validatePostData($postsToCheck,$postsMaxLength,$postsMinLength);
                                //pull in values if it validates
                                if (empty($errors)){
                                                $queryStatus = "no validation errors";
                                                $email = mysqlPrep($_POST["email"]);
                                                $password = mysqlPrep($_POST["password"]);
                                                $hashedPassword = sha1($password);
                                                $query = "SELECT id, email, name FROM users 
                                                                WHERE email = '{$email}'
                                                                AND hashedpassword = '{$hashedPassword}'";
                                                
                                                $results = mysql_query($query);
                                                if(mysql_num_rows($results) == 1 && $forgot == 1 ){
                                                                $user = mysql_fetch_array($results);
                                                                $_SESSION["id"] = $user["id"];
                                                                $_SESSION["name"] = $user["name"];
                                                                $_SESSION["email"] = $user["email"];
                                                                redirect("updatelostpassword.php5?pass=" . $password . "");}
                                                                
                                                elseif(mysql_num_rows($results) == 1){
                                                                $user = mysql_fetch_array($results);
                                                                $_SESSION["id"] = $user["id"];
                                                                $_SESSION["name"] = $user["name"];
                                                                $_SESSION["email"] = $user["email"];z
                                                                redirect("index.php5");
                                                }else{
                                                                $queryStatus = "<br><b>The email or password you provided, was invalid, please try again.</b> <br><br>";
                                                }              
                                } else {
                                                $queryStatus = "";
                                                                for ($i = 0; $i < count($errors);$i++){
                                                                                $queryStatus .= $errors[$i];
                                                                }
                                }
                }
?>

<?php include("includes/header.php5");?>
<?php require_once("includes/leftnavi.php5"); ?>
                                                
                                                                                                <td id="mainmiddle">
                                                                                                                <table>
                                                                                                                                <tr>
                                                                                                                                                <td class="longtableheader">
                                                                                                                                                                Attention
                                                                                                                                                </td>
                                                                                                                                </tr>
                                                                                                                                <tr>
                                                                                                                                                <td class="longtablecontent">
                                                                                                                                                                <?php if (!isset($_GET["forgot"])){
                                                                                                                                                                                echo "<b>The requested section of the site requires a log in.</b><br><br>
                                                                                                                                                                
                                                                                                                                                                Please log in using the form above.<br><br>";
                                                                                                                                                                }
                                                                                                                                                                ?>
                                       <br>
                                        <font color="#CC3333"><?php echo $queryStatus;?></font>
                                        
                                        <br>
                                                                                                                                                                If you have <b>lost</b> your password, please enter your email below and we will send you a link to reset your password
                                                                                                                                                                <br><br>
                                                                                                                                                                <form action="lostpassword.php5" method="post" id="login">
                                                                                                                                                                                Email: <input type="text" name="email" size="32"value="">
                                                                                                                                                                                <input type="submit" name="newpassword" value=">">
                                                                                                                                                                </form>
                                                                                                                                                                
                                                                                                                                                </td>
                                                                                                                                </tr>
                                                                                                                </table>
                                                                                                </td>
                                                                                                
<?php require_once("includes/rightnavi.php5"); ?>
<?php require_once("includes/footer.php5"); ?>
<?php dbDisconnect();?>

 

The check login session file session.php5

 


session_start();
                function checkLoggedin(){
                                if (!isset($_SESSION["id"])){
                                                redirect("login.php5");;
                                }
                }
                
                function confirmLoggedIn(){
                                if (isset($_SESSION["id"])){
                                                return true;
                                } else {
                                                return false;
                                };
                }
                
                function logOut(){
                                $_SESSION = array();
                                if(isset($_COOKIE[session_name()])){
                                                setcookie(session_name(),"",time()-42000,"/");
                                }
                                session_destroy();
                                
                                redirect("index.php5");
                }
                

 

functionsuni.php5 just runs the query and returns the result

 

 

 

I have tried using session-write-close() after setting which did not work. I stopped the script from re-directing to the index page and echoed the session variables and they are all there, they just get deleted when i switch pages? I am pulling my hair out can any one help?

 

Thank you

 

Jamie

 

Link to comment
https://forums.phpfreaks.com/topic/143644-sessions-in-windowslinux/
Share on other sites

Add the following two lines of code immediately after your first opening <?php tag, before the first require_once() statement -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

Edit: And what does a phpinfo() statement show for session.cookie_path?

This is the error that get thrown on the login page using the two lines of code

 

ini_set ("display_errors", "1"); error_reporting(E_ALL);
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\dev\login.php5:3) in C:\xampp\htdocs\dev\includes\session.php5 on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\dev\login.php5:3) in C:\xampp\htdocs\dev\includes\session.php5 on line 3

 

and the cookie path is set to / which is the same as my orginal server

 

 

Thanks for your reply

they just get deleted when i switch pages?

 

What is different about the URL's for the different pages? Does one have www. and the other one does not?

 

Also, put the ini_set("display_errors", "1"); eror_reporting(E_ALL); code on each page.

Based on what you have posted so far, either the server is not using cookies for the session id, your browser is not sending the session id back to the server, or something in your code is clearing the session variables.

 

Have you determined that sessions work at all by just using two simple scripts, one that has a session_start() and sets a $_SESSION variable to some value and the second one with a session_start() and an echo of that session variable?

 

What does a phpinfo() statement show for these settings -

 

session.use_cookies

session.use_only_cookies

session.use_trans_sid

 

Any chance your browser has been configured to not use any cookies or a session cookie with some addresses?

 

And post the code for the second page involved in case it is doing something that is php configuration specific.

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.