473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

$_SESSION over two + pages

nathj
938 Expert 512MB
Hi,

I am trying to get $_SESSION to work on my site. In order to learn this an dunderstand it better I have built two very simple test pages to see if i can access $_SESSION on both pages.

Page 1
[PHP]
<?php /* Created on: 03/07/2007 */
session_start();?>
<html>
<body>
<?php
$_SESSION['item1'] = "First session variable";
echo $_SESSION['item1'];
echo '<br /> <a href="session2.php"> click here </a>';

?>
</body>
</html>
[/PHP]

This displays the $_SESSION['item1'] correctly and the link takes you to the second page.

Page 2
[PHP]
<?php /* Created on: 03/07/2007 */
session_start();?>
<html>
<body>
<?php
echo 'My first variable: ' . $_SESSION['item1'];
?>
</body>
</html>
[/PHP]

This however, only displays the basic text and nothing comes out from the $_SESSION['item1'].

I am really ew to this idea and I need to understand this is order to get the site I am developing to be properly interactive.

Can anybody see what am missing with this simple example?

Cheers
nathj
Jul 3 '07 #1
19 2158
kovik
1,044 Expert 1GB
You're not missing anything. It sounds like a problem with a local installation. Is this a local test?
Jul 3 '07 #2
nathj
938 Expert 512MB
You're not missing anything. It sounds like a problem with a local installation. Is this a local test?
volectricity,
Yep, it's a local test. I have checked my browsers and cookies are enabled, though I was led to beleive that $_SESSION was completely server side and so did not need cookies. What else could it be? Is there something in the ini file that I need?

Cheers
nathj
Jul 3 '07 #3
kovik
1,044 Expert 1GB
Well, it'd actually be more a filesystem issue.

Here, put this on both pages and tell me if you get the same result:

Expand|Select|Wrap|Line Numbers
  1. echo session_id();
Jul 3 '07 #4
Hi,

I am trying to get $_SESSION to work on my site. In order to learn this an dunderstand it better I have built two very simple test pages to see if i can access $_SESSION on both pages.

Page 1
[PHP]
<?php /* Created on: 03/07/2007 */
session_start();?>
<html>
<body>
<?php
$_SESSION['item1'] = "First session variable";
echo $_SESSION['item1'];
echo '<br /> <a href="session2.php"> click here </a>';

?>
</body>
</html>
[/PHP]

This displays the $_SESSION['item1'] correctly and the link takes you to the second page.

Page 2
[PHP]
<?php /* Created on: 03/07/2007 */
session_start();?>
<html>
<body>
<?php
echo 'My first variable: ' . $_SESSION['item1'];
?>
</body>
</html>
[/PHP]

This however, only displays the basic text and nothing comes out from the $_SESSION['item1'].

I am really ew to this idea and I need to understand this is order to get the site I am developing to be properly interactive.

Can anybody see what am missing with this simple example?

Cheers
nathj

Just a shot in the dark. It happened to me once.

If you first page lets say you call it session.php is called from http://example.com/session.php
and your second page is
http://www.example.com/session2.php

The session is not carried over. see the www and the non www. Make sure both pages are www or both non www.
Jul 3 '07 #5
kovik
1,044 Expert 1GB
The session is not carried over. see the www and the non www. Make sure both pages are www or both non www.
That sounds like it could cause problems. Actually, it's more of issue of the fact that you have the http:// included when you do it.

However, in this post, the sample code uses a relative link.
Jul 3 '07 #6
ak1dnar
1,584 Expert 1GB
Hi,
Have you tried to run ,

[PHP]phpinfo();[/PHP]
and double check your settings.

Jul 4 '07 #7
nathj
938 Expert 512MB
Hi,
Have you tried to run ,

[PHP]phpinfo();[/PHP]
and double check your settings.

I have looked at the phpinfo() results and can see that sessions are enabled and everything there looks like the sample you gave, except hash_bits_per_character = 5 on my installation, I don't know if that has anything to do with it?

Cheers
nathj
Jul 4 '07 #8
nathj
938 Expert 512MB
Well, it'd actually be more a filesystem issue.

Here, put this on both pages and tell me if you get the same result:

Expand|Select|Wrap|Line Numbers
  1. echo session_id();
The session id is the same on both pages.

As for the www I am building this at present on localhost. I have tried using complete and relative paths and this does not affect the current behaviour. I will however, bear that in mind when I come to the production stage of the project.

nathj
Jul 4 '07 #9
Atli
5,058 Expert 4TB
If your server is running on Windows, you must set the 'session.save_path' in your php.ini to a place Apache has permission to use.
This is the folder PHP will use to store the session data, and if it is not set it will not be able to save the data, which causes it to regenerate the session_id every time you call the session_start() method.
Jul 4 '07 #10
nathj
938 Expert 512MB
If your server is running on Windows, you must set the 'session.save_path' in your php.ini to a place Apache has permission to use.
This is the folder PHP will use to store the session data, and if it is not set it will not be able to save the data, which causes it to regenerate the session_id every time you call the session_start() method.
Some technical information then:
OS: Windows Vista Business (sorry it's not my fault)
Webserver: IIS 7.0
PHP Version: 5.2.3
Session: Enable and the save_path = "C:\Users\user\AppData\Local\Temp\php\session" which I do have full permission on.

Interestingly I am also having trouble with php_GD2.dll but one thing at a time I guess.

Thanks for all the help so far, I'm sure we'll get this thing sorted soon.

Cheers
nathj
Jul 4 '07 #11
kovik
1,044 Expert 1GB
Well, check your session_save_path() folder to see if the session files are actually there. If not, you don't have valid permissions.
Jul 4 '07 #12
Atli
5,058 Expert 4TB
Session: Enable and the save_path = "C:\Users\user\AppData\Local\Temp\php\session" which I do have full permission on.
I would recommend moving this out of the Temp thing, to a place like, for example "C:\Inetpub\phpsessions\".
It doesn't really matter whether you have access, Apache must have access to it.
Try giving users like 'System' and 'Local Service' access to it, see if that works. You can also try giving everybody access, just to see if this is really the problem.
Jul 4 '07 #13
Purple
404 Expert 256MB
Hi Nathj

Session: Enable and the save_path = "C:\Users\user\AppData\Local\Temp\php\session" which I do have full permission on.
can you see session records being stored within this location ?

I am running the same config on my development laptop and had more than a few issues with the new security settings in Vista..

Purple
Jul 4 '07 #14
nathj
938 Expert 512MB
Hi Everyone,

First of all thanks for all your help so far. I will now attempt to answer all the questions you have asked:

1) (volectricity) Is there anything in the path specified - No, there's not. It is completely empty.

2) (Atli) Apache having access and moving it to another location: I tried moving it to a different location and changed the variable in the ini file but that didnt' make any difference. Also I do not have Apache installed anywhere, I am using IIS 7 as the webserver

3) (Purple) Session records: I'm not entirely sure what I would be looking for here but the path specified is empty. What security issues did you encouter with Vista? I am so fed up with Vista that I am happy to blame it for anything and everything.

Also I thought I should post the debug information as this may help some more:

Warning: Unknown: open(C:\Users\user\AppData\Local\Temp\php\session\ sess_diuuc9l68mjcpr0tfplaphb2t3, O_RDWR) failed: Permission denied (13) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\Users\user\AppData\Local\Temp\php\session) in Unknown on line 0


I think I have aswered the questions asked. Thanks for the help so far I really appreciate it.
nathj
Jul 5 '07 #15
kovik
1,044 Expert 1GB
Then change the folder to be within the path your server is.

path/to/server/phpsess

It should work.
Jul 5 '07 #16
I had exactly the same problem yesterday with IIS, win xp pro and php sessions.
I would set a value in $_SESSION['count'] on one page and then it would not appear in the next page although the session id was the same on both pages.

It turned out to be the fact that I had copied a php.ini file which had a
session.save_path = "c:/PHP5/sessionfolder"
entry but the actual directory was not there..... as soon as I had created the directory, everything worked as I expected.

Hope that is your answer too.
Jul 6 '07 #17
nathj
938 Expert 512MB
I had exactly the same problem yesterday with IIS, win xp pro and php sessions.
I would set a value in $_SESSION['count'] on one page and then it would not appear in the next page although the session id was the same on both pages.

It turned out to be the fact that I had copied a php.ini file which had a
session.save_path = "c:/PHP5/sessionfolder"
entry but the actual directory was not there..... as soon as I had created the directory, everything worked as I expected.

Hope that is your answer too.
The story at the moment for my session path is that the phpInfo() displays:
C:\Users\user\AppData\Local\Temp\php\session

This path is present and is fuly available. The php.ini file lists a path of:
C:\inetpub\phpSession
Again this path exists and I have full access to it.

The ini file resides in C:\program files\PHP and is the one that phpInfo states is loaded.

This is the only php.ini file I can find on my local system, and as my system is standalone it can't be pulling any from a network location.

I'm really baffled by this and it is now halting development progress - never a nice feeling.

I really appreciate all the help so far and any further thoughts or suggestions are most welcome.
nathj
Jul 6 '07 #18
nathj
938 Expert 512MB
Hi,

Further to my last post I have done a bit more digging and there are a few mysteries.

1) The phpInfo() reports a different file to the php.ini file, a bit of a mystery.

2) The path that phpInfo() lists I don't seem to have access to, I have tried setting this in Vista and while it says I have full permission it doesn't sem to list the special permissions as being available. However, I don't think that is the problem. I tried, via fopen and fwrite to write to a file in the directory phpInfo lists for sessions and failed, however if I try that to another directory with the same permissions it works fine.

3) I also tried chmod() on the file path in question and was told I did not have permission.

All of this suggests that I should use a different file location but how do I do that if the phpInfo() is not reading from the ini file I have?

Cheers
Nathan
Jul 6 '07 #19
nathj
938 Expert 512MB
Hi Nathj



can you see session records being stored within this location ?

I am running the same config on my development laptop and had more than a few issues with the new security settings in Vista..

Purple
Hi Purple,

Did you manage to get it working at all? I can see lots of information on the web stating that this is a problem with Vista, but there has to be a solution, doesn't there?

Cheers
nathj
Jul 6 '07 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: B-B | last post by:
Platform: Win2k Server, Apache 1.3, PHP 4.2.3 I understand that when using $_SESSION variables, using the "session_register()" function should not be done. I have seen no documentation...
4
by: tornado | last post by:
Hello all, I am not able to find the solution to this problem :(. I have two php pages . On the first page i am getting some values in $_SESSION when i use print_r function. I don't get the...
5
by: Ken | last post by:
What am I doing wrong? I set the variable co_name on the first page with an <input.... > and session_start() at the top of both pages. Clicking on a link that takes me to the second page: ...
13
by: Mimi | last post by:
Hello, I am having trouble using the session vars in PHP 4.3.9 OS: Win XP Prof Web Server IIS (is local and there are no links to other servers from the web pages I work on) Browser: IE 6.0 ...
9
by: Quinonez | last post by:
if i set a $_SESSION=$_POST in every page of a multiple page form how then would i call it on a later page of the same session? and also how is distigushed between pages ? should it be set up...
5
by: comp.lang.php | last post by:
Is it possible to access values preset from $_SESSION from within a CLI PHP page? If so, how is it done? Each time I try to access $_SESSION is an empty array; the moment I leave the CLI PHP and...
12
by: Michael Windsor | last post by:
I've been trying to integrate some PHP pages of my own with some existing code. The details of this are for the support forums for that code (where I have been asking questions), but I wonder if...
14
by: Sandman | last post by:
Is there any particular reason I should still use $_POST? Also, I'm reading mixed things about sessions. php.net says you can propagate session IDs either via cookies or session IDs:...
2
by: gm04030276 | last post by:
hey, i'm basically trying to use php sessions and a bit of javascript to make tabbed browsing within a web page using sessions to store the data of the different opened pages. Problem: when i unset...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.