PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mikebr
Forum Contributor
Posts: 243 Joined: Sat Sep 28, 2002 7:05 am
Post
by mikebr » Fri Mar 07, 2003 1:20 pm
I have built a MySQL db on my laptop which seems to run without any problems but on loading it to myn server I find that the session is not getting set. IE5 and cookies are set for "Accept all" but the session does not get listed in the cookie list in the browser settings so the user gets redirected to my login page again as he should if the variables are empty on being checked. My server is using the same PHP version I have on my laptop "PHP4.2.3". Has anyone any idea what thyis problem can be? I have tried looking this up on the PHP manual but I seem to be working under it's guidlines.
The very simple code I am using to set the session is:
Code: Select all
<?php
$c_password = $_POST['c_password'];
$c_login = $_POST['c_login'];
$browse_time = +3600;
$ufs = "mix";
session_start();
header ("Cache-control: private");
$salt = substr($ufs, 0, 3);
$crypted_password = crypt($c_password, $salt);
include "inc_defaults.php"; // Default variables
session_register('crypted_password');
$_SESSION['crypted_password'] = $crypted_password;
session_register('c_login');
$_SESSION['c_login'] = $c_login;
session_register('expire');
$_SESSION['expire'] = time() + $browse_time; // Browse time is a default variable
header("Location: ../membersarea.php");
exit;
?>
daven
Forum Contributor
Posts: 332 Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:
Post
by daven » Fri Mar 07, 2003 1:25 pm
put session_start() at the top of your page.
When using superglobals ($_SESSION[]), you do not need to use session_register()
mikebr
Forum Contributor
Posts: 243 Joined: Sat Sep 28, 2002 7:05 am
Post
by mikebr » Fri Mar 07, 2003 1:53 pm
Thanks for the help, but changing the code to the following still doesn't set the session?
Code: Select all
<?php
session_start();
$c_password = $_POST['c_password'];
$c_login = $_POST['c_login'];
$browse_time = +3600;
$ufs = "mix";
header ("Cache-control: private");
$salt = substr($ufs, 0, 3);
$crypted_password = crypt($c_password, $salt);
$_SESSION['crypted_password'] = $crypted_password;
$_SESSION['c_login'] = $c_login;
$_SESSION['expire'] = time() + $browse_time; // Browse time is a default variable
header("Location: ../membersarea.php");
exit;
?>
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Fri Mar 07, 2003 11:34 pm
I'm assuming that what you mean is that when you redirect to 'membersarea.php' you can't get the $_SESSION variables right?
Make sure that you have session_start() at the top of every page that needs to use the session information
phice
Moderator
Posts: 1416 Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:
Post
by phice » Sat Mar 08, 2003 12:34 am
Exactly what protokol said.
Use session_start(); on the very first line (after the <?, of course) of your php document that you wish to use session variables.
echo $_SESSION["variable_name"]; when you choose to print out the value of the session variable.
mikebr
Forum Contributor
Posts: 243 Joined: Sat Sep 28, 2002 7:05 am
Post
by mikebr » Sat Mar 08, 2003 2:49 am
Sorry guys, I checked on another 2 computers and the session is getting set on them, the problem seems to be on the computer I have been working on. Weird, the session does not get set in any browser on my desktop machine but on my PC and laptop it does??????
Thanks for the help, I guess I need to trash my internet prefeences on my computer and try again.
phice
Moderator
Posts: 1416 Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:
Post
by phice » Sat Mar 08, 2003 2:12 pm
Tools > Internet Options > [TAB] Advanced > [BUTTON] Restore Defaults
evilcoder
Forum Contributor
Posts: 345 Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia
Post
by evilcoder » Sat Mar 08, 2003 6:45 pm
ermmm sessions are serverside matey. Your browsers cant reject them.
phice
Moderator
Posts: 1416 Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:
Post
by phice » Sat Mar 08, 2003 7:01 pm
Well it wouldn't hurt to reset his IE settings.
evilcoder
Forum Contributor
Posts: 345 Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia
Post
by evilcoder » Sat Mar 08, 2003 7:16 pm
lol true... i was just telling it how it is.
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Sat Mar 08, 2003 7:17 pm
evilcoder wrote: ermmm sessions are serverside matey. Your browsers cant reject them.
Not really, the browser needs to set a cookie to determine the session ID.
If the cookie isn't set (and the SID is not appended to the URL), the server won't know what session to use.
So, check if the browser has cookies enabled, (which the IE reset might fix).
evilcoder
Forum Contributor
Posts: 345 Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia
Post
by evilcoder » Sat Mar 08, 2003 7:27 pm
i have cookies disabled on my PC, and session always work perfectly.
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Sat Mar 08, 2003 7:30 pm
session_start() creates a session or resumes the current one based on the current session id that's being passed via a request, such as GET, POST, or a cookie.
the browser has to tell the server the id.
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Sat Mar 08, 2003 11:02 pm
evilcoder wrote: i have cookies disabled on my PC, and session always work perfectly.
So the way that you would be able to have sessions work then is if the session_id() is passed to the URL or through hidden form inputs.
evilcoder
Forum Contributor
Posts: 345 Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia
Post
by evilcoder » Sat Mar 08, 2003 11:17 pm
dunno, but i go to alot of sites using sessions and i never have a probably and the session id is never parsed through the url.