Quick Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cloggin55
Forum Newbie
Posts: 3
Joined: Thu Apr 08, 2010 5:57 am

Quick Question

Post by cloggin55 »

I"m trying to pass some code through a redirect and I'm getting an error.
Anyone have any suggestion?

This is the redirect with the code

<?
$urls = array(
"http://url1.com/?id=<?php echo str_replace('-', ' ', $_GET['id'])?>",
"http://url2.com/?id=<?php echo str_replace('-', ' ', $_GET['id'])?>");
$url = $urls[array_rand($urls)];
$destination = "Location: $url";
header($destination);
?>

Any help is much appreciated.

Thanks!
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: Quick Question

Post by dejvos »

I think this will work.

Code: Select all

<?
$urls = array(
"http://url1.com/?id=".str_replace('-', ' ', $_GET['id']),
"http://url2.com/?id=".str_replace('-', ' ', $_GET['id'])
);
$url = $urls[array_rand($urls)];
$destination = "Location: $url";
header($destination);
?>
Turv
Forum Commoner
Posts: 25
Joined: Fri Mar 13, 2009 3:56 pm

Re: Quick Question

Post by Turv »

cloggin55 wrote:I"m trying to pass some code through a redirect and I'm getting an error.
Anyone have any suggestion?

This is the redirect with the code

<?
$urls = array(
"http://url1.com/?id=<?php echo str_replace('-', ' ', $_GET['id'])?>",
"http://url2.com/?id=<?php echo str_replace('-', ' ', $_GET['id'])?>");
$url = $urls[array_rand($urls)];
$destination = "Location: $url";
header($destination);
?>

Any help is much appreciated.

Thanks!
You are opeing PHP Tags from within another PHP Tag, Look up PHP String Concatenation
Post Reply