Jump to content

[SOLVED] Server Side Login Fails


freddyw

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/170755-solved-server-side-login-fails/
Share on other sites

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?

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?

<?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.

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

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

 

:D Harhar Lol, I didn't  understand it intil an hour of reading a tutorial from google.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.