How To receive GET or POST Request From Specified servers

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
Mohammad-Za
Forum Newbie
Posts: 1
Joined: Thu Aug 18, 2011 3:38 am

How To receive GET or POST Request From Specified servers

Post by Mohammad-Za »

Hello Guys.

I've authored a php file which receives some information like this from a bank site (like paypal) :
www.exmaple.com/verfy.php?[b]ed=xxxxx&s ... ?tid=zzzzz[/b]
and stores the ed , sd, tid numbers in the database.
But there's a problem ! Every one can crate a file which posts those information to my verfy.php file!
What should I do to receive those information from ONLY one server!
* I also used HTTP_REFERER but it didn't work.
genix2011
Forum Commoner
Posts: 74
Joined: Tue Aug 02, 2011 4:00 pm

Re: How To receive GET or POST Request From Specified server

Post by genix2011 »

hi,

you can check for the ip accessing your script, using this function:

Code: Select all

$remoteip = '127.0.0.1';
if($remoteip != get_ip_address()){
    die("You are not allowed to access this script!");
}

function get_ip_address() {
    foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) {
        if (array_key_exists($key, $_SERVER) === true) {
            foreach (explode(',', $_SERVER[$key]) as $ip) {
                if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
                    return $ip;
                }
            }
        }
    }
}
Post Reply