473,770 Members | 7,213 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 6477
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
7789
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 = ""; echo "<form method='POST' action='login.php'>
3
2088
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 attempts to run the query. Usually I can press reload in my browser (Netscape, IE, and Opera) and the...
11
3351
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
2385
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 explaining what I'm doing wrong here & perhaps suggest a better approach.. I'm familiar with use of...
10
3516
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 or will a postback also do it? This is important as we have a few pages that a user
4
1951
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 string value, show it on screen, save it in a session variable and show the session ID on screen....
2
2462
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 public ip of the local server so when I type (out of the local server net) the
5
1973
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 this : .../secure.php?user=joebloggs&randid=324395 Each page looks up the username and checks it...
6
3782
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 large numbers of rows in one of the tables to be updated. (I have done it this way to make the more...
0
9591
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
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
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...
0
8883
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
7415
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
6676
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
5312
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3575
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.