Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 4th, 2004, 09:48 AM
Authorized User
 
Join Date: Dec 2003
Location: East Flat Rock, NC, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sessions - one user has problems

I have a site with a log-in procedure which works fine for all people but one. When she logs in, she is taken to the “welcome” page which recognizes her by name. However, subsequent pages do not recognize that she is logged in (tracked by session variable “valid”), and send her back to the log-in page.

I can log on as her from another machine and everything works fine, as it does for all other users. (She is using Windows Milleneum Edition with Internext Explorer 5.50.)

Here are snippets from the pages. On the first page, when logging on with a valid log-in, session variable “valid” is set to “true” and the next page is correctly shown. On that next page, if session variable “valid” is “true” then perform action “A”. Otherwise, perform action “B”, requesting log-in.

Thanks for any help you can give me!

                    - Steve


First page – logging in:

<?php
session_start();
...
$_SESSION['valid']=true;
...
?>


Second page – requesting information:

<?php
session_start();
if (!isset($_SESSION['valid'])) $_SESSION['valid']=false;
...
if ($_SESSION['valid']) {
  ... (perform action A – have logged in)
}
else {
  ... (perform action B – request log-in)
}
?>
 
Old June 4th, 2004, 01:51 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Does she have cookies disabled or something?

Snib

<><
 
Old June 4th, 2004, 05:35 PM
Authorized User
 
Join Date: Dec 2003
Location: East Flat Rock, NC, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I designed the pages to use neither cookies nor javascript, to try to avoid client-side problems. However, I will see if she has disabled cookies, although she seems the type to have no idea how to do so...

(My understanding was that the session variables were kept on the server, and wouldn't use cookies. But this is a beginner's php forum, and I know I could be very wrong!)
 
Old June 4th, 2004, 06:18 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I believe (help me here Rich or Nik :-)) that sessions use cookies when the PHP.ini file tells them to:

session.use_cookies=1

So you would probably need to modify it to say:

session.use_cookies=0

Or if you use a remote host ask them to, but they might not allow it.

To disable/enable cookies in IE:

Open IE, on the toolbar at the top go to Tools -> Internet Options -> Privacy (tab) -> move the slider so it accepts at least some cookies.

Hope you get this problem solved!

Snib

<><
 
Old June 4th, 2004, 07:23 PM
Authorized User
 
Join Date: Dec 2003
Location: East Flat Rock, NC, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is a remote host, and it is set to "1".

Thanks for the info - I'll get her to change her settings. (And I may let my php instructor know about it, too!)

- Steve
 
Old June 8th, 2004, 06:27 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Right, sessions use cookies to pass around the session_id by default and modern browsers have cookies disabled by default. It's better to just hard code in the session_id.

First page – logging in:

Code:
<?php
session_start();
...
$_SESSION['valid']=true;

echo "<a href='second_page.php?sid=".session_id()."'>Go to second page.</a>\n";

// or if using POST

echo "<input type='hidden' name='sid' value='".session_id()."' />\n";

...
?>
Now PHP will pick up on the session id if a script includes a call to session_start.



Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old June 8th, 2004, 06:35 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hmm.... doesn't PHP usually do this anyway (somehow)? It does to my links.

Snib

<><
 
Old June 8th, 2004, 07:43 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:
 Hmm.... doesn't PHP usually do this anyway (somehow)? It does to my links.
No, not by default anyway.

If the session.use_trans_sid directive is set to "1" and the proper tags are specified in the url_rewriter.tags directive PHP will include the session id in all urls. I usually just handle that myself by hard coding the sid.

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::




Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 16 - Problems with sessions. kb90 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 3 April 11th, 2008 09:07 AM
Problems with sessions in php 4.3.11 ocabrera70 Beginning PHP 1 January 31st, 2008 04:28 AM
Problems with Sessions HelpWanted ASP.NET 1.0 and 1.1 Basics 2 December 7th, 2006 04:56 PM
sessions problems: change on refresh ! papango Beginning PHP 4 July 28th, 2004 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.