Question

Ok so I have a quick question which I suspect for most is ridiculously easy but here goes...

I have a redirect function

function redirect_to( $location = NULL ) {
if ($location != NULL) {
header("Location: {$location}");
ob_end_flush();
exit;
 }
}

But I want to pass in an id variable ($thread_page) into the url, so something like this....

  redirect_to("thread.php?id="<?php echo $thread_page; ?>);

But this doesn't work....any help?

many thanks

No correct solution

OTHER TIPS

It's the same as how you have done it in your function with $location:

redirect_to("thread.php?id=$thread_page");

You can wrap in curly braces for consistency if you like:

redirect_to("thread.php?id={$thread_page}");

Also, this looks like $thread_page might be an integer, but if you are passing any other types of data it is best to use urlencode().

redirect_to("thread.php?id=" . urlencode($thread_page));

You would be calling redirect_to function from PHP itself, so this should work -

 redirect_to("thread.php?id=".$thread_page);
redirect_to('thread.php?id=' . $thread_page);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top