Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.