user3199862
user3199862

Reputation: 1

unable to send user to other page php

i have a code that fetch a movie trailler and create a youtube url. everything is work ok except when it's time to open it in the browser, here the code

if (isset($_POST['link'])){
    $arr1 = $_POST['link']; 
    $movieName = str_replace(' ', '+', $arr1[0]);
    $movieYear = $arr1[1];
    $page = file_get_contents('http://www.youtube.com/results?search_query='.$movieName.'+'.$movieYear.'+trailer&aq=1&hl=en');
    if($page){
         if(preg_match('~<a .*?href="/watch\?v=(.*?)".*?</div>~s', $page, $matches))
             $youtubelink = "http://www.youtube.com/v/" . $matches[1];
             header("Location: '".$youtubelink."'");
        }
        else
        {
            echo "<b>Trailler not found</b>";
        }
} 

When i press the button, it does not send me to the youtube link, i know that the link is good cause when i erase the header code and echo the $youtubelink, it is the good address.

Thanks

Edit: I end up with this:

echo "<script>window.location = '$youtubelink'</script>";

Upvotes: 0

Views: 48

Answers (1)

user2537383
user2537383

Reputation: 315

header('Location: http://www.example.com/');

Those single quotes are messing you up.

Upvotes: 4

Related Questions