0

i need to redirect url

https://vivekp.co/server/apiurl/qwertyuiopl

but its redirect to

https://vivekp.co/server/apiurl/".$youtube_id

how solve this?

<?php
if (isset($_GET['urlid'])) {
$url = $_GET["urlid"];
//$url="https://youtube.com/watch?v=fbjfnjnfkjs";

preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match);

$youtube_id = $match[1];

$nr="https://vivekp.co/server/apiurl/".$youtube_id;

header('location:$nr');

}else{
    echo "Error";
}
?>
Vicky
  • 21
  • 6

2 Answers2

1

Just set your header like,

header('location:'.$nr);
Virb
  • 1,639
  • 1
  • 16
  • 25
0

You should either take out the variable from '' or change it to ""

header("location:$nr");

or

header('location:'.$nr);
Himanshu Upadhyay
  • 6,558
  • 1
  • 20
  • 33