473,385 Members | 1,324 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,385 software developers and data experts.

Sharing session variables

How can I share session registered variables between different processes?
Here is my problem:
File 1:
-----------------------------------------------------------------------
<?php
session_start();
$var1="This should";
$var2="be displayed";
$_SESSION[ 'var1' ]=$var1;
$_SESSION[ 'var2' ]=$var2;
if (session_is_registered('var1')) {
print "Var1 is registered<br>";
}
if (session_is_registered('var2')) {
print "Var2 is registered<br>";
}
print "<A HREF=/work/test2.php>Second File</A>";
?>
File 2:
-----------------------------------------------------------------------
<?php
if (session_is_registered('var1')) {
print "test2:Var1 is registered<br>";
}
if (session_is_registered('var2')) {
print "test2:Var2 is registered<br>";
}

$var1=$_SESSION[ 'var1' ];
$var2=$_SESSION[ 'var2' ];
print "$var1 $var2 <br>";
?>
In file test2.php neither variable is reported as a session registered
variable and nothing is displayed. File /tmp/sess* has the correct
contents:
var1|s:11:"This should";var2|s:12:"be displayed";

How can I establish real global variables, ones which will
be visible in both files? I thought that httpd was supposed
to read the sessxxxxx file, depending on the cookie received from
the browser and establish those global variables.
I apologize if it is a beginer question, but I was unable to
answer it either through the O'Reilly book or PHP online literature.
I'm at the verge of re-installing PHP 4.3.36 with shmop module enabled.
--
Trust me, I know what I'm doing. (Sledge Hammer)

Jul 17 '05 #1
3 2450
make sure you add:
session_start();
and the top of each page that you want to access the variables in.

"Mladen Gogala" <go****@sbcglobal.net> wrote in message
news:pa****************************@sbcglobal.net. ..
How can I share session registered variables between different processes?
Here is my problem:
File 1:
-----------------------------------------------------------------------
<?php
session_start();
$var1="This should";
$var2="be displayed";
$_SESSION[ 'var1' ]=$var1;
$_SESSION[ 'var2' ]=$var2;
if (session_is_registered('var1')) {
print "Var1 is registered<br>";
}
if (session_is_registered('var2')) {
print "Var2 is registered<br>";
}
print "<A HREF=/work/test2.php>Second File</A>";
?>
File 2:
-----------------------------------------------------------------------
<?php
if (session_is_registered('var1')) {
print "test2:Var1 is registered<br>";
}
if (session_is_registered('var2')) {
print "test2:Var2 is registered<br>";
}

$var1=$_SESSION[ 'var1' ];
$var2=$_SESSION[ 'var2' ];
print "$var1 $var2 <br>";
?>
In file test2.php neither variable is reported as a session registered
variable and nothing is displayed. File /tmp/sess* has the correct
contents:
var1|s:11:"This should";var2|s:12:"be displayed";

How can I establish real global variables, ones which will
be visible in both files? I thought that httpd was supposed
to read the sessxxxxx file, depending on the cookie received from
the browser and establish those global variables.
I apologize if it is a beginer question, but I was unable to
answer it either through the O'Reilly book or PHP online literature.
I'm at the verge of re-installing PHP 4.3.36 with shmop module enabled.
--
Trust me, I know what I'm doing. (Sledge Hammer)

Jul 17 '05 #2
On Tue, 01 Jun 2004 22:17:24 -0800, StinkFinger wrote:
make sure you add:
session_start();
and the top of each page that you want to access the variables in.


Thanks a lot. That was it.

--
Trust me, I know what I'm doing. (Sledge Hammer)

Jul 17 '05 #3
Regarding this well-known quote, often attributed to Mladen Gogala's famous
"Wed, 02 Jun 2004 00:49:58 -0400" speech:
How can I share session registered variables between different processes?
Here is my problem:
File 1:
-----------------------------------------------------------------------
<?php
session_start();
$var1="This should";
$var2="be displayed";
$_SESSION[ 'var1' ]=$var1;
$_SESSION[ 'var2' ]=$var2;
if (session_is_registered('var1')) {
print "Var1 is registered<br>";
}
if (session_is_registered('var2')) {
print "Var2 is registered<br>";
}
print "<A HREF=/work/test2.php>Second File</A>";
?>
File 2:
-----------------------------------------------------------------------
<?php
if (session_is_registered('var1')) {
print "test2:Var1 is registered<br>";
}
if (session_is_registered('var2')) {
print "test2:Var2 is registered<br>";
}

$var1=$_SESSION[ 'var1' ];
$var2=$_SESSION[ 'var2' ];
print "$var1 $var2 <br>";
?>
In file test2.php neither variable is reported as a session registered
variable and nothing is displayed. File /tmp/sess* has the correct
contents:
var1|s:11:"This should";var2|s:12:"be displayed";

How can I establish real global variables, ones which will
be visible in both files? I thought that httpd was supposed
to read the sessxxxxx file, depending on the cookie received from
the browser and establish those global variables.
I apologize if it is a beginer question, but I was unable to
answer it either through the O'Reilly book or PHP online literature.
I'm at the verge of re-installing PHP 4.3.36 with shmop module enabled.


Be sure to session_start() the session in test2.php. The session_start()
function is a bit misnamed. You use it to start a new session but you also
use it to continue an old one.

http://us3.php.net/manual/en/function.session-start.php

--
-- Rudy Fleminger
-- sp@mmers.and.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Greg Bryant | last post by:
I'm trying to extend an existing site written in CF. We're going to move it to PHP at some point in the near future, but in the meantime, I'd like to add some minor new features, and can steal...
3
by: Amit S. Jamgade | last post by:
Hi All, I am trying to share the session between classic ASP and ASP.Net application. For session sharing I used the method available on this link: http://msdn.microsoft.com/library/default.asp?...
3
by: Hardik Shah | last post by:
Hi, I am calling an ASP.Net page from an ASP classic application but need the .Net page to have access to ASP classic's session variables. I am using HTTPWebRequest to call ASP classic page...
4
by: Cowboy \(Gregory A. Beamer\) | last post by:
Background: ------------- The idea started as a single sign on type of application. Having tested it before, I knew we could institute single sign on using the same Authentication Cookie name (in...
3
by: grooby | last post by:
I would like to develop an asp.net Web application using muliple web projects under one solution file and share the session information between web applications( or projects). Is this possible?
3
by: Selden McCabe | last post by:
I have an old ASP project, and I'm adding some functionality in ASP.Net. I stuff some information into Session variables in the ASP page, then redirect to the ASP.Net page. But when I pull up...
4
by: W Akthar | last post by:
Hi, I need to pass session state variables across different web applications. Firstly is this possible and secondly can someone show me how please??
2
by: Guy | last post by:
Is there a way to prevent new browsers windows from sharing session variables with the original window? Our team has an ASP.Net app that lets users analyze portfolio risk given certain portfolio...
4
by: abcd | last post by:
I have an ASP application. It instantiaties some COM components and we put those COM components in Session variables...COM components have license restrictions...We have written new ASPX page ( for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...

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.