How To Modify REFERRER IN php USING curl_setopt and make a 301 redirect

Viewed 49

I have been trying to set up a 301 redirect and setting the referrer with the domain where it is redirecting to.

e.g https://my-site.com/goto.php?url=https://example.com/drake.mp3

the referrer will be https://example.com

this is because the mp3 files on the https://example.com website are not accessible without the link being clicked on the original website. you cannot accessing it by putting it on your browser address bar, it will be redirected to the homepage of https://example.com.

so i came up with a scipt which i have not achieved what i am looking for.

    <?php
    $redirect_url = $_GET['url'];
    function getter($redirect_url) {
        $referer='http://example.com';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $redirect_url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_REFERER, $referer);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
    
    
    $final = getter($redirect_url);
    
    header("Location: " . $final);
?>

PLEASE HELP ME OUT, I DONT KNOW WHERE I AM GETTING IT WRONG, I AM EVEN A NOVICE IN PHP. BUT I REALLY NEED TO ACHEIEVE THIS PLEASE.

0 Answers
Related