Jump to content

Invoking a remote ASPX script that has IP restrictions.


Messito

Recommended Posts

Hello,

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

[u]What's needed?[/u]
The php script should call a remote aspx service on another domain -> [b]www.anotherdomain.com/service.aspx?p1=x&p2=y[/b]
This "service.aspx" will only execute if this request is sent from a [b]specific IP[/b]. 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.

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

[code]$xmlAnswer = implode('', file($URL));[/code]

Where $URL is the URL of the service call -> http://www.anotherdomain.com/service.aspx?p1=x&p2=y

[b]I get an error response of Invalid IP.[/b]
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.

[b]Any Ideas how to fix this?[/b]

Thanks in advance!  :)
Link to comment
Share on other sites

Are you trying to restrict a script so it may only be run by certain IPs? If so, look at this snippet:

[code]<?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...
?>[/code]
Link to comment
Share on other sites

Hi,

thanks for the quick reply.

Actually the service I'm calling to (which is a 3rd party) -> [b]service.aspx [/b] , 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.
Link to comment
Share on other sites

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..?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.