enkidu72 Posted April 27, 2008 Share Posted April 27, 2008 Hi all , I have a problem with a session dying prematurely . I have an app I wrote in php/mysql running on apache . I have 2 copies installed on linux machines , and It's working great . Now the problem is that I had to install it on a Vista machine , and on Vista when I log in seems that the session end immediately and I'm kicked out . I have poor knowledge of Windows , but apache doesn't give me any errors , so I really can't explain ... I post some code ( working prfectly on linux with php 4 and 5 , and apache 1 and 2 ...) index.php <? session_start(); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> the login part : if (!isset($login_message)) { $login_message = "" ; } if (isset($_SESSION['logged']) && $_SESSION['logged']=='1') { $loginForm = 0; } if (isset($_POST['nome'])&& isset($_POST['password'])){ include_once ("admin_config.php"); $nome=mysql_real_escape_string(trim(strip_tags($_POST['nome']))); $password=mysql_real_escape_string(trim(strip_tags($_POST['password']))); $connect ; $selectdb ; $result = mysql_query("SELECT nome,password,is_admin FROM user WHERE nome='$nome'")or die(mysql_error("Login Incorrect")); $valid=array(); while($row = mysql_fetch_array( $result )) { $valid['nome'] = $row['nome']; $valid['password'] = $row['password']; $valid['perms'] = $row['is_admin']; } if (isset($valid['nome'])) { if ( $nome==$valid['nome']) { if ($valid['password']==$password){ $_SESSION['nome']=$valid['nome']; $_SESSION['logged']=1; $_SESSION['perms']=$valid['perms']; $loginForm = 0; } } } } if ($loginForm == 1){ include ("auth_box.php"); echo $login_message ;} ?> and the beginning of a page if ( (isset($_SESSION['nome'])) && (isset($_SESSION['logged'])) && (($_SESSION['logged']=='1')) ){ if I remove this check everything works .... Someone has some hint ? Thx in advance David Link to comment https://forums.phpfreaks.com/topic/103130-solved-session-end-prematurely/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2008 Share Posted April 27, 2008 Add the following two lines after your first opening <?php tag - ini_set ("display_errors", "1"); error_reporting(E_ALL); Also, you should be using <?php instead of <? as it is highly likely your php installation on Windows is using the recommended settings and the short open tag is disabled. You did not post all your code, so it is possible that your session_start() that is after a <? tag is not being seen as php code, but the rest of your php code, using <?php, is being seen. The following syntax in your code for mysql_error is incorrect and should your mysql_query fail, the output will be something other than what you expect - mysql_error("Login Incorrect")); Link to comment https://forums.phpfreaks.com/topic/103130-solved-session-end-prematurely/#findComment-528247 Share on other sites More sharing options...
enkidu72 Posted April 27, 2008 Author Share Posted April 27, 2008 Many thx ! It worked ! Was just because of the "<?" instead of "<?php" many thx again Link to comment https://forums.phpfreaks.com/topic/103130-solved-session-end-prematurely/#findComment-528248 Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2008 Share Posted April 27, 2008 The short open tags <? and <?= are against php.net recommend settings and should not be used as they result in non-portable code. Link to comment https://forums.phpfreaks.com/topic/103130-solved-session-end-prematurely/#findComment-528249 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.