The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Php Session expires after change page

Discussion in 'General Discussion' started by leonep, May 6, 2015.

  1. leonep

    leonep Well-Known Member

    Joined:
    Nov 18, 2014
    Messages:
    46
    Likes Received:
    1
    Trophy Points:
    8
    Location:
    Pescara
    cPanel Access Level:
    Root Administrator
    Hi ,i have 2 simple pages for test sessions in php

    first page :

    <?php
    ini_set('display_errors','On');
    error_reporting(E_ALL);
    session_start();
    $_SESSION['hello']='world';?>


    second page:

    <?php
    ini_set('display_errors','On');
    error_reporting(E_ALL);
    echo $_SESSION['hello'];?>


    Notice: Undefined variable: _SESSION in /home/itmediaquality/public_html/testsession2.php on line 5

    Note: i don't have any problem in local test environment ! i need to config something on cPanel or php.ini ? thanks

    adding session_start on second page i got:
    Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/itmediaquality/public_html/testsession2.php:2) in/home/itmediaquality/public_html/testsession2.php on line 5
    world
     
    #1 leonep, May 6, 2015
    Last edited by a moderator: May 6, 2015
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  3. LostNerd

    LostNerd Well-Known Member

    Joined:
    Mar 12, 2014
    Messages:
    258
    Likes Received:
    11
    Trophy Points:
    18
    Location:
    Hastings, East Sussex, UK
    cPanel Access Level:
    Root Administrator
    Twitter:
    You have not specified
    Code:
    session_start();
    in your second page which is why it is not set.

    Also, session_start() must be specified before any text is outputted to the system. It's always best to start your page with
    Code:
    <?php
    session_start();
    //Everything else goes underneath
    
     
Loading...

Share This Page