473,403 Members | 2,270 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,403 software developers and data experts.

Session variables and header("location:xxx");

I'm designing a small site and I have this structure in mind:

index.php
---------------
login fields. User enters login info. LoginCheck.php is called.

LoginCheck.php
-----------------------
Login info are POST collected and checked in DB. If successful, session variables are set. Then redirected to index.php using header("location:index.php");

In index.php. I'm checking is the session variable is registered. But it looks like the session variable is lost during redirection using header.

Is there any workaround for this?
Mar 15 '08 #1
6 3258
Markus
6,050 Expert 4TB
If we saw your (relevant) code then we might be able to suggest something.
Mar 15 '08 #2
If we saw your (relevant) code then we might be able to suggest something.
[php]
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "LoginOK.php"
session_register("myusername");
session_register("mypassword");
header("location:index.php");
}
else {
echo "Wrong Username or Password";
}[/php]
Mar 15 '08 #3
Markus
6,050 Expert 4TB
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "LoginOK.php"
session_register("myusername");
session_register("mypassword");
header("location:index.php");
}
else {
echo "Wrong Username or Password";
}
Ive never used session_register.
Do you start with session_start() on every page?
Mar 15 '08 #4
ronverdonk
4,258 Expert 4TB
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Mar 15 '08 #5
Ive never used session_register.
Do you start with session_start() on every page?
I have used session_start() only in the login page. I think it is enough to start a session in login page, and not on every page.

You said you have never used session_register. Then how do you work around with session variables? Can you please help me on this?
Mar 15 '08 #6
Markus
6,050 Expert 4TB
I have used session_start() only in the login page. I think it is enough to start a session in login page, and not on every page.

You said you have never used session_register. Then how do you work around with session variables? Can you please help me on this?
You need to use session_start(); on every page!

When i use sessions i do this:
[php]
# login.php
session_start();
# log in script
# if(login == successful)
$_SESSION['logged_in'] = true;
[/php]
[php]
# member.php
session_start(); # MUST BE INCLUDED!
if(isset($_SESSION['logged_in']))
{
# member is logged in
}
else
{
# member isnt logged in
}
[/php]
session_start(); has to be on every page that you are using sessions in.
:)
Mar 15 '08 #7

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

Similar topics

2
by: Eino Mäkitalo | last post by:
It seems that urrlib2 default redirection does not allow me to handle Cookies. Service I'm trying seems to use IP switcher and session id's with cookies. After successful login it changes session...
23
by: lwoods | last post by:
I am trying to pass some info to another page on my site. I set "session_start()" in page 1, assign a session variable to a value, then execute a "header('Location: ....')." But on the target...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.