SERVER_ADDR issue!

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
yankleber
Forum Newbie
Posts: 4
Joined: Sun Dec 06, 2009 11:31 am

SERVER_ADDR issue!

Post by yankleber »

Hey all!

I am new here and I am really needing badly to figure this out...

I am working on a remote authenticating algorythm using PHP, and I have two simple scripts (a main one and an include one), like this:

Main script at client website...

Code: Select all

 
<?php
include "http://www.mywebsite.com/checkpar2.php";
?>
 
Checkpar2.php script at MY website...

Code: Select all

 
<?php
echo $_SERVER['SERVER_ADDR'];
?>
 
As you can notice, I am trying to capture the IP address of the client. The problem is that it is echoing my IP and not the client IP. I am really puzzled with that, because since the second script is being included in the first script and not ran as standalone, I wouldnt suppose to work as part of the first script, and therefore, echo the IP of the server where the first script is???

What am I missing here??

Thank is advance!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: SERVER_ADDR issue!

Post by AbraCadaver »

When the client website includes the file from a remote website using HTTP, the remote webserver actually parses/executes the PHP in that file and returns the result. So you get the SERVER_ADDR of http://www.mywebsite.com. There are a several options. Here are two:

1. Change the extension to something that the webserver doesn't parse as PHP, 'checkpar2.inc'
2. Use SMB/CIFS or NFS to mount the remote sites filesystem and then do an include on that path

-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
yankleber
Forum Newbie
Posts: 4
Joined: Sun Dec 06, 2009 11:31 am

Re: SERVER_ADDR issue!

Post by yankleber »

Hi Shawn,

Thanks for your quick response!

The problem on use an extension other than ".php", is because anyone can paste it directly in the browser, so the entire code will be showed in the screen. Since it is part of an authentication process (actually a copy protection), the reason I want to use it as an include is exactly because I don't want that users know WHAT I am doing (and this way make it harder to crack my lock).

About the other solution, it seems to be a nice one but I have no idea what you are talking about! Could you give me a few more details about that???

Thanks!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: SERVER_ADDR issue!

Post by AbraCadaver »

Depends on the OS. By SMB/CIFS I mean a mapped drive in windows. NFS is a similar technology for linux/unix.

-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply