$_SESSION Problem state not changing

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by johnnei, Feb 28, 2010.

  1. johnnei

    johnnei New Member

    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    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:
    <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:
    $_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:
    <?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: Mar 1, 2010
  2. espfutbol98

    espfutbol98 New Member

    Messages:
    200
    Likes Received:
    2
    Trophy Points:
    0
    Try putting <?php session_strat(); ?> at the absolute top of the page.
     
  3. marshian

    marshian New Member

    Messages:
    526
    Likes Received:
    9
    Trophy Points:
    0
  4. johnnei

    johnnei New Member

    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    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: Mar 1, 2010
  5. marshian

    marshian New Member

    Messages:
    526
    Likes Received:
    9
    Trophy Points:
    0
    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.
     
  6. johnnei

    johnnei New Member

    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    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: Mar 1, 2010
  7. descalzo

    descalzo Grim Squeaker Community Support

    Messages:
    9,375
    Likes Received:
    327
    Trophy Points:
    83
    You cannot have a blank line or even a single space before the

    <? php session_start(); ?>
     
  8. johnnei

    johnnei New Member

    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    Its on the absolute top there's nothing in-front of it anymore
     
  9. marshian

    marshian New Member

    Messages:
    526
    Likes Received:
    9
    Trophy Points:
    0
    There must be something in front of it somehow, can you post the entire source again?
     
  10. johnnei

    johnnei New Member

    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    I archived it and included it to the post.
     

    Attached Files:

  11. misson

    misson Community Paragon Community Support

    Messages:
    2,572
    Likes Received:
    72
    Trophy Points:
    48
    Last edited: Mar 3, 2010
  12. johnnei

    johnnei New Member

    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    I will have a look soon on how Dreamweaver Saves the files.. Currently really busy with everything in rl :/
     
  13. johnnei

    johnnei New Member

    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    I saw that I had to uncheck a little box "Include Unicode Signature (BOM)" As un-checked I checked all files but only on index.php was that box there ... so re-uploaded all files (just to be sure ^^) but still same. I'll re-attach files.

    (Sorry for double post) Just for make you guy's check the topic again :$
     

    Attached Files:

  14. marshian

    marshian New Member

    Messages:
    526
    Likes Received:
    9
    Trophy Points:
    0
    There's still some sort of header in the file. It's a 3 byte code: EF BB BF, but I don't know what causes it. There must be some option in Dreamweaver... (I don't have it, nor do I have any experience with it, sorry.)
    What encoding are you saving the file as? Have you tried UTF-8 or ASCII?

    Edit: just to confirm, the header is the same as the one in the files you uploaded earlier.
    Edit again: the header does not appear in a number of other files, such as data/common.php or data/header.php, both in the old and new versions.
     
    Last edited: Mar 10, 2010
    • Like Like x 1
  15. johnnei

    johnnei New Member

    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    Ye. I noticed that .. index.php is the ONLY file I can pick that save type... I'll post screen about howto save.
    [​IMG]
    The C thing is standard maybe I have to put that to None? And Where can I see the BOM in the file (while using Hex-Editor). Is it just on top of file or somewhere else?
    Edit: nvm it are the 1st 3 bytes :$
    Putting the C to None still contains the BOM :/
     
    Last edited: Mar 10, 2010
  16. misson

    misson Community Paragon Community Support

    Messages:
    2,572
    Likes Received:
    72
    Trophy Points:
    48
    Unicode normalization affects how certain equivalent characters are saved (e.g. "\uE9" (é) vs "e\u0301" (e with combining-acute)) and has nothing to do with the BOM. From the screenshot, the option that should affect the presence of the BOM is (surprise, surprise) "Include Unicode Signature (BOM)".
     
    Last edited: Mar 10, 2010
  17. johnnei

    johnnei New Member

    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    Oh my god! Your ****ting me?... I not that smart.. but he.. I'm not dumb also -.-
    I unchecked it made it overwrite it and its still there...
     
  18. misson

    misson Community Paragon Community Support

    Messages:
    2,572
    Likes Received:
    72
    Trophy Points:
    48
    • Like Like x 1
  19. johnnei

    johnnei New Member

    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    The error is gone now :D
    Tnx Now I can start fixing the pages ^^
     

Share This Page