/    Sign up×
Community /Pin to ProfileBookmark

login script not working locally

Can anyone see a reason why this code would continually return “Wrong Username or Password”? I am using it locally on a windows XP pc using xampp for my php and mysql. The code was taken, unchanged, from my webserver where it actually functions as it should. Could this be because it’s on an XP machine? I also exported the database from my actual server and it looks fin in phpmyadmin. The script which calls this is below also incase that helps.

checklogin.php

[code=php]<?php
include(“misc.inc”);
$tbl_name = ‘members’;

// Connect to server and select databse.
mysql_connect(“$host”, “$user”, “$password”)or die(“cannot connect”);
mysql_select_db(“$database”)or die(“cannot select DB”);

$mypassword = sha1($mypassword);
$myusername = addslashes($myusername);

$sql = “SELECT * FROM $tbl_name WHERE `username` = ‘$myusername’ and `password` = ‘$mypassword'”;
$result = mysql_query($sql);

// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
$_SESSION[‘myusername’] = stripslashes($_POST[‘myusername’]);
$_SESSION[‘mypassword’] = $_POST[‘mypassword’];
if(isset($_POST[‘remember’])){
setcookie(“cookname”, $_SESSION[‘myusername’], time()+60*60*24*100, “/”);
setcookie(“cookpass”, $_SESSION[‘mypassword’], time()+60*60*24*100, “/”);
}

// Register $myusername and redirect to file “login_success.php”

session_register(“myusername”);
header(“location:index.php”);
} else {
echo “Wrong Username or Password”;
}
?>[/code]

login.php

[code=php]<?php

session_start();

echo “<p class=’login’>n”;

$myusername = stripslashes($myusername);
if (!session_is_registered(“myusername”)) {
echo “<table>n
<form action=’checklogin.php’ method=’post’ name=’authentication’>n
<tr>n
<td><span class=’inputlabel’>Username:</span></td><td><input class=’input’ type=’text’ size=’25’ name=’myusername’ /></td>n
</tr>n
<tr>n
<td><span class=’inputlabel’>Password:</span></td><td><input class=’input’ type=’password’ size=’25’ name=’mypassword’ /></td>n
</tr>n
<tr>n
<td><span class=’inputlabel’>Remember me?:</span></td><td><input type=’checkbox’ name=’remember’>(requires cookies)</td>n
</tr>n
<tr>n
<td>&nbsp;</td><td><input class=’input’ type=’submit’ name=’submit’ value=’Log in’ /></td>n
</tr>n
</form>n
</table><br >n
<a href=’register.php’>Register</a>”;
} else {
$myusername = stripslashes($myusername);
echo “Welcome $myusername</p>n
<p style=’text-align:right; margin-right: 30px’>n
<a href=’userdetails.php’>My Details |</a>n
<a href=’logout.php’>Log out |</a>n”;
} ?>
<a href=’userlist.php’>Userlist |</a>
</p>[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 23.2006 — Since I do not see where you are setting the username and password variables, my guess is that you have register_globals on your remote host (not really a good thing) and not on your local host. If you explicitly reference them via the $_POST array, then it will not matter which configuration is being used (and thus will be more portable).
Copy linkTweet thisAlerts:
@DoppleauthorApr 24.2006 — I see. Thanks. I suppose when your working with your own PHP server, that's when you start to run into these kind of things which improve your knowlege of the language. I'm going to look up a guide on setting up your server for maximum efficiency. Can you recommend any or is it really something that is personal preference?
Copy linkTweet thisAlerts:
@DoppleauthorApr 24.2006 — I see. Thanks. I suppose when your working with your own PHP server, that's when you start to run into these kind of things which improve your knowlege of the language. I'm going to look up a guide on setting up your server for maximum efficiency. Can you recommend any or is it really something that is personal preference?
×

Success!

Help @Dopple spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...