Solved

Use mysql and ph record uniqe ip address

Posted on 2006-06-30
6
230 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
  • 2
  • 2
6 Comments
 
LVL 29

Accepted Solution

by:
TeRReF earned 250 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now