LeonardChallis LeonardChallis - 2 years ago 159
PHP Question

Why am I getting the error "4020 : Information received from an Invalid IP address." from SagePay?

This is a PHP (Zend Framework 1.11) site, not using an off-the-shelf package. When the request to:


(with a
), I get the following response:

4020 : Information received from an Invalid IP address.

I have logged in to the SagePay admin area and added the IP address of the live server to the Valid IPs section and I've made sure it's using the correct SagePay URL to post to and.

An important note is that this issue started this morning, when we changed the SagePay account that payments get sent to, by changing the

Update: This same account (vendor) is used on other accounts with the Form integration method, but the site in question used the Server integration method. Can individual accounts support multiple different payment methods like this, or does one need to activate the other? I don't see any options relating to this in the admin panel.

Answer Source

After getting a response from SagePay I have found the following important notes:

  • You can use Form/Server/Direct integration interchangeably on the same vendor's account, without needing to change settings or register anything
  • The 4020 error genuinely is an IP restriction error and is not masquerading another error

The issue here was that the IP address of the web server (www.mysite.com), being on a VPS, turned out to not be the same address as the one used when curl requests were made. I made a test PHP page that mailed the IP in $_SERVER['REMOTE_ADDR'] to myself and put it on another server. I then used curl to grab that script and low and behold it was a different IP. Putting (a zero padded version of) this in to the Valid IPs section in My SagePay control panel (logged in with the admin account) it sprung to life immediately.


You can use:

curl icanhazip.com

Like so:

[user@host ~]# curl icanhazip.com

to display the correct IP to use, from the command line of the server you're hosting the web site on, instead of uploading files and all that malarkey. More information and usage here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download