+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: $_SESSION Problem state not changing

  1. #1
    johnnei is offline x10Hosting Member johnnei is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    20

    $_SESSION Problem state not changing

    Ey,

    I use $_SESSION to save a login to acces some extra paged (duh -.-)...
    But all variables are getting saved right but the already asigned one won't change.
    I got this on top of my page:
    PHP Code:
    <link href="data/style.css" rel="stylesheet" type="text/css">
    <style type="text/css">
    <?php 
    if(!isset($_SESSION))
    {
        
    session_start();
        
    $_SESSION['login'] = "true";
        echo 
    'NEW Session has been started<br>';
    }
    ?>
    @import url("data/style.css");
    </style>
    <script type="text/javascript" src="./data/lang.js"></script>
    This is on index.php and through index.php all other pages are including using include(x);.

    When a log-ing succeeds it will generate this:
    PHP Code:
    $_SESSION['login'] = "false";
    $_SESSION['id'] = "".$myrow['id'];
    $_SESSION['acc'] = "".$myrow['acc'];
    echo 
    'You have been logged in, Login Requierd: '.$_SESSION['login'].'<br>';
    echo 
    'Account ID has been set to: '.$_SESSION['id'].'<br>';
    echo 
    'Account Name has been set to :'.$_SESSION['acc'].'<br>'
    The output of the $_SESSION's are on that area: false, 5, Johnnei.
    But above that the vars are also shown and there the id and acc are set fine but login is still on true.
    Why does this occur?

    Edit 1: Added index.php
    Edit 2: Renewed source :D
    PHP Code:
    <?php session_start(); ?>
    <link href="data/style.css" rel="stylesheet" type="text/css">
    <!--<style type="text/css">
    @import url("data/style.css");
    </style> !-->
    <script type="text/javascript" src="./data/lang.js"></script>
    <center>
    <?php
    include("./data/common.php");
    include(
    "./module/user_data.php");
    include(
    "./data/header.php");
    $op "news";
    //Get Page
    if (isset($_GET['do']))
    {
        
    $op "" $_GET['do'];
    }
    else
    {
        
    $op "news";
    }

    if(
    $op == "reg")
    {
        include(
    "module/register.php");
    }
    else if(
    $op == "news")
    {
        include(
    "module/news.php");
    }
    else if(
    $op == "man")
    {
        include(
    "module/manage.php");
    }
    else if(
    $op == "ins")
    {
        include(
    "module/install.php");
    }
    else if(
    $op == "ser")
    {
        include(
    "module/server.php");
    }
    else
    {
        echo 
    'The current page is not found in the server.';
    }
    ?>
    </center>
    Gr, Johnnei
    Last edited by johnnei; 03-01-2010 at 03:15 PM. Reason: Added index.php, renew

  2. #2
    espfutbol98's Avatar
    espfutbol98 is offline x10 Sophmore espfutbol98 is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Zagreb... želim
    Posts
    200

    Re: $_SESSION Problem state not changing

    Try putting <?php session_strat(); ?> at the absolute top of the page.

  3. #3
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: $_SESSION Problem state not changing

    I think you should take a good look at this: http://www.php.net/manual/en/intro.session.php
    And pretty much everything it links to.
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

  4. #4
    johnnei is offline x10Hosting Member johnnei is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    20

    Re: $_SESSION Problem state not changing

    Well As people dont really get me I'll add on 1st post the complete index.php. Cus on the index is almost the first thing (to avoid errors with headers etc) session_start and that is the absolute page of everything on the site.
    Last edited by johnnei; 03-01-2010 at 09:44 AM.

  5. #5
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: $_SESSION Problem state not changing

    If, and only if, I understand your problem correctly, this behaviour is normal. When you enter the page $_SESSION isn't set, not even if the client is currently associated with a session. (Sessions are not always (this is a setting in php.ini) automatically resumed.) Thus, you enter the if statement. session_start() will then either start a new session or continue a current session. Either way, $_SESSION["login"] is set to false.

    First of all, you'll want to move session_start() to the absolute top of your page (even before the html-tag). Secondly, isset($_SESSION) will never give the result you want to achieve. A better way to do it would be isset($_SESSION["login"]).

    PS: "almost the first thing" is not good enough, when you use headers like cookies, sessions, header(), ... you'll need to put it before any output.
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

  6. #6
    johnnei is offline x10Hosting Member johnnei is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    20

    Re: $_SESSION Problem state not changing

    Hmm... okey I will try a few things.

    Well now i put it on line 1: <?php session_start(); ?> this error occurs.. which is for me ocward but...
    
    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/johnnei/public_html/wow/index.php:1) in /home/johnnei/public_html/wow/index.php on line 1

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/johnnei/public_html/wow/index.php:1) in /home/johnnei/public_html/wow/index.php on line 1
    Last edited by johnnei; 03-01-2010 at 03:11 PM.

  7. #7
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,267

    Re: $_SESSION Problem state not changing

    You cannot have a blank line or even a single space before the

    <? php session_start(); ?>
    Nothing is always absolutely so.

  8. #8
    johnnei is offline x10Hosting Member johnnei is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    20

    Re: $_SESSION Problem state not changing

    Its on the absolute top there's nothing in-front of it anymore

  9. #9
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: $_SESSION Problem state not changing

    There must be something in front of it somehow, can you post the entire source again?
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

  10. #10
    johnnei is offline x10Hosting Member johnnei is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    20

    Re: $_SESSION Problem state not changing

    I archived it and included it to the post.
    Attached Files

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Domain Changing Problem
    By freefly in forum Free Hosting
    Replies: 2
    Last Post: 10-17-2008, 09:32 AM
  2. problem changing domain
    By ffakename in forum Free Hosting
    Replies: 1
    Last Post: 07-15-2008, 03:17 AM
  3. Problem changing my sub-domain
    By Movieserv in forum Free Hosting
    Replies: 4
    Last Post: 05-01-2008, 02:16 PM
  4. problem after changing the domain
    By xoicexo in forum Free Hosting
    Replies: 6
    Last Post: 04-01-2008, 04:52 AM
  5. Problem when changing my DNS!
    By marox in forum Free Hosting
    Replies: 4
    Last Post: 12-17-2007, 02:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers