Jump to content

[SOLVED] re login script not working


blui

Recommended Posts

Hi all, I have a php login script that used to work fine but now it appears to not working correctly - I am assuming its down to the register_globals being now off.

Can some please tell me what i need to do to get ths script working again please?

 

<?

session_start();

ob_start();

session_register(logged);

$_SESSION['logged'] = 0;

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<?

$redirect = $_GET['redirect'];

if (isset($_POST['submit']))

{

if ($_POST['username'] == "Paul" && $_POST['password'] == "daleragu")// replace this logic with authorization from mysql if needed

{//if it gets to this point, the authorization is correct, the we can redirect with the header 3 lines down

$redirect = $_POST['redirect'];

$_SESSION['logged'] = 1;

header ("Location: $redirect");

}

else

{

?>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

<table width="502" border="0" align="center" cellpadding="5" cellspacing="0" class="h3">

Invalid Username and/or Password<br><br>

    <form action="adminloginstart.php" method="post">

    <input type="hidden" name="redirect" value="<? echo $redirect; ?>">

    Username: <input type="text" name="username"><br>

    Password: <input type="password" name="password"><br><br>

    <input type="submit" name="submit" value="Login">

    </form>

            </table>

<?

}

}

else

{

?>

<table width="502" border="0" align="center" cellpadding="5" cellspacing="0" class="h3">

Invalid Username and/or Password<br><br>

    <form action="adminloginstart.php" method="post">

    <input type="hidden" name="redirect" value="<? echo $redirect; ?>">

    Username: <input type="text" name="username"><br>

    Password: <input type="password" name="password"><br><br>

    <input type="submit" name="submit" value="Login">

    </form>

            </table>

<?

}

?>

       

</body>

</html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/44537-solved-re-login-script-not-working/
Share on other sites

<?
session_start();
ob_start();
session_register(logged);
$_SESSION['logged'] = 0;
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<?
$redirect = $_GET['redirect'];
if (isset($_POST['submit']))
{
   if ($_POST['username'] == "Paul" && $_POST['password'] == "daleragu")// replace this logic with authorization from mysql if needed
   {//if it gets to this point, the authorization is correct, the we can redirect with the header 3 lines down
   $redirect = $_POST['redirect'];
   $_SESSION['logged'] = 1;
   header ("Location: $redirect");
   }
   else
   {
   ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<table width="502" border="0" align="center" cellpadding="5" cellspacing="0" class="h3">
Invalid Username and/or Password


     <form action="adminloginstart.php" method="post">
     <input type="hidden" name="redirect" value="<? echo $redirect; ?>">
     Username: <input type="text" name="username">

     Password: <input type="password" name="password">


     <input type="submit" name="submit" value="Login">
     </form>
             </table>
    <?
   }
}
else
{
?>
<table width="502" border="0" align="center" cellpadding="5" cellspacing="0" class="h3">
Invalid Username and/or Password


     <form action="adminloginstart.php" method="post">
     <input type="hidden" name="redirect" value="<? echo $redirect; ?>">
     Username: <input type="text" name="username">

     Password: <input type="password" name="password">


     <input type="submit" name="submit" value="Login">
     </form>
             </table>
<?
}
?> 

 

done it for you.

Thanks JayLewis, I tried your code and still recieved the following error messages any idea why?

 

 

Notice: Use of undefined constant logged - assumed 'logged' in f:\program files\easyphp1-7\www\php\adminloginstart.php on line 4

 

Notice: Undefined index: redirect in f:\program files\easyphp1-7\www\php\adminloginstart.php on line 9

<?php
session_start();
ob_start();
session_register('logged'); // add single quotes to avoid the constant stuff.
$_SESSION['logged'] = 0;
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<?
$redirect = isset($_POST['redirect'])?$_POST['redirect']:null; // added a check here to avoid the index error. also changed to POST.
if (isset($_POST['submit']))
{
   if ($_POST['username'] == "Paul" && $_POST['password'] == "daleragu")// replace this logic with authorization from mysql if needed
   {//if it gets to this point, the authorization is correct, the we can redirect with the header 3 lines down
   $redirect = $_POST['redirect'];
   $_SESSION['logged'] = 1;
   header ("Location: $redirect");
   }
   else
   {
   ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<table width="502" border="0" align="center" cellpadding="5" cellspacing="0" class="h3">
Invalid Username and/or Password


     <form action="adminloginstart.php" method="post">
     <input type="hidden" name="redirect" value="<? echo $redirect; ?>">
     Username: <input type="text" name="username">

     Password: <input type="password" name="password">


     <input type="submit" name="submit" value="Login">
     </form>
             </table>
    <?
   }
}
else
{
?>
<table width="502" border="0" align="center" cellpadding="5" cellspacing="0" class="h3">
Invalid Username and/or Password


     <form action="adminloginstart.php" method="post">
     <input type="hidden" name="redirect" value="<? echo $redirect; ?>">
     Username: <input type="text" name="username">

     Password: <input type="password" name="password">


     <input type="submit" name="submit" value="Login">
     </form>
             </table>
<?
}
?> 

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.