Page 1 of 1

Session problems

Posted: Thu Jun 07, 2007 9:01 am
by dafinch
I'm having a session problem that I believe is a configuration issue on my web server. Its a box I control and has red hat enterprise 5 installed on it. The version of php thats installed is 5.1.6 according to phpinfo. What is happening is when I try to access any data I've put into a session variable the web page doesnt respond. I am using session_start(), these are the first three lines of my code

Code: Select all

<?php
session_start();
?>

Here is the line i'm using to see whats in the session variable i've set earlier

Code: Select all

echo "$_SESSION['logsearch']<br>";
Here is the error message from the error_log from my web server when it executes this line

[Thu Jun 07 09:09:30 2007] [error] [client 149.161.73.89] PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/index.php on line 22


It doesnt generate any errors when I put something into a session variable, just when I try to access it. Any tips as to what might be wrong would be appreciated.

Posted: Mon Jun 11, 2007 8:14 am
by tecktalkcm0391
I don't think you can put any gobal variables in " " 's try....

Code: Select all

echo $_SESSION['logsearch']."<br>"; //the . is like a "and this too"

Posted: Mon Jun 11, 2007 1:37 pm
by RobertGonzalez
Sure you can, you just need to know how PHP parses strings (which is very well documented in the PHP manual):

Code: Select all

<?php
echo "{$_SESSION['logsearch']}<br />";
?>
Alternatively, you could do (which is what I suggest you do):

Code: Select all

<?php
echo $_SESSION['logsearch'] . '<br />';
?>
You could even do:

Code: Select all

<?php
echo "$_SESSION[logsearch]<br />";
?>
but I would not recommend it (at least in my opinion it makes it a little harder to read).