Help - Search - Members - Calendar
Full Version: Logging Ip Adress And Linking Account To Ip
Zymic Webmaster Forums > Zymic Free Web Hosting > Databases & MySQL
NaN101
First of all, I want to give you the following information:

I have a little website, using a php login script. People will only be able to see index.html and the login-page if they do not succesfully login. There is no option to register: I am the only one the can register them (by INSERT INTO database).

What I want to do:

I will create a separate account for every person I want to give access to the hidden content (about 5). But! I want to implement into the php-files that when they login, the database will automatically register the IP they're using at that moment.

As soon as everybody had logged in for the first time, I will save the IP adresses and remove the IP-logging code. All I want to do afterwards is "link" their account to their IP adress, meaning they can login from anywhere, but if they're not at the original IP adress they will see a page: "You were logged in successfully, but you do not have the rights to view the hidden content from this internet connection." And if they log in from the original connection, they must be able to see the hidden content.

If someone could write me some code, or give me a link to a tutorial, I would be very gratefull. smile.gif
swordz
How much php do you know? I'm assuming a bit, as you're writing an IP logger.

Simply add a query "SELECT * FROM `table` WHERE `username`='$username' AND `IP`='$_SERVER['REMOTE_ADDR']'". If it returns something (check with mysql_num_rows), they're allowed to, otherwise they're not.

Make sense?

swordz
salman123
Hello

Every tell me how to update site
Brandon
QUOTE(salman123 @ Dec 12 2008, 04:21 PM) *
Hello

Every tell me how to update site

What?...
NaN101
I haven't written an IP-logging script, actually I know almost nothing about PHP. I only know how to create tables and insert data into them, not how to write scripts to check the data etc. This is the piece of code that checks the user and pass, and sets the SESSION.

CODE
$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){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>


What should I add to make it FIRST check if the password and username match, and THEN make sure the username and the IP-adress match?
NaN101
Never mind, I worked it out myself using some IF statements. Looks like learning a little bit of JavaScript was good for something after all: it works the same in PHP. tongue.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.