MyBB Community Forums

Full Version: PHP Redirect
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
How can I use PHP to create a redirection of something like:

http://mybb.com/jasoniscool.php?id=hi
to redirect to

http://google.com

pyridine wrote me this line of htaccess to try and it unfortunately failed. So I am looking for a PHP one instead.

RewriteRule blog-script/jason.php?id=hi http://google.com [R,NC]
(2011-09-25, 04:36 AM)Aristotle Wrote: [ -> ]http://php.net/manual/en/function.http-redirect.php

Will that work for you?

No, as I need ?id=1 to redirect to google.com
Umm... yes it'll work for him Toungue
if($mybb->input['id'] == 1)
{
     http_redirect("http://google.com);
}

EDIT: But Jason, don't PM me for support like that anymore, thanks Smile
(2011-09-25, 04:52 AM)Dylan M. Wrote: [ -> ]Umm... yes it'll work for him Toungue
if($mybb->input['id'] == 1)
{
     http_redirect("http://google.com);
}

EDIT: But Jason, don't PM me for support like that anymore, thanks Smile

This wont be for MyBB (reasoning why its not in support or something else) so how can I go about editing that to where its just for a normal page?

Sorry.
Replace the $mybb->input with the appropriate input class if you're using one, or $_GET if you aren't.
(2011-09-25, 05:02 AM)Dylan M. Wrote: [ -> ]Replace the $mybb->input with the appropriate input class if you're using one, or $_GET if you aren't.

<?php

if($_GET['id'] == 1)
{
     http_redirect("http://google.com);
}

?>

Quote:Parse error: syntax error, unexpected $end in /home/jasonl/public_html/blog-script/sponsors.php on line 8

UPDATE: Seems you made a mini type and forgot the " after google. However, now I get

Quote:Fatal error: Call to undefined function http_redirect() in /home/jasonl/public_html/blog-script/sponsors.php on line 5

Can I fix it by starting outbound buffering and then placing a header location function in there?
I fixed it myself with this code incase anyone is interested.

<?php

ob_start(); 
session_start(); 


if($_GET['id'] == 1)
{
	ob_end_clean(); 
	header( 'Location: http://google.com' ) ;
	exit; 
}

?>
To use http_redirect() you need to have the PECL extensions installed on your server. Otherwise you're limited to the header() instead.
(2011-09-25, 03:38 PM)Dylan M. Wrote: [ -> ]To use http_redirect() you need to have the PECL extensions installed on your server. Otherwise you're limited to the header() instead.

I already fixed it with the code I provided above.

demo
Sometimes, easy to do scripts makes our jobs tedious.
Pages: 1 2