SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by 'out'? Do you mean it has timed out?
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,072
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Are you using session_start() at the top of every page?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>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("./");
    }
    }
    ?>

  6. #6
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello tangoforce,
    I have kept session_start() in each and every page at the top, but also not working.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  10. #10
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Location
    Pakistan
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  11. #11
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello asher,
    You are right. That was the problem which you have described.
    Many many thanks to you.
    See you next time.
    Thanks again.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •