473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Another session problem/question

170 100+
Sorry if this seems obvious to some, but

On the "check" page I have

Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. $_SESSION['subjectshort']=$subjectshort; [previously defined]
  3. $_SESSION['admincheck']='horse';
  4. header( "Location: admin.php" ); 
  5.  
then on admin.php I have on the first line
Expand|Select|Wrap|Line Numbers
  1. <?php session_start(); if(isset($_SESSION['admincheck'])) {  ?>
  2. ...stuff...
  3. <?php } else { redirect to check page} ?>
  4.  
My question:

Why doesn't this work? It won't let me log in, but keeps redirecting back to the check page. What obvious thing am I missing here?

Thanks.
Jun 4 '08 #1
7 1368
Tarantulus
114 100+
do a
Expand|Select|Wrap|Line Numbers
  1. print_r($_SESSION);
on you admin page, just to make sure that it is actually being set correctly, I can't see anything wrong outright.
Jun 4 '08 #2
beary
170 100+
do a
Expand|Select|Wrap|Line Numbers
  1. print_r($_SESSION);
on you admin page, just to make sure that it is actually being set correctly, I can't see anything wrong outright.
Thanks, but the existing code won't let me into the admin page...
Jun 4 '08 #3
Tarantulus
114 100+
Thanks, but the existing code won't let me into the admin page...
are you sure? (given the minimal amount of code you've shown) it looks like your getting bounced from the check page to the admin page and back again...

also, HTTP headers shouldn't really contain relative paths, try the full path in your header command or at least "./admin.php"
Jun 4 '08 #4
beary
170 100+
are you sure? (given the minimal amount of code you've shown) it looks like your getting bounced from the check page to the admin page and back again...
Yeah I'm sure. That's what I said in my initial post: it was getting me to the admin page but then not letting me stay.

Also, I'm not sure what maximal code would be. How much more is needed?

What I can say is the following.

In the check page, if I include
Expand|Select|Wrap|Line Numbers
  1. session_register('$user');
  2.  
and in the admin page if I include
Expand|Select|Wrap|Line Numbers
  1. if(session_is_registered('$user') 
  2.  
it lets me in just fine. But everything I've read says that session_register etc is no longer needed. My php version is 5.2.5.

So I guess this is a "quick fix" but I want to know why it doesn't work the other way...
Jun 4 '08 #5
Markus
6,050 Expert 4TB
Hey, have a look at this, it might help:

[3 Feb 2002 10:32pm UTC] chris at k2labs dot org

This is actually not a bug at all but rather behavior of HTTP.

For PHP to be able to "find" a previously set session variable, it must
be able to identify the client, right? Well, the default method used to
accomplish this is via a cookie set when you initiate the session. Since
it appears you are redirecting the user to the member's only page using
the Location header on the same page the session is initiated, the
PHPSESSID cookie will not be set. Thus, once the user arrives at the
member's only page, PHP won't be able to identify the user. Their
session variable is still there, but PHP won't give it to a stranger.
:)

Basically, in your HTTP reponse that includes the Set-Cookie header, it
needs to be a regular 200 OK response and not a protocol level
redirection. If you absolutely have to have the behavior you're going
for here, you're going to have to use a meta refresh for the
redirection. Yes, it's not as cool, but it's the only way to set a
cookie and redirect the client in the same response. Otherwise, you'll
have to pass the value of the cookie on the URL, which might be a good
option for you actually.

Hope that helps.
The bug
Jun 4 '08 #6
beary
170 100+
Hey, have a look at this, it might help:


The bug
Thanks a lot markusn00b, That definitely explains the problem.

Cheers!
Jun 4 '08 #7
Markus
6,050 Expert 4TB
Thanks a lot markusn00b, That definitely explains the problem.

Cheers!
Welcome, beary!

See you around the forums, dude.
Jun 4 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Xizor | last post by:
Let's say I run a server. I have two people using the server. Bill and Joe. Bill is at address.com/bill and Joe is at address.com/joe. Let's say Joe and Bill are both using PHP with sessions on...
12
by: Patrick | last post by:
I have two ASP pages payment.asp: For customers to fill in payment/card details (pre-populating details if details submitted were invalid and user had to re-fill in details) confirmorder.asp:...
3
by: Martin | last post by:
Hi all As my posting title suggests I'm having problems using InProc Session state in my ASP .NET app. I wrote a site for a friend which uses ADO .NET to keep track of a simple...
5
by: Dan | last post by:
We have a simple site. It's a frameset with two frames a left and a right. The left frame is essentially a list of records from a database (using a server-side repeater control). When you click...
1
by: usl2222 | last post by:
Hi, I'm building this web application using asp.net and c# as code behind. Currently I save all my session data in session variables. One of the things that this application must do, is to...
2
by: Boban Dragojlovic | last post by:
I'm building a complex web-based reservations system. Gathering the user's data requires between 8 and 15 pages (depending on which options they are interested in). I use the "Session" object to...
17
by: Rabbit | last post by:
Hi, On my 1st page, i have a function which gets a new ID value and need to transfer to another immediately. which I want to get in 2nd page using Request.form("txtID"), but doesn't work, the...
4
by: three-eight-hotel | last post by:
I'm somewhat of a newbie to PHP coding, but have developed a site using the technology, and have been pleasantly surprised by the capabilities offered. I am more comfortable in the ASP world,...
13
by: Mortimer | last post by:
Hi, i'm using PHP 5.1 I have two objects and the second one is using an instance of the first. As displayed in the example below, the Garbage Collector calls the destruct method of the first...
10
by: _Who | last post by:
Given Request.Cookies and Response.Cookies in asp.net is there any reason to ever use javascript or any other method to use cookies? Thanks
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.