Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Use mysql and ph record uniqe ip address

Posted on 2006-06-30
6
Medium Priority
?
282 Views
Last Modified: 2011-10-03
i want to add this to my curent guest book essboork but only record it if it is uniqe
0
Comment
Question by:jcw20
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 29

Accepted Solution

by:
TeRReF earned 1000 total points
ID: 17020373
Euh... do you mind clearifying your question a bit?

You can retrieve someone's ip-address with
$ip = $_SERVER["SERVER_ADDR"];

You could create a table with ip addresses and query it with the aquired ip addres, something like:
$query = "SELECT COUNT(*) as cnt from ipaddresses where ip=".$ip;

Hope this helps a bit?!
0
 
LVL 1

Author Comment

by:jcw20
ID: 17020876
Well my goal is to have the guestbook show the ip plus record other info but if that ip has been recorded to not accept the entry but i don't know what kind of field to use in mysql to shw up as a doted decimal  like  1234.1234.1234.1234
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 17021018
You should use varchar(15) and do a string comparison in a query (like the query I showed you)
0
 
LVL 1

Author Comment

by:jcw20
ID: 17021082
<?php
$host="10.10.10.4"; // Host name
$username="web"; // Mysql username
$password=""; // Mysql password
$db_name="addressbook"; // Database name
$tbl_name="addressbook"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");

$datetime=date("y-m-d h:i:s"); //date time
$ip = $_POST['ip'];
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$sql="INSERT INTO $tbl_name(ip,name,lastname, email, comment, datetime)VALUES('$ip','$name','$lastname', '$email', '$comment', '$datetime')";
$result=mysql_query($sql);

//check if query successful
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page
}

else {
echo "ERROR";
}

mysql_close();
?>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question