newbie php question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pnutz
Forum Newbie
Posts: 5
Joined: Sat Dec 27, 2003 12:33 pm

newbie php question

Post by pnutz »

:roll:

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!
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

You want to get the IP address and hostname of a user visiting one of your php scripts?
pnutz
Forum Newbie
Posts: 5
Joined: Sat Dec 27, 2003 12:33 pm

Post by pnutz »

yes i do..
how do i go abt this...
pnutz
Forum Newbie
Posts: 5
Joined: Sat Dec 27, 2003 12:33 pm

Post 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...
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Sorry, don't think I will be able to help, but what would the client be requesting via the HTTP? A webpage?
pnutz
Forum Newbie
Posts: 5
Joined: Sat Dec 27, 2003 12:33 pm

Post 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...
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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
pnutz
Forum Newbie
Posts: 5
Joined: Sat Dec 27, 2003 12:33 pm

Post by pnutz »

hey there thanks for the reply..
do i need to declare anything..
cause i seem to get variable undefined error..
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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
Post Reply