guymclarenza Posted February 13, 2021 Share Posted February 13, 2021 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) ?> Quote Link to comment https://forums.phpfreaks.com/topic/312141-still-trying-to-learn/ Share on other sites More sharing options...
benanamen Posted February 13, 2021 Share Posted February 13, 2021 Where does $url magically come from? Quote Link to comment https://forums.phpfreaks.com/topic/312141-still-trying-to-learn/#findComment-1584433 Share on other sites More sharing options...
Solution guymclarenza Posted February 13, 2021 Author Solution Share Posted February 13, 2021 I worked out where to do the var dumps, I think I now understand what this script is doing. Quote Link to comment https://forums.phpfreaks.com/topic/312141-still-trying-to-learn/#findComment-1584434 Share on other sites More sharing options...
guymclarenza Posted February 13, 2021 Author Share Posted February 13, 2021 1 minute ago, benanamen said: Where does $url magically come from? Yes I found that and fixed it. I had two variables for the same thing. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/312141-still-trying-to-learn/#findComment-1584435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.