sessions

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
crzyman
Forum Newbie
Posts: 18
Joined: Fri Sep 16, 2005 10:44 pm

sessions

Post by crzyman »

On page one I have this at the top of the page:

Code: Select all

session_start();  
header("Cache-control: private"); 
$bandname = "aaa"; 
$_SESSION["bandname"] = $bandname;
And on page two I have this:

Code: Select all

session_start(); 
header("Cache-control: private"); //IE 6 Fix 
$bandname = $_SESSION['bandname'];
The problem is the value of $_SESSION['bandname'] isn't being passed. Can someone please tell me what I am doing wrong? Many thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

are you positive the session actually set? If you have any output before the session is started, the session will not be able to set correctly.

Make sure you have error_reporting turned on to E_ALL, do not disable any types of messages.
crzyman
Forum Newbie
Posts: 18
Joined: Fri Sep 16, 2005 10:44 pm

Post by crzyman »

Thanks for looking. I am positve that there is no output prior to the session starting. I am not sure how to turn on error_reporting to E_ALL If it is on by default then it must still be on. I also don't know how to disable any types of messages so that to must be good. I don't know why this won't work. Thanks for your time.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

first, look at the output of phpinfo() to see where your error_reporting setting is at (it should be at 2047 I believe).. at any rate you can check what's actually set by going into your php.ini. By default, I think most versions set E_ALL & ~E_NOTICE

While you are in there, check to see that display_errors is on/1.
crzyman
Forum Newbie
Posts: 18
Joined: Fri Sep 16, 2005 10:44 pm

Post by crzyman »

error_log /logs/scripts.log /logs/scripts.log

error_reporting no value no value

This is what I see in my php.inf. I get sessions to work if I use this method.
page 1

Code: Select all

<?

session_register("bandname");
$bandname = "aaa";

?>

<FORM METHOD="POST" ACTION="test.php"> 

<input type="Submit" name=$bandname value="Submit"> 
 
  </form>
page 2

Code: Select all

<?php 
session_start(); 
header("Cache-control: private"); //IE 6 Fix 

echo "<strong>Step 2 - Register Session </strong><br />"; 

?> 
Welcome to my website <strong><? echo $_SESSION['bandname']; ?></strong>!
That works perfect, but I need it to work the way I have it in my original post. Any ideas?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

session_register() should not be used at all costs, as you may know.

Did you change error_reporting and display_errors to the values I've said (E_ALL and On) respectively in your php.ini? (You should need to restart the web server process as well, depending on installation settings)

it seems strange that session_register() would work though.. hmmm....
crzyman
Forum Newbie
Posts: 18
Joined: Fri Sep 16, 2005 10:44 pm

Post by crzyman »

I will do what you said. Thank you for your help.
Post Reply