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
r22pl
Forum Newbie
Posts: 6 Joined: Tue Mar 07, 2006 3:45 pm
Post
by r22pl » Tue Mar 07, 2006 4:08 pm
I have no idea why this isnt working
I have a login system for my website, and I have it so
Code: Select all
if ($_GET['id'] == "login") {
if (isset($_SESSION['adminuser'])) {
echo "You are already logged in!";
} else {
// Check Supplied User/Pass
$login_user = $_POST['login_user'];
$login_pass = $_POST['login_pass'];
if ($login_user == "USERNAME" && $login_pass == "PASSWORD") {
// User Confirmed, register session and redirect
session_register('adminuser');
$_SESSION['adminuser'] = $adminuser;
header('Location: index.php');
} else {
// User Denied
echo "Invalid Login";
}
}
}
(the user/pass is USERNAME:PASSWORD)
the session wont register, when i do
Code: Select all
if (isset($_SESSION['adminuser'])) {
echo "Welcome back!";
}
, no text will appear
r22pl
Forum Newbie
Posts: 6 Joined: Tue Mar 07, 2006 3:45 pm
Post
by r22pl » Tue Mar 07, 2006 4:26 pm
Yeah, I have session_start(); in the beginning of my document. What should I use instead of session_register?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 07, 2006 4:29 pm
as long as you use $_SESSION, nothing else. You may need to call
session_write_close() as using a redirection can short-circuit any session creation.
r22pl
Forum Newbie
Posts: 6 Joined: Tue Mar 07, 2006 3:45 pm
Post
by r22pl » Tue Mar 07, 2006 10:08 pm
Where should I put it?
So I get rid of the session_register('adminuser'); and add the session_write_close();
Code: Select all
// User Confirmed, register session and redirect
$_SESSION['adminuser'] = $adminuser;
session_write_close();
header('Location: index.php');
because that didn't work
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Tue Mar 07, 2006 10:50 pm
You can just set the session var by creating one...
Code: Select all
<?php
session_start();
$_SESSION['my_session_var'] = 'This is my value';
echo $_SESSION['my_session_var'] . '<br />';
if ( changed_my_mind() ) {
// Pretend function to show the point...
$_SESSION['my_session_var'] = 'This is my new session value';
}
echo $_SESSION['my_sesison_var'];
?>
r22pl
Forum Newbie
Posts: 6 Joined: Tue Mar 07, 2006 3:45 pm
Post
by r22pl » Wed Mar 08, 2006 6:18 am
Thanks, it fixed the problem