Forum Moderators: open

Message Too Old, No Replies

Grabbing an IP

         

glamdring

4:30 pm on Jul 5, 2004 (gmt 0)

10+ Year Member



Can someone tell me if its possible to grab an IP address when a simple, one field form is submitted without using a server-side language such as php?

If so, how the heck do I do it?

coopster

5:18 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Most examples you will find will use a server-side solution. A java/javascript solution is probably possible. Why can't you use server-side?

glamdring

6:10 pm on Jul 5, 2004 (gmt 0)

10+ Year Member



Oh, its not that I cant do it...

more like its a total pain in the a** to do it, as its a tiny little mod to an otherwise complete site, and means moving a bunch of links, etc.

Still, looks like I dont have much of a choice! LOL

THanks

Philosopher

6:15 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your grabbing it from a submitted form, then it's already being processed by a server side script right? Why not just grab the IP from the info sent with the form? Seems it would be an easy mod. to make to the current script.

Then again, maybe I'm missing something here.

glamdring

6:38 pm on Jul 5, 2004 (gmt 0)

10+ Year Member



Well this is what makes up the form at the moment. Its just an email field that gets written to an mySQL db on submission.

<form name="camera" method="post" action="/camera.php">
<table width="100" border="0" align="center" cellpadding="0" cellspacing="2">
<tr>
<td><input name="cam_email" type="text" size="30" maxlength="40"></td>
</tr>
<tr>
<td><p align=center><input type="submit" name="Submit" value="Submit"></p></td>
</tr>
</table>
//--THIS BIT IS WHAT I'VE GOT IN ANOTHER FORM--//
<input type="hidden" name="IP" value="<? echo $_SERVER['REMOTE_ADDR'];?>">
</form>

But how do I actually get the IP without using the PHP $_SERVER['REMOTE_ADDR'] command? Thats what I mean.

coopster

7:12 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That's what Philosopher is getting at. In the processing script,
camera.php
, just use that PHP variable for insertion/update of the row in your database. In your query statement, just add it, something like this

$sql = "INSERT INTO table (ipaddress) VALUES('" . $_SERVER['REMOTE_ADDR'] . "')";

glamdring

7:22 pm on Jul 5, 2004 (gmt 0)

10+ Year Member



Ah! So it doesnt need to be in the form itself then?

coopster

7:26 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Nope, it doesn't. Now you're getting the picture ;)