Automatic session being out

Hello Everybody,
I am having problem in session being out automatically. In localhost, the program work perfectly without being session out. But in FTP server, the problem occurs.
The problem is that after login the user will enter into authorize page then when the user moves to other page then the session will be out and then the page is redirect to login page.

          I have tried a lot but could not find how it is happen.

Please help me to get rid out of it.

Thanks in advance.

What do you mean by ‘out’? Do you mean it has timed out?

Not time out, but session will destroy automatically. I have kept session time out of 2 hrs but as soon as I click to move to another page after being login, the session is destroyed.

Are you using session_start() at the top of every page?

here is my php code given below

index.php

<?php
require_once(‘includes/init.php’);
if(isset($_POST[‘log’]))
{
$userid=$db->escape_value($_POST[‘email’]);
$pwd=$db->escape_value ($_POST[‘pwd’]);
$pwd=md5($_POST[‘pwd’]);

	$findid="select * from member where memberid='$userid'";
	$r=mysql_query($findid);
	$rn=mysql_num_rows($r);
	if($rn&gt;0)
	{
		$arr=mysql_fetch_array($r);
		if($pwd==$arr['password'])
		{					
			$_SESSION['memberid']=$userid;
			redirect_to("member.php");					
		}
		else
		{
			$message=" UserID or password is invalid";
		}				
	}
	else
	{
		$message=" UserID or password is invalid";
	}				
}			

?>

init.php

<?
session_start();
//define paths
defined(‘DS’) ? null : define(‘DS’, “/”);
defined(‘SITE_ROOT’) ? null : define(‘SITE_ROOT’, $_SERVER[‘DOCUMENT_ROOT’].DS.‘report’);
defined(‘INC_PATH’) ? null : define(‘INC_PATH’, SITE_ROOT.DS.‘includes’);
defined(‘MOD_PATH’) ? null : define(‘MOD_PATH’, SITE_ROOT.DS.‘model’);
defined(‘JS_PATH’) ? null : define(‘JS_PATH’, SITE_ROOT.DS.‘jquery’);
defined(‘TEM_PATH’) ? null : define(‘TEM_PATH’, SITE_ROOT.DS.‘templates’);
defined(‘PLUGIN_PATH’) ? null : define(‘PLUGIN_PATH’, SITE_ROOT.DS.‘plugins’);

$root=“http://localhost/report/”;
$css=$root.“css/”;
$inc=$root.“includes/”;
$images=$root.“http://www.sitepoint.com/forums/images/”;
$mod=$root.“model/”;
$js=$root.“jquery/”;
$temp=$root.“templates/”;
$spry=$root.“SpryAssets/”;
$plugin_path=$root.“plugins/”;

//ms paths
defined(‘MS_PATH’) ? null : define(‘MS_PATH’, SITE_ROOT.DS.‘ms’);
defined(‘MS_TEM_PATH’) ? null : define(‘MS_TEM_PATH’, MS_PATH.DS.‘templates’);

$ms_root=$root.“ms/”;
$ms_temp=$ms_root.“templates/”;
$css_table=$ms_root.“css/”;

//include files for all
require_once(INC_PATH.DS.‘config.php’);
require_once(INC_PATH.DS.‘db_connect.php’);
require_once(INC_PATH.DS.‘session.php’);
require_once(INC_PATH.DS.‘class.function.php’);
require_once(MOD_PATH.DS.‘db.class.php’);
include_once(PLUGIN_PATH.DS.“fckeditor/fckeditor.php”) ;

//initialize ojects
$db= new db();
//$session = new session();
$functions= new functions();

?>


member.php

<?
require_once(‘includes/init.php’);
confirm_logged_in();

 $userid=$_SESSION['memberid'];
 $findid="select * from member where memberid='".$_SESSION['memberid']."'";
 $r=mysql_query($findid);
 $arr=mysql_fetch_array($r);

?>

viewlist.php

<?php
require_once(‘includes/init.php’);
confirm_logged_in();

if($_REQUEST['date']==NULL)
	$dbdate=date("Y/m/d");
else
	$dbdate=$_REQUEST['date'];
$userid=$_SESSION['memberid'];	
$getemail=mysql_fetch_array(mysql_query("select * from member where memberid='".$_SESSION['memberid']."'"));
$email=$getemail['email'];


session.php

<?php
//session_start();

function redirect_to( $location )
{
	if ($location != NULL)
	{
		header("Location: {$location}");
		exit;
	}
}
function logged_in() {
	return isset($_SESSION['memberid']);
}

function confirm_logged_in() {
	if (!logged_in()) {
		redirect_to("./");
	}
}

?>

EVERY script which accesses $_SESSION must use session_start() at the top of the script.

This is a basic issue which you should have read about in the php manual. Most of your code above is missing the use of session_start() - yet some use it which is odd. Get it out of init.php and put it into your main code files.

Also please, give us half a fighting chance to help you. Don’t use words like ‘out’ in the future when you’re clearly capable of explaining yourself better like you have in your last reply. It doesn’t do you or your project any good.

Hello tangoforce,
I have kept session_start() in each and every page at the top, but also not working.

And one thing I forgot to tell you that the program is running perfectly in localhost but the error is only in when the program is run from FTP server.

You’ve uploaded it to a FTP server? - or a web server?

Please would you be direct and to the point instead of trying to be as confusing as possible. Using the word ‘out’ to describe sessions not working and ‘FTP’ as somewhere you’re trying to run your scripts will not help you at all.

Please also check for the URL because www.domain.com and domain.com are two separate entities. The session set for www.domain.com will expire on domain.com

Hello asher,
You are right. That was the problem which you have described.
Many many thanks to you.
See you next time.
Thanks again.