Jump to content

still trying to learn


Go to solution Solved by guymclarenza,

Recommended Posts

This script with minor changes came from a tutorial. I did a var dump and get a NULL result.  Can anyone tell me why? 

 

<?php
/** Get web page via HTTP GET using Libcurl.  */
function getPageDetails($target, $referer) {
       
    $info = curl_init();
    //settings
    curl_setopt($info, CURLOPT_HEADER, true);
    curl_setopt($info, CURLOPT_COOKIEJAR, "cookie_jar.txt");
    curl_setopt($info, CURLOPT_COOKIEFILE, "cookies.txt");
    curl_setopt($info, CURLOPT_USERAGENT, "imagimediabot2");
    curl_setopt($info, CURLOPT_URL, $url);
    curl_setopt($info, CURLOPT_REFERER, $referer);
    curl_setopt($info, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($info, CURLOPT_MAXREDIRS, 4);
    curl_setopt($info, CURLOPT_RETURNTRANSFER, true);
    
    //request
    $output = curl_exec($info);

    curl_close ($info);
    //seperate head and body
    $separator = "\r\n\r\n";
    $header = substr( $output, 0, strpos( $output, $separator ) );
    $body_start = strlen( $header ) + strlen( $separator );
    $body = substr($output, $body_start, strlen($output)-$body_start);
    
    // parse headers
    $header_array = Array();
        foreach (explode ("\r\n", $header) as $i => $line) {
            if($i === 0) {
              $header_array['http_code'] = $line;
              $status_info = explode( " ", $line );
              $header_array['status_info'] = $status_info;
        } else {
              list ( $key, $value ) = explode ( ': ', $line );
              $header_array[$key] = $value;
        }
    }

    $ret = Array("headers"=>$header_array,"body"=>$body);
    return $ret;
}

$page = getPageDetails("https://imagimedia.co.za", "");
$headers = $page['headers'];
$http_status_code = $headers['http_code'];
$body = $page['body'];

var_dump($header_array)
?>

 

Link to comment
https://forums.phpfreaks.com/topic/312141-still-trying-to-learn/
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.