Session problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dafinch
Forum Commoner
Posts: 25
Joined: Wed Jun 06, 2007 10:34 am

Session problems

Post 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.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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"
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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).
Post Reply