Forum Moderators: coopster

Message Too Old, No Replies

PHP Login

I have a problem with my php login script

         

bysonary

1:24 pm on Jan 31, 2007 (gmt 0)

10+ Year Member



Hello, I am trying to write a login script, the truth is this login script has been hacked by myself, it did belong to a friend who kindly said i could use it to hack and make my own, so I have done.

The problem I am having is when i click the submit button the script doesnt go to header(location) it just refreshes the login prompt page.

The code is below


<?php
session_start();?
include '/home/www/juttuffi/header.php';
include '/home/www/juttuffi/dbc.php'; // db connector
>

<form action="<?php $SERVER['PHP_SELF'];?>" method="post">
<input type="text" name="user"/><br>
<input type="password" name="pass"/><br>
<input type="submit" value="login"/>
</form?

<?php
if(isset($_POST['username']) && $_POST['password']){
[code]
$username = $_POST['user'];
$password = $_POST['pass'];

$query = "SELECT * tadministrators WHERE uname = '$user' AND pwd = '$pass' ";
$result = mysql_query($query) or die("Unable to verify user because : " . mysql_error());

if(mysql_num_rows($result) == 1)
{
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$_SESSION['usrname'] = $row['uname'];
}

$_SESSION['Authenticated'] = true;
header('Location: http://mydomain.com/control/index.php');
}
else
{
$err = "ERROR: Incorrect Username and/or Password";
}

echo '<span class="notice">';
echo $err;
echo '</span>';
echo '<br>';
echo ($result);
}
?>

Can anyone tell me where this code is going wrong? and why it isnt redirecting to /control/index.php and it is just refeshing the login.php which is the page the above code belongs too.

I would really appreciate it.

omoutop

1:38 pm on Jan 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



with a quick view on your code...

under your includes, there seem to be an error in closing the php tags
also the orm tag is not clossing correctly
(perhaps a copy/paste error?)

If these are indeed errors, then the header() will not work.

Also the header() must be places on top of the page, before any output. Where you have it it will just failed (under the <form>...</form>

[edited by: omoutop at 1:39 pm (utc) on Jan. 31, 2007]

bysonary

1:38 pm on Jan 31, 2007 (gmt 0)

10+ Year Member



UPDATE: sorry my bad lots of misspelled variables in my code etc. dont reply to this