freddyw Posted August 18, 2009 Share Posted August 18, 2009 So I have a simple log in to get to the admin options of a website heres the code HTML <html> <body> <form action="adminslog.php" method="post"><br> <input type ="password" name="password"> <input type ="submit" value ="Log in"> </form> </body> <html> PHP <? ini_set("display_errors", "1"); error_reporting(E_ALL); $strCurrentPassword = "AADDMIINN"; $strPassswordEntered = $_POST ['password']; if ($strPassswordEntered == $strCurrentPassword) { echo "Redirecting to Admin Control"; header('Refresh: 0; URL=http://www.mysite/admins.html'); exit; } ?> first of all apologies to the people with short tags, I've changed it to <?php it still does the same. After any password is entered, right or wrong it leaves the page blank instead of bringing up the page it should any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/170755-solved-server-side-login-fails/ Share on other sites More sharing options...
.josh Posted August 18, 2009 Share Posted August 18, 2009 you are echoing something before your header call. You cannot have any output before headers are sent. Quote Link to comment https://forums.phpfreaks.com/topic/170755-solved-server-side-login-fails/#findComment-900536 Share on other sites More sharing options...
freddyw Posted August 18, 2009 Author Share Posted August 18, 2009 The page is now like this <? ini_set("display_errors", "1"); error_reporting(E_ALL); $strCurrentPassword = "AADDMIINN"; $strPassswordEntered = $_POST ['password']; if ($strPassswordEntered == $strCurrentPassword) { header('Refresh: 0; URL=http://www.mysite/admins.html'); echo "Redirecting to Admin Control"; exit; } ?> still nothing, am i being stupid and missing something obvious? Quote Link to comment https://forums.phpfreaks.com/topic/170755-solved-server-side-login-fails/#findComment-900544 Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Share Posted August 18, 2009 Fixed. Use Location instead of refresh. <? ini_set("display_errors", "1"); error_reporting(E_ALL); $strCurrentPassword = "AADDMIINN"; $strPassswordEntered = $_POST ['password']; if ($strPassswordEntered == $strCurrentPassword) { echo "Redirecting to Admin Control"; header("Location: http://www.mysite/admins.html"); exit; } ?> Also, Arn't you best off using .htaccess for this? Quote Link to comment https://forums.phpfreaks.com/topic/170755-solved-server-side-login-fails/#findComment-900548 Share on other sites More sharing options...
.josh Posted August 18, 2009 Share Posted August 18, 2009 <?php $strCurrentPassword = "AADDMIINN"; $strPassswordEntered = $_POST['password']; if ($strPassswordEntered == $strCurrentPassword) { header('Location: http://www.mysite/admins.html'); exit; } ?> and make sure you don't have any whitespace before your opening php tag. Quote Link to comment https://forums.phpfreaks.com/topic/170755-solved-server-side-login-fails/#findComment-900549 Share on other sites More sharing options...
.josh Posted August 18, 2009 Share Posted August 18, 2009 well considering you aren't setting a session variable and checking for it on logged in pages, .htaccess would be better, yes. Quote Link to comment https://forums.phpfreaks.com/topic/170755-solved-server-side-login-fails/#findComment-900550 Share on other sites More sharing options...
freddyw Posted August 18, 2009 Author Share Posted August 18, 2009 Thanks to Both you guys. I read Gergy's first and that got it working. I noticed crayon took out the echo, which makes sense as its an instant redirect. I fairly new to PHP and no *very little* about htaccess, but will look into it *= nothing Thanks. Appreciate the help Quote Link to comment https://forums.phpfreaks.com/topic/170755-solved-server-side-login-fails/#findComment-900559 Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Share Posted August 18, 2009 Thanks to Both you guys. I read Gergy's first and that got it working. I noticed crayon took out the echo, which makes sense as its an instant redirect. I fairly new to PHP and no *very little* about htaccess, but will look into it *= nothing Thanks. Appreciate the help Harhar Lol, I didn't understand it intil an hour of reading a tutorial from google. Quote Link to comment https://forums.phpfreaks.com/topic/170755-solved-server-side-login-fails/#findComment-900564 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.