Jump to content

Recommended Posts

Hi, im new here and also somewhat new to php, though i do know java and a little c++

anyways im trying to make a user check all it does it check if the given user, pass, and ip are correct

 

I can only get it to work with just using user, pass but when i try to and ip and always comes up as false

heres what I have

<?php
$host="localhost"; // Host name
$username="****"; // Mysql username
$password="*****"; // Mysql password
$db_name="*****"; // Database name
$tbl_name="user"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("null");
mysql_select_db("$db_name")or die("null");

// username and password sent from form
$myusername=$_GET['u'];
$mypassword=$_GET['p'];
$myip=$_GET['i'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$mypassword = stripslashes($myip);
$myusername = mysql_real_escape_string($myip);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and password='$myip'";
$result=mysql_query($sql);
$num_rows = mysql_num_rows($result);

if($num_rows > 0) {
echo 'true';
} else {
echo 'false';
}
?>

I call it with something like

http://website.com/check.php?u=bob&p=123&i=111.111.1.11

 

does anyone know why it always comes up as false

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/138348-solved-help-needed-with-user-check/
Share on other sites

Your setting $myusername to $myip and same with $mypassword, look:

 

$mypassword = stripslashes($myip);
$myusername = mysql_real_escape_string($myip);

 

Then in your query your checking if password is equal to myip.

 

password='$myip'";

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.