General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old March 6th, 2003, 01:07 AM
hector hector is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 3 hector User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
session id problem

Everytime I execute a session_start() command, a new session ID is generated. is this normal with PHP on Windows?

i need to have the same session ID to be able to track my variables right? - when I go from one page to another (say from a login page to a login confirmation page) I get different session IDs.

the following is my setup:
- Windows XP
- PHP 4.3.1 for Windows
- MySQL 3.23.55-nt

Reply With Quote
  #2  
Old March 6th, 2003, 02:26 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Append your links with the session id
PHP Code:
 $sess session_name() . '=' session_id();
$link '<a href="page.php?' $sess ">link</a>'; 

Or, you can use the constant SID
PHP Code:
 $link '<a href="page.php?' SID ">link</a>'; 

Or, if you are really really lazy - have PHP do it for you
PHP Code:
 ini_set'session.use_trans_sid', ( int )); 


Now, lets get to your problem. Your php ini file is set to have session.use_trans_sid = 0, or false - which means by default it will not attempt to re-write your urls. On the same note, session.use_cookies is set to 1 or true, meaning to track the user by means of setting a cookie. If php can't set a cookie on the clients machine, you need to carry the session info in the link(s) for php to know that there is an active session going on.

Personally - I set 'session.use_trans_sid' to 0 or false in all of my applications as I prefer to write my own links. But, you can get a quick fix by enabling it as above.

One other thing to note - make sure you have the ini_set() at the top of your script before starting the session...
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #3  
Old March 6th, 2003, 03:18 AM
hector hector is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 3 hector User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Joe,

If I attach the session id to the links, does this mean I don't have to use the session_start() command if I go to another page?

from what i understood in the PHP manual, i have to place a session_start() command in every page that needs to track the sessions. is my understanding correct? or do i just need to execute this command at the very start of the session?

thanks,
hec

Reply With Quote
  #4  
Old March 6th, 2003, 03:29 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Yes - you must still and always use session_start() at the top of your pages....

Reply With Quote
  #5  
Old March 6th, 2003, 03:46 AM
hector hector is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 3 hector User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok - my other problem is in accessing the session variables i set in the previous pages.

correct me if i am wrong:
if I need to set a session variable I use session_register() and then set the value of the variable like this:
PHP Code:
 session_register("myvar");
     
$myvar "value"


and then in the following page I can access the variable by using $_SESSION['myvar'].

my problem is I seem to be able to set the values for the variable but I could not access them anymore in the next pages - I get a "PHP Notice: Undefined index:myvar" error.

Reply With Quote
  #6  
Old March 6th, 2003, 05:05 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Ok - this is why it is essential to post your code on when looking for help.

session_register(), session_is_register(), session_unregister()

Get rid of those functions - never refer to them, act like they are invisible as they will actually be invisible by ver 5 anyways. But until then, just ignore those functions.

Now, to register a session variable, you would register it as so ->
PHP Code:
 $_SESSION['var_name'] = 'the value of the session variable'

To unregister the session variable ->
PHP Code:
unset( $_SESSION['var_name'] ); 

To check to see if it is registered ->
PHP Code:
if ( ( isset( $_SESSION['var_name'] ) ) && ( $_SESSION['var_name'] ) ) echo 'is set and has a value other than false or null'


Remeber, do all of this after you have started the session....


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > session id problem


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 | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway