Jump to content

[SOLVED] curl question


dtdetu

Recommended Posts

<?php
session_start();

function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}


$_SESSION['url'] = curPageURL();


?>

 

 

 

the code above gets the current url for which you are on, then it will store it to a session variable

 

 

then on redirect do the following code

 

this will be on the page it is redircted to...

 

 

<?php
session_start();

echo $_SESSION['url'];

?>

Link to comment
https://forums.phpfreaks.com/topic/135791-solved-curl-question/#findComment-707602
Share on other sites

but how can i use this with curl my code is this

 

 $ch = curl_init("$l[link]"); 
       curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/'); 
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);   
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
       curl_setopt ($ch, CURLOPT_COOKIEJAR, 'files/cookie.txt');  
       $result = curl_exec($ch);

 

this code redirects me to some url how can i get that url

Link to comment
https://forums.phpfreaks.com/topic/135791-solved-curl-question/#findComment-707609
Share on other sites

it redirects me to a random url which i dont know , i want to get the url like

 

$redirectedurl = $??;

 

You need to set the CURLOPT_FOLLOWLOCATION option to false and the CURLOPT_RETURNTRANSFER option to true. Then parse the returned data for the location. The method of redirection determines where you need to look. For example, if you're being redirected with an HTTP header, then you'll also need to set the CURLOPT_HEADER option to true and look for the text after 'location'

Link to comment
https://forums.phpfreaks.com/topic/135791-solved-curl-question/#findComment-707677
Share on other sites

hey i found the solution in case someone needs

 

<?
function get_web_page( $url ) 
{ 
    $options = array( 
        CURLOPT_RETURNTRANSFER => true,     // return web page 
        CURLOPT_HEADER         => true,    // return headers 
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects 
        CURLOPT_ENCODING       => "",       // handle all encodings 
        CURLOPT_USERAGENT      => "spider", // who am i 
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect 
        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect 
        CURLOPT_TIMEOUT        => 120,      // timeout on response 
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects 
    ); 

    $ch      = curl_init( $url ); 
    curl_setopt_array( $ch, $options ); 
    $content = curl_exec( $ch ); 
    $err     = curl_errno( $ch ); 
    $errmsg  = curl_error( $ch ); 
    $header  = curl_getinfo( $ch ); 
    curl_close( $ch ); 

    //$header['errno']   = $err; 
   // $header['errmsg']  = $errmsg; 
    //$header['content'] = $content; 
    print($header[0]); 
    return $header; 
}  
$thisurl = "myurl";
$myUrlInfo = get_web_page( $thisurl ); 
echo $myUrlInfo["url"];
?>

Link to comment
https://forums.phpfreaks.com/topic/135791-solved-curl-question/#findComment-707679
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.