PHP Login problems

Compaq ?
January 7, 2010 at 17:43:39
Specs: Windows 98, ?
I have a .php page, and as far as I can tell, it's good

code, but it keeps displaying the "Incorrect

Username!" error (javascript function uc, php T_ELSE),

even though I am using the correct username! Code:

<?php
printf("<html><head><title>Mindos4.com</title>");
?>
<script type="text/javascript">
function uc() {
<?
$usr="_guest_";
if ($_GET['uname'] == $usr)
{
?>
location.href="javascript:pc()";
<? }
else {
?>
alert("Incorrect Username!");
<? } ?>
}
function pc() {
<?
$pwd="guest";
if ($_GET['pwd'] == $pwd)
{
$url="usr.php?usr=cpanel&uname="+
$_GET['uname'];
?>
var url = <?php echo $url; ?>;
location.href=url;
<?
}
else {
?>
alert("Incorrect Password!");
<?
}
?>}</script><?

printf("</head><body>");
printf("<center><h1>Login</h1>\n");
printf("<form action=\"javascript:uc()\" method=\"get\">");
printf("Username: <input type=text name=\"uname\" />");
printf("Password: <input type=password name=\"pwd\" /><input type=submit
value=\"Login\" /></form>");
printf("</center></body></html>");


?>


See More: PHP Login problems

Report •

#1
January 7, 2010 at 19:13:43
It looks like you've got two issues going on - the first being that your form is being handled by javascript, so it's probable that $_GET is null. The second issue is php executes once as your page loads. When javascript calls its functions, the values within any php variables will remain as they were when the page was first loaded.

Try the code below and then check the source from within your browser, you'll get an idea of what php is doing while it executes.

<?php
   $some_num = 1;
?>
<script type="text/javascript">

var test = <?php echo $some_num; ?>;

function php() {
   alert(<?php echo $some_num++; ?>);
}

function js() {
   alert(test++);
}

</script>

<input value="php" type="button" onclick="php();">
<input value="js" type="button" onclick="js();">


Report •

#2
January 8, 2010 at 19:02:57
thnx. but i came up with another solution. this one stores the password and username in the same file, and I used the while() function, got rid of the javascript, and made it so that creating new accounts was almost instant. but thanks for the suggestion!

Report •
Related Solutions


Ask Question