Page 1 of 1

PHP Session Variables [SOLVED]

Posted: Mon Mar 07, 2011 1:44 pm
by Uncle_Frank
Hello all -

I am working on a login scripts that uses php session variables to transfer the information across as users submit information.

When user enters their user name / pw, a .php file checks the login information vs. a mysql database and checks.

If all good, it sets the variables:

Code: Select all

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
//session_register("User");
session_start();
$_SESSION["User"]=$User;
$_SESSION["User_PW"]=$User_PW;
$_SESSION["Name"]=$Name;
header("location:".$Redirect);
}
When it redirects to the next page, the variables are there, and joy I can see them:

Code: Select all

// At top of the page to determine if session is still good:
//Confirm session is correct
session_start();
if(!session_is_registered(User)){
header("location: /Distributors.html");
}
//Print the company name, saved as User. This works and outputs just fine.
$Company = $_SESSION['User'];
echo $Company;
On this page, a user will fill out new customer data. When they submit the form data on this page, it adds all the information to the mysql database on a backend page that will auto forward to a success page.

Unfortunately at this point, the variables are gone. When I try to print them on the background form submission page (after I've removed the auto forward, for testing) I get nothing. The session ID is still the same, but its as if the variables are gone.

I use session_start() on all pages, so that is all the same.

Any ideas?
Thanks

Re: PHP Session Variables

Posted: Mon Mar 07, 2011 3:43 pm
by Uncle_Frank
Nevermind everyone. After some digging, I found that session variables might be affected by different redirects:

Ie:

location: /test.php
vs.
location: test.php

This is solved.

Thanks