Author Topic: Invoking a remote ASPX script that has IP restrictions.  (Read 17337 times)

0 Members and 1 Guest are viewing this topic.

Offline MessitoTopic starter

  • Irregular
    • View Profile
Invoking a remote ASPX script that has IP restrictions.
« on: July 08, 2006, 10:42:25 AM »
Hello,

Looks like a simple code, but I had problems doing it.

What's needed?
The php script should call a remote aspx service on another domain -> www.anotherdomain.com/service.aspx?p1=x&p2=y
This "service.aspx" will only execute if this request is sent from a specific IP. In other words, this service has IP restriction, for security matters.
The returned XML response notifies if the referring IP is authorised or not.

I've configured my site's IP as an authorised IP.

The problem
To invoke the service I've used a simple implode() statement:

Code: [Select]
$xmlAnswer = implode('', file($URL));
Where $URL is the URL of the service call -> http://www.anotherdomain.com/service.aspx?p1=x&p2=y

I get an error response of Invalid IP.
Which I suppose means that the call for the remote service is invoked from the viewer IP (browser page), and not from the machine IP.

Any Ideas how to fix this?

Thanks in advance!  :)

Offline Daniel0

  • Administrator
  • 'Insane!'
  • *
  • Gender: Male
  • ^bb|[^b]{2}$
    • View Profile
    • degeberg.com
Re: Invoking a remote ASPX script that has IP restrictions.
« Reply #1 on: July 08, 2006, 10:58:20 AM »
Are you trying to restrict a script so it may only be run by certain IPs? If so, look at this snippet:

Code: [Select]
<?php
$allowed_ips 
= array('127.0.0.1','1.2.3.4','9.8.7.6');

if(!
in_array($_SERVER['REMOTE_ADDR'],$allowed_ips))
{
die("Your IP ({$_SERVER['REMOTE_ADDR']}) is not allowed to run this script.");
}

// do whatever here...
?>

Offline MessitoTopic starter

  • Irregular
    • View Profile
Re: Invoking a remote ASPX script that has IP restrictions.
« Reply #2 on: July 08, 2006, 11:07:21 AM »
Hi,

thanks for the quick reply.

Actually the service I'm calling to (which is a 3rd party) -> service.aspx , is the one which has IP restriction.

What I need to do, it to make sure that the call for this service (which is done by my php script) will originate from the machine ip
(my domain IP) , and not from the user IP.

The method I tried, using implode() - apparently doesn't work - so I'm wondering how it can be done.

Offline Daniel0

  • Administrator
  • 'Insane!'
  • *
  • Gender: Male
  • ^bb|[^b]{2}$
    • View Profile
    • degeberg.com
Re: Invoking a remote ASPX script that has IP restrictions.
« Reply #3 on: July 08, 2006, 11:14:12 AM »
Just do something similar in the ASP script (I don't know ASP so I can't give an example), just your machine/server IP in the array.

Offline MessitoTopic starter

  • Irregular
    • View Profile
Re: Invoking a remote ASPX script that has IP restrictions.
« Reply #4 on: July 08, 2006, 05:51:20 PM »
but this asp isn't mine - it's a 3rd party service I'm calling to execute an action for me.

My script is in PHP - I need it to call the aspx file, and that this call will originate from my server IP, not from the browser IP.

Any ideas..?

Offline MessitoTopic starter

  • Irregular
    • View Profile
Re: Invoking a remote ASPX script that has IP restrictions.
« Reply #5 on: July 16, 2006, 06:20:34 AM »
Pitching the post up...

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.