473,786 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

$_SESSION over two + pages

nathj
938 Recognized Expert Contributor
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 2189
kovik
1,044 Recognized Expert Top Contributor
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 Recognized Expert Contributor
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 Recognized Expert Top Contributor
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
phpmike
5 New Member
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 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
Hi,
Have you tried to run ,

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

Jul 4 '07 #7
nathj
938 Recognized Expert Contributor
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_c haracter = 5 on my installation, I don't know if that has anything to do with it?

Cheers
nathj
Jul 4 '07 #8
nathj
938 Recognized Expert Contributor
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 Recognized Expert Expert
If your server is running on Windows, you must set the 'session.save_p ath' 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

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

Similar topics

4
6166
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 pertaining the the "why" of this, but I am removing the offending statements from my code anyway. Prior to discovering this tidbit, I had been attempting to save some arrrays in individually registered variables. But the arrays were not being saved...
4
12300
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 values when i use just echo() or print() functions. Now, the first page calls the second php page. But when i try to get the values for $_SESSION on the second page i get empty values even when i use print_r() function. register.globals is set...
5
2977
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: Script on the second page. echo $_SESSION; Does not display
13
23339
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 The problem I am having is that each time I reload the same PHP page, I get
9
6798
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 differently on each page, ive read of $_SESSION=$_POST but i cant seem to figure out how to call it back at the end of the form
5
13300
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 return to my calling web-app PHP script, $_SESSION is back again, values and all, completely untouched. Can $_SESSION be called? If not, then I have a bigger problem inasmuch as $_REQUEST variables set via form/query-string MUST be accessed from...
12
41192
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 someone here can enlighten me as to why the problematic code is having the effect it is. For reasons I don't know, if the PHP version is 5 or greater, register_long_arrays is false and $_SESSION exists, the following statement is executed: ...
14
5881
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: http://www.php.net/manual/en/ref.session.php#session.idpassing OK cool. However, PHP in a nutshell makes no mention of this. Paul just says hey, use session_start() and you're on your way:
2
2034
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 the first 0 index in the array (ie close the default page) it seems to wipe the other one (can't get it to add more that one anymore) from the array also the information is held in sub array $_SESSION each page has its own array of infomation...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10360
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10108
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.