Jump to content

PHP IP Display


cry of war

Recommended Posts

Hi i am working on a website that has User and it allows you to pick users on which you can sign into. So in other words a user from a company signs in anyone on that IP address can sign in. Security is not any issuse I just want the user to log in so I can see who is visiting.

 

I have it all planned out but i doesnt want to work for some reason I can do the SQL in phpmyadmin and it finds the source but when i try to do it with php nothing happens..

 

sqlQuery("") is a function in brain.php

 

index.php

<?php
include "brain.php";
$table="users";
$ip=$_SERVER["REMOTE_ADDR"];

/*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*/
if (isset ($_POST["submit"])){
$ip=$_SERVER["REMOTE_ADDR"];
$noc=$_POST["noc"];
$name=$_POST["name"];
$email=$_POST["email"];
$phone=$_POST["phone"];
$position=$_POST["position"];
$bad="0";
if ($bad=="0"){
echo "Welcome to the website ".$name."!<br />\n";
sqlQuery("INSERT INTO $table VALUES ('','$ip', '', '$noc', '$name', '$email', '$phone', '$position')", $link, $debug);
}
}



/*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*/
$result=mysql_query("SELECT * FROM $table");
if (!is_resource($result)){
$query="
ID INT(30) NOT NULL AUTO_INCREMENT,
IP VARCHAR(30) NOT NULL,
currentuser INT(1) NOT NULL,
noc VARCHAR(30) NOT NULL,
name VARCHAR(30) NOT NULL,
email VARCHAR(30) NOT NULL,
phone VARCHAR(30) NOT NULL,
position VARCHAR(30) NOT NULL,
PRIMARY KEY (ID)
";
sqlQuery("CREATE TABLE $table($query)", $link, $debug);
echo "A Table(s) has/have been created please refresh the Page if this message continues to come up please contact the Head Admin.<br>";
}
/*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*//*table*/



$ip=$_SERVER["REMOTE_ADDR"];
$result=sqlQuery("SELECT * FROM $table WHERE IP = '69.95.173.35'", $link, $debug);
if (is_resource($result)){
echo "<br />Please select your name-position from the names below or creat a new account";
while ($row = mysql_fetch_assoc($result)) {
echo "\n<input type='submit' class='input' value='".$row['name']."'-'".$row['position']."' name='".$row['name']."'>\n";
	}
	}
	else
	{
	echo "There are, at this time, no accounts other then the on you are currently signed into in the database please sign in as a new user below";
	}
/*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*//*2nd*/





echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
?>
Name of Company:<br>
<input type="text" class="input" value="" name="noc" /><br>
Your Name:<br>
<input type="text" class="input" value="" name="name" /><br>
Your E-Mail:<br>
<input type="text" class="input" value="" name="email" /><br>
Phone Number You can be reached at:<br>
<input type="text" class="input" value="" name="phone" /><br>
Your position with the Company:<br>
<input type="text" class="input" value="" name="position" /><br>
<input type="submit" class="input" value="Enter the Site" name="submit">
<input type="reset" class="input" value="ReTry" name="reset">
<form>

 

brain.php

 


<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
/***MySQLconnect***/
$host="*****************";
$user="***************";
$password="************";
/***databaseconnect***/
$databasename="enduserp_game1";
/****coding****/
$debug="1";
$link = mysql_connect("$host", "$user", "$password");
if ( !is_resource( $link ) )
               echo "Failed to connect to the MySQL service.<br />";
$db_selected = mysql_select_db($databasename, $link);
if (!$db_selected) {
   die("Could not select database: " . mysql_error());
}
function sqlQuery( $mysqlQuery, $link, $debug ) {
       if ( $debug ){
               echo "Query: $mysqlQuery<br />";
			 $result = mysql_query( $mysqlQuery, $link );
       if ( !$result ) {
               if ( $debug )
                       die('Invalid query: ' . mysql_error());
               print "Query failed, please try again.";
               die;
       }
	}
       return;
	}
?>

Link to comment
https://forums.phpfreaks.com/topic/108429-php-ip-display/
Share on other sites

its like it executes the query but then I doesn't find anything when there is that exact IP in there

 

in phpmyadmin i type

 

SELECT * FROM users WHERE IP='my IP'

and it finds the info but but when i type it in php like this

 

$table="users";

$ip=$_SERVER["REMOTE_ADDR"];

$result=sqlQuery("SELECT * FROM $table WHERE IP = '$ip'", $link, $debug);

 

it wont find anything

 

Link to comment
https://forums.phpfreaks.com/topic/108429-php-ip-display/#findComment-555883
Share on other sites

have you echoed $ip to make sure it's the same IP address you expect it to be?

 

$ip=$_SERVER["REMOTE_ADDR"];
echo "ip: $ip";

 

I would change function sqlQuery to show error if query fails:

 

$result = mysql_query( $mysqlQuery, $link ) or die(mysql_error() . " in $mysqlQuery");

Link to comment
https://forums.phpfreaks.com/topic/108429-php-ip-display/#findComment-555886
Share on other sites

it is the IP address is stored to the database straight from my computer so i cant be anything else can it?

 

 

 

if (isset ($_POST["submit"])){

$ip=$_SERVER["REMOTE_ADDR"];

blahblahblah;

sqlQuery("INSERT INTO $table VALUES ('','$ip', '', '$noc', '$name', '$email', '$phone', '$position')", $link, $debug);

}

 

the IP is stored to the database for later review and it takes it straight from you connection

Link to comment
https://forums.phpfreaks.com/topic/108429-php-ip-display/#findComment-555891
Share on other sites

have you echoed $ip to make sure it's the same IP address you expect it to be?

 

$ip=$_SERVER["REMOTE_ADDR"];
echo "ip: $ip";

 

I would change function sqlQuery to show error if query fails:

 

$result = mysql_query( $mysqlQuery, $link ) or die(mysql_error() . " in $mysqlQuery");

Link to comment
https://forums.phpfreaks.com/topic/108429-php-ip-display/#findComment-555953
Share on other sites

tried both of those neither of them work i have a query report attacked to the php page too and it gives back the correct query

 

Query: SELECT * FROM users WHERE IP = '69.95.173.35'

 

 

and thats whats also stored in the date base

 

 

this is the display after everything is done

 

 

Welcome to the website !

Query: INSERT INTO users VALUES ('','76.23.76.109', '', 'kenny', '', '', '', '')

Query: SELECT * FROM users WHERE IP = '76.23.76.109'

There are, at this time, no accounts other then the on you are currently signed into in the database please sign in as a new user below

Link to comment
https://forums.phpfreaks.com/topic/108429-php-ip-display/#findComment-556058
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.