help with logging ip address during registration

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rxpghost
Forum Newbie
Posts: 9
Joined: Fri Oct 31, 2008 7:00 pm

help with logging ip address during registration

Post by rxpghost »

Hello,

I would like to log the ip address of people that register on my site. I have created the database table for this but need the php code to get it logged. On the registration page I have a form that posts the data from each field to the db. I am new to php so the simplest terms would be appreciated.

Thanks in advance
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: help with logging ip address during registration

Post by Syntac »

Code: Select all

echo $_SERVER["REMOTE_ADDR"]; // Should print the client's IP address
rxpghost
Forum Newbie
Posts: 9
Joined: Fri Oct 31, 2008 7:00 pm

Re: help with logging ip address during registration

Post by rxpghost »

thanks for the quick reply. I want something that will post the ip address in the database table "ip". Any ideas on how to do this?
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: help with logging ip address during registration

Post by omniuni »

How is your database structured? Otherwise, check this link:

http://www.tizag.com/mysqlTutorial/mysqlinsert.php
rxpghost
Forum Newbie
Posts: 9
Joined: Fri Oct 31, 2008 7:00 pm

Re: help with logging ip address during registration

Post by rxpghost »

this would be the db query but i just used the mysql wizard to create the table

Code: Select all

CREATE TABLE `ip` (
`id` int(5) NOT NULL auto_increment,
`ip` varchar(50) NOT NULL default ”,
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
one post on another site looks about right but I always get errors when I insert that code into my form.

Code: Select all

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$sql = “INSERT INTO `ip` ( `id` , `ip` ) VALUES ( ”, ‘$ip’)”;
$query = mysql_query($sql);
 
print “Logged: $ip”;
?>
rxpghost
Forum Newbie
Posts: 9
Joined: Fri Oct 31, 2008 7:00 pm

Re: help with logging ip address during registration

Post by rxpghost »

ok I figured out how to log the ip address. Now I have two other things to figure out for my login system. First I need to know how to replace the password that people type to Astrix ***** instead of showing the actual password. Also I need to add "verify email" and "verify password" fields and have them compare to each other. Again, I appreciate any help that you can offer.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: help with logging ip address during registration

Post by omniuni »

starring the password is done client-side:

Code: Select all

 
<input type="password" size="30" />
As for comparing, submit on post something like "pass1" and "pass2" and and just use PHP's comparator to see if they're the same, otherwise, reload the page, and display a warning that they did not match.
rxpghost
Forum Newbie
Posts: 9
Joined: Fri Oct 31, 2008 7:00 pm

Re: help with logging ip address during registration

Post by rxpghost »

I don't understand how it's done on the client side. I have had the login system up and running and it doesn't star the password. I've checked it from several computers and still the same result. Can you explain in more detail how to compare the password, confirm password? Thanks in advance.
baoky
Forum Newbie
Posts: 12
Joined: Sat May 24, 2008 6:21 am

Re: help with logging ip address during registration

Post by baoky »

Google was invented for a reasonImage
rxpghost
Forum Newbie
Posts: 9
Joined: Fri Oct 31, 2008 7:00 pm

Re: help with logging ip address during registration

Post by rxpghost »

Wow what a worthless comment. It speaks to your character that you would take the time to register just to post an insulting comment. Thank you to everyone else that has been helpful.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: help with logging ip address during registration

Post by s.dot »

Code: Select all

<input type="password" name="passwordFieldName">
will 'star' the password

to compare that the passwords match, you need two HTML fields for entering the passwords.

Code: Select all

<p>Password: <input type="password" name="password" /><br />
Confirm Password: <input type="password" name="passwordConfirm" /></p>
And to check them in PHP:

Code: Select all

if ($_POST['password'] != $_POST['passwordConfirm'])
{
    die('Your passwords do not match.');
}
Here's a good form tutorial: http://www.htmlgoodies.com/tutorials/fo ... hp/3479121
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
rxpghost
Forum Newbie
Posts: 9
Joined: Fri Oct 31, 2008 7:00 pm

Re: help with logging ip address during registration

Post by rxpghost »

Many thanks Scottayy, that's exactly what I was looking for.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: help with logging ip address during registration

Post by VladSun »

rxpghost wrote:Wow what a worthless comment.
I do second baoky's opinion!
All of your simple questions in your thread are "google answerable".

You should start "learn & think", instead of "copy & pasting" ;)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply