Page 1 of 1
Coding Login script
Posted: Wed Feb 18, 2009 9:56 am
by overdrv69
I need help figuring out why this is not working.
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
header("location: access-denied.php");
exit();
}
?>
everytime I check the login it goes to the access-denied.php. Not sure why the session is not being passed I coded that in my login-exec.php script.
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
session_write_close();
header("location: member-index.php");
exit();
I'm calling the auth.php script an the begining of "member-index.php"
Please advise.
Thanks
Re: Coding Login script
Posted: Wed Feb 18, 2009 10:03 am
by papa
Do you have a session_start() on member-index.php ?
Re: Coding Login script
Posted: Wed Feb 18, 2009 10:18 am
by overdrv69
Yes,
Here is the code.
<?php
require_once('auth.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Member Index</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Welcome <?php echo $_SESSION['SESS_FIRST_NAME'];?></h1>
<a href="member-profile.php">My Profile</a> | <a href="logout.php">Logout</a>
<p>This is a password protected area only accessible to members. </p>
</body>
</html>
auth.php is opening the session. Are you suggesting that I should open the another session on the member-index.php?
Re: Coding Login script
Posted: Wed Feb 18, 2009 10:26 am
by papa
You must have that function at the start of every document.
Try add:
Code: Select all
<?php
session_start();
require_once('auth.php');
?>
Re: Coding Login script
Posted: Wed Feb 18, 2009 10:39 am
by overdrv69
I did as you mentioned. Still the same. Here is my auth.php code.
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
header("location: access-denied.php");
exit();
}
?>
I can't figure it out.
Re: Coding Login script
Posted: Wed Feb 18, 2009 11:13 am
by papa
Start by simple error debugging. In login-exec.php for example:
Is $result set ?
Try echoing out all the variables, $member['firstname']; and $_SESSION['SESS_FIRST_NAME']..
Break down the code and go step by step.
Re: Coding Login script
Posted: Wed Feb 18, 2009 11:19 am
by overdrv69
Ok, will try to firure out thanks.
Re: Coding Login script
Posted: Wed Feb 18, 2009 11:37 am
by jason.carter
one thing is clear.
If header("location: access-denied.php"); is called then obviously the if loop is entered.
I suggest you replace the header above with echo $_SESSION['SESS_MEMBER_ID'] and you will see it is blank.
Can you also confirm you dont have cookies OFF on your browser?
Re: Coding Login script
Posted: Wed Feb 18, 2009 12:18 pm
by overdrv69
Not sure what to do.
Re: Coding Login script
Posted: Wed Feb 18, 2009 12:39 pm
by overdrv69
You were right it is blank. Does that mean I cause a "if" loop?
Re: Coding Login script
Posted: Wed Feb 18, 2009 1:02 pm
by Benjamin
Please use the appropriate
Code: Select all
[ /code] tags when posting code blocks in the forums. Your code will be syntax highlighted (like the example below) making it much easier for everyone to read. You will most likely receive more answers too!
Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces. You can even start right now by editing your existing post!
If you are new to the forums, please be sure to read:
[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]
If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online. You'll find code samples, detailed documentation, comments and more.
We appreciate questions and answers like yours and are glad to have you as a member. Thank you for contributing to phpDN!
Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]