Sessions

This is a discussion on "Sessions" within the PHP Forum section. This forum, and the thread "Sessions are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Feb 22nd, 2006, 13:40
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Sessions

Hi, im trying to start a session and print its ID but its not working.
Hers the code

HTML: Select all
<?php
session_start( );
?>
<html>
<head>
<title>Session ID</title>
</head>
<body>
<?php
print "Welcome to session number: ";
print $PHPSESSID;
?>
</body>
</html>
And im getting the following output
Welcome to session number:

Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

I don't understand what this is going on about, im using an earlier version than 4.2.3 and (4.1 something).
Is there an easy way to fix this
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Feb 22nd, 2006, 14:21
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Sessions

try using session_id() instead of $PHPSESSID...
see here for more information
http://uk2.php.net/manual/en/function.session-id.php
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Feb 22nd, 2006, 15:52
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Sessions

Hi, that makes it print the session ID but its still gicing the warning.

Also (and more importantly) when I add a variable to the session, how do I retrieve that variable later on on a page a couple of links ahead. Im just messing around with them so I don't have a real example but this is the sort of thing im trying to do

Page 1 -> start session, add variable (Ive done this bit)
Page 2 -> Just a HTML link page (doesn't need the session)
Page 3 -> Only accesible from page 2, opens session (done this) and retrieves the variable value (I don't know how to do this)

If the varaible is called "$name" how do I print its value on page 3, because im assuming if i just put echo"$name"; its going to look for a varaible called $name on the page and not in the session

Im just doing this to help me understand how you can use sessions to save having to pass all the variables using forms.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Feb 24th, 2006, 19:13
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Sessions

Im trying to use sessions to make a login system but its not working, my code is

PHP: Select all

<?php
session_start
();
if (
$_SESSION[logged_in] == 'yes') {$members "./member.php";}
else {
$members "./register.php";}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Im trying to make it so if the session variable $logged_in is set to yes, the link is set to members.php and if its not set to yes, it goes to a registration screen. I set $logged_in to "yes" if the user logs in and it prints the value yes. When I then go to the page with the above code on, i expected it to execute the above code but it appears to always evaluate as false. Can anyone tell me what im doing wrong, thanks


Does anyone know if what im doing is right, I just can't seem to get it working

Last edited by djme; Feb 24th, 2006 at 22:17.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Feb 25th, 2006, 12:10
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Sessions

Ive been doing a bit of reading on the net and it seems this is important to say.

Im trying to access a session variable on a different page to where it was registered

Do this mean I have to declare or access it differently to if I was just using it on that page? I want the session variable to be accessible to all pages. I still can't find what I need to do to make it work though, I read that it should be declared globally but I don't know how to do this
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
sessions

Thread Tools

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

BB 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
Little help on sessions? ktsirig PHP Forum 0 Mar 2nd, 2006 22:12
xsl, php sessions (please help) marco_van_mayo Other Programming Languages 0 Feb 19th, 2006 14:35
php sessions fragalot PHP Forum 7 Nov 8th, 2005 20:43
PHP Sessions benbacardi PHP Forum 5 Aug 28th, 2005 09:29
Sessions vor ASP.NET Forum 3 Aug 19th, 2003 20:10


All times are GMT. The time now is 15:45.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

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