Page 1 of 1
newbie php question
Posted: Sat Dec 27, 2003 12:33 pm
by pnutz
How do i go abt doing this
1) get a http packet from my client
2) from the packet i need to know my client ip and machine name
3) Then send in my the back a message that i have received the request
How do i go abt doing this
Thanks
marry x-mas!
Posted: Sat Dec 27, 2003 3:49 pm
by nigma
You want to get the IP address and hostname of a user visiting one of your php scripts?
Posted: Sat Dec 27, 2003 8:45 pm
by pnutz
yes i do..
how do i go abt this...
Posted: Sat Dec 27, 2003 9:14 pm
by pnutz
Thanks for the replay...but How do i accept http request from my client, for example lets say my client sends me a string "Hi"... how do i accept this request and then write a function to get the client's ip and machine name
Then send back a response saything that request received...
Anyone with any ideas..
Thanks...
Posted: Sat Dec 27, 2003 9:57 pm
by nigma
Sorry, don't think I will be able to help, but what would the client be requesting via the HTTP? A webpage?
Posted: Sat Dec 27, 2003 10:10 pm
by pnutz
my client would send me a http request would would be a hi string... this is how i do it in asp...
<html>
<form action="page2.asp?message=hello">
<input type=submit value="send message">
</form>
</html>
and my server would receive as such
Dim strMessage, strIP
strMessage=Request("message")
Response.write(strMessage)
strIP=Request.ServerVariables("Remote_Host")
how do i encode this to php...
Posted: Sat Dec 27, 2003 11:04 pm
by nigma
Alright, in that case you would put this in your PHP script:
Code: Select all
$msg = $_GET['message']; // Would be assigned the value "hi"
$userIP = $REMOTE_ADDR; // Users IP
$userHost = $REMOTE_HOST; // Users Hostname
Posted: Sat Dec 27, 2003 11:25 pm
by pnutz
hey there thanks for the reply..
do i need to declare anything..
cause i seem to get variable undefined error..
Posted: Sun Dec 28, 2003 12:46 am
by Nay
Er, try this instead:
Code: Select all
<?php
$msg = $_GET['message'];
$userIP = $_SERVER['REMOTE_ADDR'];
$userHost = $_SERVER['REMOTE_HOST'];
?>
Most probably you have register_globals off so $REMOTE_ADDR and $REMOTE_HOST means nothing to PHP. And also, you'll need to call the file as file.php?message=the_message.
-Nay
Posted: Sun Dec 28, 2003 12:53 pm
by nigma
Also, Nay / Charp:
After reading your post Nay and feeling quite embarassed for not covering what should have been covered I went over to the PHP man and did some reading, appearantly you can also do this by using the function
getenv().
http://us2.php.net/getenv