473,574 Members | 2,927 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session variable reading doesn't work

L.S.

I am developing a PHP-login script (on Lycos Tripod) that uses Session to
pass on variables. Below is the entire (stripped) structure that I use. It
opens a page where you can Set and Read the session variable BUT ... It
doesn't work!!! It seems that both set- and readlink open their own private
session.

How can I get the read-link to access the proper session variable?

Below is a full testing environment. It uses frames and should work fine ...
but it doesn't. I use this directory-structure:
testindex.php
testmenu.php
testhome.php
login001 [dir]
-----testsetvar.php
-----testreadvar.php
fb001 [dir]
-----testfb.php
-----testframe1.php
-----testframe2.php

The content of the files is:
*************** *************** *********
testindex.php
*************** *************** *********
<HTML>
<HEAD>
<title>page</title>
</HEAD>
<FRAMESET BORDER="on" cols="200,*">
<FRAME SRC="testmenu.p hp" NAME=menu>
<FRAME SRC="testhome.p hp" NAME=main>
</FRAMESET>
</HTML>

*************** *************** *********
testmenu.php
*************** *************** *********
<HTML>
<HEAD>
<title>Menu</title>
</HEAD>
<BODY>
<A href='login001/testsetvar.php' target='main'>S et</A> the session
variable<BR><BR >
<A href='fb001/testfb.php' target='main'>R ead</A> the session variable
</BODY>
</HTML>

*************** *************** *********
testhome.php
*************** *************** *********
<HTML>
<HEAD>
<title>Home</title>
</HEAD>
<BODY>
This is the Homepage
</BODY>
</HTML>

*************** *************** *********
testsetvar.php
*************** *************** *********
<?php
session_start() ;
session_registe r('testvar');

$testvar="this is the testvariable";
if(session_is_r egistered('test var')):
$reg="the testvariable IS registered";
else:
$reg="the testvariable is NOT registered";
endif;

print("var = ".$testvar."<BR >reg = ".$reg."<BR>ses sion ID =
".session_id(). "<BR>");
?>

*************** *************** *********
testreadvar.php
*************** *************** *********
<?
session_start() ;

if(session_is_r egistered('test var')):
$reg="the testvariable IS registered";
else:
$reg="the testvariable is NOT registered";
endif;
print("var = ".$testvar."<BR >reg = ".$reg."<BR>ses sion ID =
".session_id(). "<BR>");
?>

*************** *************** *********
testfb.php
*************** *************** *********
<HTML>
<HEAD>
<title>page</title>
</HEAD>
<FRAMESET BORDER="on" cols="*,150">
<FRAME SRC="testframe1 .php" NAME=frame1>
<FRAME SRC="testframe2 .php" NAME=frame2>
</FRAMESET>
</HTML>

*************** *************** *********
testframe1.php
*************** *************** *********
<?
include("../login001/testreadvar.php ");
?>
<HTML>
<HEAD>
<title>Home</title>
</HEAD>
<BODY>
<BR>This is frame1<BR>
</BODY>
</HTML>

*************** *************** *********
testframe2.php
*************** *************** *********
<HTML>
<HEAD>
<title>Home</title>
</HEAD>
<BODY>
<BR>This is frame2
</BODY>
</HTML>

*************** *************** *********

Jul 16 '05 #1
5 6467
Peter say...
session_registe r('testvar');

$testvar="this is the testvariable";


I might be wrong, but first off is it that you have to register testvar
after you've actually declared it? As I say I may be way off there.

The other thing is to check if you've got register_global s on in your
php.ini file.

If it's off (which is the default IIRC) then the above won't work.
Alternatively, just use $_SESSION["testvar"] = "this is the testvariable";

With the $_SESSION[] array, you do not need to use session_registe r.

If I used session_registe r with register_global s off, I got error messages
and things didn't work as planned.

using $_SESSION is quicker anyway, because you can just treat it like you
might $testvar but without having to bother with another function
(session_regist er) everytime.

--
Nathan.
XBL Gamertag: Cowfield
http://www.cowfields.com
Bow to the Cow!
Jul 16 '05 #2
Monday 28 of July 2003 14:01, Nathan wrote in alt.php:

I might be wrong, but first off is it that you have to register testvar
after you've actually declared it? As I say I may be way off there.


that's the point ... but as you said, it's better to use $_SESSION['var']
anyway ...

--
Robert Jirik
[mailto:robert(a t)aristoteles(d ot)xhaven(dot)n et]
public PGP key: http://xhaven.net/robert/pgp_key.asc
-
"Real programmers don't work from 9 to 5. If any real programmers
are around at 9am it's because they were up all night"

Jul 16 '05 #3
I removed the references to session_start() and session_is_regi stered() and
replaced them with the $_SESSION way of setting and reading the variable but
.... ALAS it still doesn't work. Any other ideas?

Thanks for your replies anyway, Peter.

Jul 16 '05 #4
I finally got it working. I went back to the original code, using
session_start() etc. Nathan was right!! Apparantly, you must first declare
the variable and then make a call to session_registe r().

Thank you all for your replies.

Peter.
Jul 16 '05 #5
Peter say...
Nathan was right!!


Yay!

--
Nathan.
XBL Gamertag: Cowfield
http://www.cowfields.com
Bow to the Cow!
Jul 16 '05 #6

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

Similar topics

1
7774
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains: ---------------------------------------------------------------------------- <?php ini_set("session.use_cookies", "off"); ini_set("session.use_trans_sid", "on"); session_start(); $_SESSION = ""; $_SESSION =...
3
2077
by: Michael J. Astrauskas | last post by:
I have a site where a user logs in and a session variable I created is used to keep track of the fact that the user is logged in. This various pages query a MySQL database to get information (mostly to generate a catalogue and news page). Occasionally when loading a page I simply get the error "No database selected" when the PHP script...
11
3332
by: doltharz | last post by:
Please Help me i'm doing something i though was to be REALLY EASY but it drives me crazy The complete code is at the end of the email (i mean newsgroup article), i always use Option Explicit and Response.Expires=-1,
9
2372
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use - perhaps I'm just not very smart or perhaps MS is making this too hard for us sql bunnies to understand - I dunno, but I'd really appreciate someone...
10
3494
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much more time I have on a session? If I do a refresh, does reset the session clock? Do you have have to go to another page to reset the session timeout...
4
1945
by: T Ralya | last post by:
I am told that ASP.NET controls the session ID and session variables, but that does not fit my symptoms. I am posting here as directed. I'm hoping that someone can at least recommend something to try to isolate the problem. I have a simple application that demonstrates my problem. Page 1, step1: SaveSessionVariableButton will create a...
2
2455
by: fReDiNi | last post by:
Hi, I have an strange problem with session variables. I have a site hosted in a local server. I have physic access to this server and its configuration.(apache, php,files...). I have external access to the web site by typing the public ip address of the local server. I have a domain too, and this domain is redirected to the static...
5
1964
by: Chenky | last post by:
Hi all, I'm not a overly experienced PHP programmer but I like to dabble and I'm working on a 'semi-secure' member's area. Previous I have used normal variables to determine the validity of a user. i.e. Once the user has logged in, a random id is created an placed in the database in their row and each secured page will have a URL like...
6
3762
by: ChrisAtWokingham | last post by:
I have been struggling with unexpected error messages on an ASP.NET system, using SQL and C#. The application draws organisation charts, based on data stored in the SQL database. Some of the chart editing processes place a very heavy load on the server as the effects of the edit ripple through the organisation structure, requiring potentially...
0
7805
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...
0
8053
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. ...
0
8237
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7817
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...
0
8098
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6454
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...
0
5301
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...
0
3741
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2245
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

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.