$_SESSION Problem state not changing

johnnei

New Member
Messages
20
Reaction score
0
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:

johnnei

New Member
Messages
20
Reaction score
0
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:

marshian

New Member
Messages
526
Reaction score
9
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.
 

johnnei

New Member
Messages
20
Reaction score
0
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:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
You cannot have a blank line or even a single space before the

<? php session_start(); ?>
 

johnnei

New Member
Messages
20
Reaction score
0
Points
0
Its on the absolute top there's nothing in-front of it anymore
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
There must be something in front of it somehow, can you post the entire source again?
 

johnnei

New Member
Messages
20
Reaction score
0
Points
0
I archived it and included it to the post.
 

Attachments

  • site..rar
    31.6 KB · Views: 14

johnnei

New Member
Messages
20
Reaction score
0
Points
0
I will have a look soon on how Dreamweaver Saves the files.. Currently really busy with everything in rl :/
 

johnnei

New Member
Messages
20
Reaction score
0
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 :$
 

Attachments

  • site_10-3..rar
    31.5 KB · Views: 2

marshian

New Member
Messages
526
Reaction score
9
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:

johnnei

New Member
Messages
20
Reaction score
0
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.
savedw.jpg

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:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
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:

johnnei

New Member
Messages
20
Reaction score
0
Points
0
From the screenshot, the option that should affect the presence of the BOM is (surprise, surprise) "Include Unicode Signature (BOM)".
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...
 

johnnei

New Member
Messages
20
Reaction score
0
Points
0
The error is gone now :D
Tnx Now I can start fixing the pages ^^
 
Top