Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > PHP
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help.

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 07-01-2007, 3:56 PM   #1
Peter
 
Peter's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default 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.php" NAME=menu>
<FRAME SRC="testhome.php" NAME=main>
</FRAMESET>
</HTML>

***************************************
testmenu.php
***************************************
<HTML>
<HEAD>
<title>Menu</title>
</HEAD>
<BODY>
<A href='login001/testsetvar.php' target='main'>Set</A> the session
variable<BR><BR>
<A href='fb001/testfb.php' target='main'>Read</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_register('testvar');

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

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

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

if(session_is_registered('testvar')):
$reg="the testvariable IS registered";
else:
$reg="the testvariable is NOT registered";
endif;
print("var = ".$testvar."<BR>reg = ".$reg."<BR>session 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>

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



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Advertisements
Old 07-01-2007, 3:56 PM   #2
Nathan
 
Nathan's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Session variable reading doesn't work

Peter say...

> session_register('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_globals 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_register.

If I used session_register with register_globals 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_register) everytime.

--
Nathan.
XBL Gamertag: Cowfield
http://www.cowfields.com
Bow to the Cow!
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 3:56 PM   #3
Robert Jirik
 
Robert Jirik's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Session variable reading doesn't work

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(at)aristoteles(dot)xhaven(dot)net]
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"

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 3:56 PM   #4
Peter
 
Peter's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Session variable reading doesn't work

I removed the references to session_start() and session_is_registered() 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.


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 3:56 PM   #5
Peter
 
Peter's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Session variable reading doesn't work

I removed the references to session_start() and session_is_registered() 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.


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 3:57 PM   #6
Robert Jirik
 
Robert Jirik's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Session variable reading doesn't work

Monday 28 of July 2003 14:40, Peter wrote in alt.php:

> I removed the references to session_start() and session_is_registered()
> and replaced them with the $_SESSION way of setting and reading the
> variable but ... ALAS it still doesn't work. Any other ideas?


well, session_start() should stay as it is ... it should look like the
following:

==

test1.php:

session_start();
$_SESSION['test'] = 'schizophrenic hamster';
echo "<A HREF=\"test2.php\">check_it_out</A>";

test2.php:

session_start();
echo "My candidate for the prime minister is: " . $_SESSION['test'];

==

hope I didn't make any silly mistake in there )

if that doesn't work, try to check the session save path in php.ini + check
the session data in the file they are written to (usually /tmp in *nix,
c:\temp in Win) ...

--
Robert Jirik
[mailto:robert(at)aristoteles(dot)xhaven(dot)net]
public PGP key: http://xhaven.net/robert/pgp_key.asc
-
"The future belongs to those
who believe in the beauty of their dreams"
-- Eleanor Roosevelt

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 3:57 PM   #7
Peter
 
Peter's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Jippie .. Session variable reading does work

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_register().

Thank you all for your replies.

Peter.


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 3:57 PM   #8
Nathan
 
Nathan's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Jippie .. Session variable reading does work

Peter say...

> Nathan was right!!


Yay!

--
Nathan.
XBL Gamertag: Cowfield
http://www.cowfields.com
Bow to the Cow!
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags: , , , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
set session variable with <a href>- how? Anthony M. Saffer PHP 0 07-01-2007 3:47 PM
Session variable seems not work Simon PHP 0 07-01-2007 3:33 PM
Variable sound quality from MP3s burned to different media types? rudicheow@gmail.com Car audio 2 06-18-2007 4:44 PM
regex for PHP variable name Sebosac PHP 2 05-20-2007 6:34 PM
regex for PHP variable name Sebosac PHP 0 05-20-2007 6:34 PM


Featured Websites




All times are GMT +1. The time now is 12:00 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98