spires Posted September 2, 2006 Share Posted September 2, 2006 Hi, I've built a login system that once the user has entered in his usname and pword it will take them to the next page.This was all working earlyer today, but has since stop. Which means there must be something wrong with my code. Could someone please have a quick look?[code]<?phpsession_start();if(session_is_registered(username)) {header('Location: add_banner.php');}include('dbconnect.php');?><?php $bodyErrors = array();if (!empty($_POST['submit_butt'])) { if ($_POST['username']=='') $bodyErrors['username'] = 'Add Your Username'; if ($_POST['password']=='') $bodyErrors['password'] = 'Add Your Password'; if (count($bodyErrors) == 0) { $username=$_POST['username']; $password=$_POST['password']; $sql="SELECT * FROM user_info WHERE username='$username' and password='$password'"; $result = mysql_query($sql); $count = mysql_num_rows($result); if ($count == 1) { session_register('username'); session_register('password'); header('Location: add_banner.php'); } else { $noinput = '<div class="white2">Sorry. You have entered an incorrect username or password,<br> please try again'; } } else { if (empty($username) || empty($password)) { $bodylogErrors = '<div class="error">'; foreach ($bodyErrors as $log_error) { $bodylogErrors .= "<li>$log_error</li>"; } $bodylogErrors .= '</div>'; } } }include('functions/wrapper1.php');include('functions/dropdowns.php');include('functions/random_images.php');?>[/code]Now, here is the strange part. The page is being directed to add_banner.php but then comes back because i have a:[code]session_start();if(!session_is_registered(username)) {header('Location: add_a_banner.php');}[/code]This means that the sessions are not registering.Also, if i echo out the username inbetween session_register and the headere.g[code] session_register('username'); session_register('password'); echo $username; header('Location: add_banner.php');[/code]The session DO register, but then the header dont work because something is being printed to screen.Has anyone seen this before?any help please. :D Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/ Share on other sites More sharing options...
wildteen88 Posted September 2, 2006 Share Posted September 2, 2006 Use this:[code]$_SESSION['username'] = $username;$_SESSION['password'] = $password;[/code]Instead of [code]session_register('username');session_register('password');[/code]Also all what session_register does is setup a blank username/password session variable. It doesnt pupulate the session with anything. Also session_register is depreciated. You should use the code provided above to create your session variables.In add_banner.php you should use this:[code=php:0]session_start();if(!isset($_SESSION['username'])) {header('Location: add_a_banner.php');}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84505 Share on other sites More sharing options...
spires Posted September 2, 2006 Author Share Posted September 2, 2006 Cheers mate. You've been a great help. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84506 Share on other sites More sharing options...
spires Posted September 2, 2006 Author Share Posted September 2, 2006 I Cant for the life of me see whats wrong. Has anyone every come across this problem when the sessions will not register. It seems as though the header is kicking in before the session registers?Any more suggestion please. Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84666 Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 post all your code you got now please cheers. Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84669 Share on other sites More sharing options...
spires Posted September 2, 2006 Author Share Posted September 2, 2006 Thanks for lookingHere you gologin page[code]<?phpsession_start();if(isset($_SESSION['username'])) {header('Location: add_banner.php');}include('validation.php');include('dbconnect.php');?><?php $bodyErrors = array();if (!empty($_POST['submit_butt'])) { if ($_POST['username']=='') $bodyErrors['username'] = 'Add Your Username'; if ($_POST['password']=='') $bodyErrors['password'] = 'Add Your Password'; if (count($bodyErrors) == 0) { $username=$_POST['username']; $password=$_POST['password']; $sql="SELECT * FROM user_info WHERE username='$username' and password='$password'"; $result = mysql_query($sql); $count = mysql_num_rows($result); if ($count == 1) { session_register('username'); session_register('password'); header('Location: add_banner.php'); } else { $noinput = '<div class="white2">Sorry. You have entered an incorrect username or password,<br> please try again'; } } else { if (empty($username) || empty($password)) { $bodylogErrors = '<div class="error">'; foreach ($bodyErrors as $log_error) { $bodylogErrors .= "<li>$log_error</li>"; } $bodylogErrors .= '</div>'; } } }include('functions/wrapper1.php');include('functions/dropdowns.php');include('functions/random_images.php');?>[/code]second page [code]<?phpsession_start();if(!isset($_SESSION['username'])) {header('Location: add_a_banner.php');}include('validation.php');include('dbconnect.php');?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84689 Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 i think if you look into the other included files.your see that they have no session_start() in so, I think you should add them and try also i strongly recomend you change all the session register to the way as posted above ok. Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84696 Share on other sites More sharing options...
spires Posted September 2, 2006 Author Share Posted September 2, 2006 Sorry, i thought i had changed it all. silly me. :PSo, you have to have a session_start on every page related?That could very well be the problem. I shall go try it out and let you know how i get on.Cheers mate. Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84707 Share on other sites More sharing options...
spires Posted September 2, 2006 Author Share Posted September 2, 2006 Ok, I've added session_start() to every page that is included.and changed all of the sessions as recommended above.But i still not registering, i can see the address bar change which means the header is working.here is the web addresshttp://www.theeventorganiser.com/add_a_banner.phphere the code for the page the whole php[code]<?phpsession_start();if(isset($_SESSION['username'])) {header('Location: add_banner.php');}include('validation.php');include('dbconnect.php');?><?php $submit_cat = $_POST['cat']; $loginErrors = array();if (!empty($_POST['Submit'])) { if ($_POST['username']=='') $loginErrors['username'] = 'Add Your Username'; if ($_POST['password']=='') $loginErrors['password'] = 'Add Your Password'; if (count($loginErrors) == 0) { $username=$_POST['username']; $password=$_POST['password']; $sql="SELECT * FROM user_info WHERE username='$username' and password='$password'"; $result = mysql_query($sql); $count = mysql_num_rows($result); if ($count == 1) { $_SESSION['username'] = $username; $_SESSION['password'] = $password; header("Location:profile.php"); } else { $noinput = '<div class="white2">Sorry. You have entered an incorrect username or password,<br> please try again'; } } else { if (empty($username) || empty($password)) { $strLogError = '<div class="white2">'; foreach ($loginErrors as $log_error) { $strLogError .= "<li>$log_error</li>"; } $strLogError .= '</div>'; } } } $bodyErrors = array();if (!empty($_POST['submit_butt'])) { if ($_POST['username']=='') $bodyErrors['username'] = 'Add Your Username'; if ($_POST['password']=='') $bodyErrors['password'] = 'Add Your Password'; if (count($bodyErrors) == 0) { $username=$_POST['username']; $password=$_POST['password']; $sql="SELECT * FROM user_info WHERE username='$username' and password='$password'"; $result = mysql_query($sql); $count = mysql_num_rows($result); if ($count == 1) { $_SESSION['username'] = $username; $_SESSION['password'] = $password; header('Location: add_banner.php'); } else { $noinput = '<div class="white2">Sorry. You have entered an incorrect username or password,<br> please try again'; } } else { if (empty($username) || empty($password)) { $bodylogErrors = '<div class="error">'; foreach ($bodyErrors as $log_error) { $bodylogErrors .= "<li>$log_error</li>"; } $bodylogErrors .= '</div>'; } } }include('functions/wrapper1.php');include('functions/dropdowns.php');include('functions/random_images.php');?>[/code]This is the code on the second page[code]<?phpsession_start();if(!isset($_SESSION['username'])) {header('Location: add_a_banner.php');}include('validation.php');include('dbconnect.php');?>[/code]Any more help would be greatly appreceated. Thanks for taking the time to do this. Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84729 Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 very strange all worked then went dead aswell weired.echo out your querys and see if they mach as it suppose to not there is also some pages got no links.when i press your account i get a hello so i think the sessions work.it's the querys i think have a look weiredNice site theo.thinking. Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84733 Share on other sites More sharing options...
spires Posted September 2, 2006 Author Share Posted September 2, 2006 Cheers mate. Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84738 Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 can i have a fake name and password please to see it i get in. Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84745 Share on other sites More sharing options...
spires Posted September 2, 2006 Author Share Posted September 2, 2006 If i echo the $username out after the: $_SESSION['username'] = $username; $_SESSION['password'] = $password;It echos out the user name, Its also registers the session, Which is very strange?But then the header dont work.e,g $_SESSION['username'] = $username;$_SESSION['password'] = $password;echo $username;header('Location: add_banner.php');the 'Your Accout' doesn't have any sessions on the page its goes to yet. Here is a test username and passwordtesttest Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84747 Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 i logged in and i got the hello very weired.mybe you need to use include dont knoe weiredthis is for the users to login as the login page i suspect yes?include("add_banner.php"); Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84750 Share on other sites More sharing options...
wildteen88 Posted September 2, 2006 Share Posted September 2, 2006 [quote author=spires link=topic=106605.msg426703#msg426703 date=1157223368]If i echo the $username out after the: $_SESSION['username'] = $username; $_SESSION['password'] = $password;It echos out the user name, Its also registers the session, Which is very strange?But then the header dont work.e,g $_SESSION['username'] = $username;$_SESSION['password'] = $password;echo $username;header('Location: add_banner.php');the 'Your Accout' doesn't have any sessions on the page its goes to yet. Here is a test username and passwordtesttest[/quote]$username is not your session variable. That variable is the variable you setup ealier to to get the username form the _POST['username'] array. To echo the username session you'll want to use [code=php:0]echo $_SESSION['username'];[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84751 Share on other sites More sharing options...
spires Posted September 2, 2006 Author Share Posted September 2, 2006 the login box to the bottom left donn't have any session check on the next page yet. The login box in the center does, so try in that box and you will see the address baar change, then change back. Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84752 Share on other sites More sharing options...
spires Posted September 2, 2006 Author Share Posted September 2, 2006 the login box to the bottom left donn't have any session check on the next page yet. The login box in the center does, so try in that box and you will see the address baar change, then change back. Ok wildteen88, I'll try it out. Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84753 Share on other sites More sharing options...
spires Posted September 2, 2006 Author Share Posted September 2, 2006 Yeah, it echos out the user name. If you try the test=username and test=password your'll see it echo out at the top left hand corner Quote Link to comment https://forums.phpfreaks.com/topic/19457-session-help-please-early-post-still-unsolved/#findComment-84755 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.