Page 1 of 1

session_start() not holding data

Posted: Thu Dec 25, 2008 12:43 pm
by Teonnyn
I'm having a small problem with my sessions. When a user logs in, one session is created and holds their username. In theory, this is transferred over to another page with the same session. The page then outputs the username in a format that Flash understands (or will, later). While the script with the first session_start is located in a module directory, it is rendered on the main page. I've located the second session_start page in the main folder as well, and tried it where the script is located - but there's nothing indicating that the session is being carried over.

mod_greeter.php

Code: Select all

 
session_start();
 
$user =& JFactory::getUser();
$username = $user->username;
$timeid = time();
 
if ($user->guest) {
$_SESSION['usernametest'] = "guest";
echo "<p>User: {$_SESSION['usernametest']}</p>";
echo $ip=$_SERVER['REMOTE_ADDR'];
echo "<p>{$timeid}</p>";
echo htmlspecialchars(SID);
 
} else { 
$_SESSION['usernametest'] = $username;
echo "<p>User: {$_SESSION['usernametest']}</p>";
echo $ip=$_SERVER['REMOTE_ADDR'];
echo "<p>{$timeid}</p>";
echo htmlspecialchars(SID);
 
}
?>
  </div>
</div>
 
output.php

Code: Select all

<?php
session_start();
echo "Your username is:{$_SESSION['usernametest']}";
?>
The output viewed by users is this:

User: Guest
72.234.244.122

1230230512
However, the only output I'm getting from "output.php" is:
"Your username is:"

Re: session_start() not holding data

Posted: Thu Dec 25, 2008 2:53 pm
by aditya2071990
Maybe the way the thing is being echoed is not working for some reason.. try concatenating with dots instead, like:

Code: Select all

echo "Your username is:".$_SESSION['usernametest']."";

Re: session_start() not holding data

Posted: Thu Dec 25, 2008 3:10 pm
by Teonnyn

Code: Select all

<?php
session_start();
$user = $_SESSION['usernametest'];
echo "Your username is: $user";
?>
Well, I tried it this as well - no response

Re: session_start() not holding data

Posted: Thu Dec 25, 2008 3:31 pm
by aditya2071990
Are you getting a response for this?

Code: Select all

 
<?php
session_start();
$user = $_SESSION['usernametest'];
echo "Your username is:".$user."";
?>
 

Re: session_start() not holding data

Posted: Thu Dec 25, 2008 5:01 pm
by Teonnyn
Nope, nothing, in either the module's main directory or the main folder for the website.
All it's giving me is "your username is:"

Re: session_start() not holding data

Posted: Thu Dec 25, 2008 5:28 pm
by Teonnyn
session_start() is identified in mod_greeter.php, but it doesn't seem to want to transfer it to anything. I've tried running the output.php in both the directory mod_greeter is in and as well the top directory, but neither gives me anything. Some of the research I did indicated that potentially, session_start() only works in the directory it's called in, and won't pass a variable above or below it. That doesn't seem to be the case, however. I even tried putting session_start in the if/else structure.

Re: session_start() not holding data

Posted: Thu Dec 25, 2008 5:42 pm
by John Cartwright
Theres a couple reasons why this may not be working,

1) Cookies are disabled, and session.use_trans_id is disabled in your php. Meaning, the session id is never saved because it cannot be passed by cookie or the url
2) Your session directory is not writable. Check your error logs.

Those are the two most obvious ones. Let us know how it goes.

Re: session_start() not holding data

Posted: Thu Dec 25, 2008 5:57 pm
by Teonnyn
Okay - this can't be good. I changed the permissions on the output file to write, and it immediately declared a error.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@***.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

Changing it back to normal settings - 644, killed the error as well.

Re: session_start() not holding data

Posted: Thu Dec 25, 2008 5:58 pm
by Syntac
Would this be Apache or IIS?

Re: session_start() not holding data

Posted: Thu Dec 25, 2008 5:59 pm
by Teonnyn
Apache, reseller account - but I'm the one in control of the account.
I want to add that I've done other sessions, as tests and they transfered
the data without problem.. just have to figure out why this one isn't working.

Re: session_start() not holding data

Posted: Fri Dec 26, 2008 2:50 pm
by Teonnyn
Bumping post up, slipped to second page and still haven't figured this out! I'm not really sure what's going on and I really don't want to do this using cookies as cookies seem to have a hard time updating with the frequency needed.

Re: session_start() not holding data

Posted: Fri Dec 26, 2008 6:28 pm
by John Cartwright
I also forgot to ask, what is your current error reporting level? It is possible you are sending output before the session has started, although the errors are being suppressed (thus not setting the session). This can be caused even by invisible characters, so it is worth a shot opening the files in question in notepad and resaving them.



It's a bit dificult to say as I've never had this occur personally.

And in the future, please wait at least 24 hours before bumping your post.

Re: session_start() not holding data

Posted: Fri Dec 26, 2008 8:14 pm
by Teonnyn
I'm not really sure how to trigger error reporting, so I'd have to say none honestly. (sorry about the post bump ^^;)
I also played around a little on another domain of mine on the same server and moved a session-enabled file around to different directories.
It was a very basic file but it told me what I needed to know: Doesn't matter where the file is, it seems to be able to recieve the
basic session variable on my other domain.