Closed Thread Icon

Topic awaiting preservation: Session Variables Pages that link to <a href="https://ozoneasylum.com/backlink?for=13044" title="Pages that link to Topic awaiting preservation: Session Variables" rel="nofollow" >Topic awaiting preservation: Session Variables\

 
Author Thread
bones
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2003

posted posted 01-30-2004 20:16

This as far as I know is a very basic question. I am developing a project with PHP and it is my first time using the language. I am having trouble seeing session variables on a different page to where they are declared. I start by saying session_start(); , then session_register("FirstName");, and then $_session["FirstName"] = $_POST['First_Name']; to take the value from a form. However when I go to the next page and try use this $_session["FirstName"] variable it holds no value. I am using session_start() again on the next page. I am missing something - as i said I have no real knowledge of PHP and I am finding it hard to get a proper session variables tutorial on the web. Can anyone help me out?

bones

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 01-30-2004 21:34

Personally I prefer to do these things like this:
Page 1:

code:
<?php session_start();

//this would normally come from a form...
$_SESSION['firstName'] = $_POST['firstName'];
?>


Page 2:

code:
<?php session_start();
print($_SESSION['firstName']);
?>


That works for me.
/Dan

{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

bones
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2003

posted posted 01-31-2004 14:34

For some reason this is just not working. Can anyone think of a reason why this would not be working. Do I have to specify somewhere how long I want the session variable to last or something. The code I was given above is exactly how I have it on my site. I am getting really annoyed and confused as I imagine things are bound to get harder but how do I proceed when I acnt get the session variable to save its value from just one page to the next.

bones

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 01-31-2004 16:33

Since session variables are stored on the server as opposed to being stored by the user, you might need to check with your web host to see if they are enabled. I would ask your host what the problem is and why the example code is not working.

If you are your own host, then you should look over your configuration and see how you are storing your session data, and if it is set up correctly.

-Dan-

bones
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2003

posted posted 01-31-2004 16:39

thanks, i think that must be the problem. i am using a local apache server. if anyone knows anything about apache configuration i`d love it if ye could help me out. meantime I`m going to find an apache forum.

bones

norm
Paranoid (IV) Inmate

From: [s]underwater[/s] under-snow in Juneau
Insane since: Sep 2002

posted posted 01-31-2004 19:40

Is ' session_start()' the very first line of code on your page? If you send anything to the browser before it it won't work.......

/* Sure, go ahead and code in your fancy IDE. Just remember: it's all fun and games until someone puts an $i out */

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-31-2004 20:06

The problem is: You haven't read the documentation properly .

You use either session_register() or the $_SESSION array (note the case. Variable names are case sensitive in PHP. Therefore it's $_SESSION not $_session, which I suspect to be your actual problem.)
If you use both methods, strange things happen.

To quote the php manual:

quote:
Caution
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister().




so long,

Tyberius Prime

bones
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2003

posted posted 02-02-2004 15:12

Ya I saw that a few days back and changed it. Still no luck though. All my syntax is definitely right. I have tried putting the session_start(); at the start of the php script, i have tried putting it at the start of the html body in its own php tags, i have tried putting it in the head of the document. nothing works. still no values being saved when i go to the next page. I am looking into my php configuration being wrong somehow but its like looking for a needle in a haystack. any other suggestions would be greatly welcome. (I am using php_4.3.4, and apache_2.04.)

bones

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 02-02-2004 16:12

have you turned on all error reporting with error_reporting(E_ALL) ?
That usually is a good place to start.
You can also try to print out the sid (session_id(), I believe,) to see if it's the same on both pages.

bones
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2003

posted posted 02-02-2004 22:22

Finally I have discovered the source of my problem. After searching hundreds of forums and reports on php, my answer came to me like an angel in the night. Tell the world: IF YOU ARE USING WINDOWS THEN YOU MUST CHANGE THE SESSION_SAVE_DATA VALUE TO C:/TEMP OR C:/WINDOWS/TEMP IN YOUR PHP.INI FILE. For the love of god why dont they say this on the php.net site (or was i just too blind to see it). But there it is, thank you all for your help and no doubt it wont be long before I return again. Adieu Adieu!!

bones

« BackwardsOnwards »

Show Forum Drop Down Menu