PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2002, 09:24 AM
tigercat's Avatar
tigercat tigercat is offline
member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Germany
Posts: 89 tigercat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 39 sec
Reputation Power: 7
Unhappy simple session example

hi there,
on http://www.php.net/manual/en/printwn/ref.session.php i found a simple example to see how session variables work.
i modified it a little bit to show the result. see below.
PHP Code:
 session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($HTTP_SESSION_VARS['count'])) {
    
$HTTP_SESSION_VARS['count'] = 0;
} else {
    
$HTTP_SESSION_VARS['count']++;
}
echo 
'<a href="'.$PHP_SELF.'">click here</a><br>';
// show session-variable - one possibility
echo $HTTP_SESSION_VARS['count']."<br>";
// show session-variable - another possibility
echo "<PRE>";
print_r($HTTP_SESSION_VARS);
echo 
"</PRE>"

my problem is: the counter always shows "0".
as i read across several forum-entries and the php-manual it is not nessecary to use session_register or something else to make this example work cause i'm using php 4.0.6.
any ideas are welcome
thanx,
tigercat

Reply With Quote
  #2  
Old November 6th, 2002, 10:09 AM
SilkySmooth's Avatar
SilkySmooth SilkySmooth is offline
Newbie :P
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2001
Location: In the PHP Engine :-)
Posts: 2,880 SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 11 h 32 m 23 sec
Reputation Power: 15
Hi,

You have misread the information, quote from the manual:

Quote:
Use of $_SESSION (or $HTTP_SESSION_VARS with PHP 4.0.6 or less) is recommended for improved security and code readablity. With $_SESSION, there is no need to use the session_register(), session_unregister(), session_is_registered() functions. Session variables are accessible like any other variables.


So if you are using PHP 4.0.6 or less you need to replace the $_SESSION with $HTTP_SESSION_VARS but you still need to use the session_register function. The only time you dont use the session_register function is if you are using $_SESSION.

HTH
__________________
---------------------
-- SilkySmooth --
---------------------
Proxy | Little Directory

Reply With Quote
  #3  
Old November 6th, 2002, 10:26 AM
tigercat's Avatar
tigercat tigercat is offline
member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Germany
Posts: 89 tigercat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 39 sec
Reputation Power: 7
hi there again

thanx for your reply.
i still think there was some truth im my qustion - refering to http://www.php.net/manual/en/printw...on-register.php
Quote:
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register()

but i think that's not the main topic. i rather think there must be something to add in the example and i don't know what it is. all the post in this forum dealing with "sessions" show it a similar way but i'm not lucky with any of them.

additional: running linux, apache 1.3.19

greetings
tigercat

Reply With Quote
  #4  
Old November 6th, 2002, 10:35 AM
SilkySmooth's Avatar
SilkySmooth SilkySmooth is offline
Newbie :P
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2001
Location: In the PHP Engine :-)
Posts: 2,880 SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 11 h 32 m 23 sec
Reputation Power: 15
Read this comment posted in the user comments section of that page and you will uinderstand more clearly what I mean

--------------------------------------------------------------------------------
ddan6709@yahoo.com
28-Aug-2002 04:44

I'm writing my first PHP application and I?ve tested the saving of the session variables (I use PHP 4.0.6 on SuSE Linux). I've noticed the following:

1.
If register_globals is ON, the variables cannot be seen in another page if you don't issue a session_register() after you set the variables. For example the following code:

<?php
session_start ();
$HTTP_SESSION_VARS[ 'testvar'] = "variable transmission test";
$testvar = 'modified';

echo "<a href= \"./secpage.php\">Link</a>";
?>

won't display anything in a second page generated by the code:

<?php
session_start ();
echo "Second Page!";
echo "
</br> ";
if (isset($HTTP_SESSION_VARS[ 'testvar']))
{
echo "HTTP_SESSION_VARS: " . $HTTP_SESSION_VARS[ 'testvar'];
};
echo "
</br> ";
if (isset($testvar))
{
echo "testvar: ". $testvar;
};
?>

After I've added the session_register('testvar') line after setting the variables, the following is displayed in the second page:

HTTP_SESSION_VARS: modified
testvar: modified

These is strange because the manual specify not to use session_register if we use $HTTP_SESSION_VARS.

2.
If register_globals is off, you don't need to use session_register('testvar') but in the second page displays:

HTTP_SESSION_VARS: variable transmission test

The conclusion is that if you want your code to work with register_globals set either to On or OFF you must use session_register(). You must also use only $HTTP_SESSION_VARS to set the variable.

Reply With Quote
  #5  
Old November 7th, 2002, 04:44 AM
tigercat's Avatar
tigercat tigercat is offline
member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Germany
Posts: 89 tigercat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 39 sec
Reputation Power: 7
Thumbs up

hi there SilkySmooth

you were right. with your post i could solve my problem. thanks very much.

tigercat

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > simple session example


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT