Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder MrBiggZ's Avatar
    Join Date
    Apr 2005
    Location
    Indianapolis IN
    Posts
    345
    Thanks
    44
    Thanked 2 Times in 2 Posts

    Trying to get the HTTP status code of a URL but getting the page data along with it

    Hi!

    I'm trying to get the HTTP status code for a URL but I'm getting the page data along with it. Don't understand why. =\

    Here's the function I created:

    PHP Code:
    function pageStatus ($url) {
        
    $http curl_init($url);
        
    $result curl_exec($http);
        
    $http_status curl_getinfo($httpCURLINFO_HTTP_CODE);
        
    curl_close($http);
        echo 
    $http_status;

    Here is the URL I used which is the URL I would use to get my data.

    http://api.openweathermap.org/data/2...units=imperial

    I've tried to just use http://api.openweathermap.org/data/2.5/group and I get both a 404 and a 200 along with the page data.

    I'm rather confused as to why! .

    What am I doing wrong?!?!

    Thanks for your help!

    Dave
    “No matter how slick the demo is in rehearsal, when you do it in front of a live audience, the probability of a flawless presentation is inversely proportional to the number of people watching, raised to the power of the amount of money involved.” ~ Mark Gibbs

  • #2
    Regular Coder MrBiggZ's Avatar
    Join Date
    Apr 2005
    Location
    Indianapolis IN
    Posts
    345
    Thanks
    44
    Thanked 2 Times in 2 Posts
    I fixed my problem. I just did a little more reading and got what I needed.

    PHP Code:
    function pageStatus ($url) {
    $handle curl_init($url);
    curl_setopt($handle,  CURLOPT_RETURNTRANSFERTRUE);
    $response curl_exec($handle);
    $httpCode curl_getinfo($handleCURLINFO_HTTP_CODE);
    return 
    $httpCode;
    curl_close($handle);

    “No matter how slick the demo is in rehearsal, when you do it in front of a live audience, the probability of a flawless presentation is inversely proportional to the number of people watching, raised to the power of the amount of money involved.” ~ Mark Gibbs


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •