Jump to content

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

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.