cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Inconsistent results (command line vs php)

From: Jonathan Surname <jonathan.mailling.lists_at_gmail.com>
Date: Wed, 25 Nov 2015 22:11:40 +0000

I did search but apologise in advance if this has been asked before.
If further information is required then please let me know and I will
supply it.

There is a particular website for which I get a 200 result from curl
on the command line, but 302 using curl via PHP. This happens for all
pages on that website. Generally I have no problems with the PHP
script.

What can I do to get the script to return 200 as it (I think) ought?

See below for further information.

Thanks in anticipation

Jonathan

When I run curl -I http://www.....ac.uk/ at the command line I get:
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 61060
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Tue, 17 Nov 2015 00:48:21 GMT

When I run it via PHP I get:
HTTP/1.1 302 Found
Cache-Control: private
Content-Length: 163
Content-Type: text/html; charset=utf-8
Location: /Error.htm?aspxerrorpath=/default.aspx
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Tue, 17 Nov 2015 00:24:10 GMT

Here's my PHP function:

    function load_with_curl ($url) {
        $c = curl_init($url);
        curl_setopt($c, CURLOPT_RETURNTRANSFER, true); #get response
as string instead of echoing
        curl_setopt($c, CURLOPT_NOBODY, true); # no body
        curl_setopt($c, CURLOPT_HEADER, true); # yes get header

        #Experimenting to see if can fix problem (did not help)
        #curl_setopt($c, CURLOPT_FRESH_CONNECT, true);
        #$header = array("Cache-Control: no-cache");
        #curl_setopt($c, CURLOPT_HTTPHEADER, $header);

        $response = curl_exec($c);
        return array($response, curl_getinfo($c));
    }

Here is what seems to be potentialy relevant from phpinfo:

PHP Version 5.4.37

Configure Command ......... --with-curl' '--with-curlwrappers' ..............

curl
cURL support enabled
cURL Information 7.45.0
Age 3
Features
AsynchDNS No
Debug No
GSS-Negotiate No
IDN Yes
IPv6 Yes
Largefile Yes
NTLM Yes
SPNEGO No
SSL Yes
SSPI No
krb4 No
libz Yes
CharConv No
Protocols dict, file, ftp, ftps, gopher, http, https, imap, imaps,
ldap, ldaps, pop3, pop3s, rtsp, smb, smbs, smtp, smtps, telnet, tftp
Host i686-pc-linux-gnu
SSL Version OpenSSL/0.9.8zg
ZLib Version 1.2.5
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2015-11-26