Forum Moderators: coopster
My apologies if this question has been asked
in the past.
I am building a PHP links page that contains
all of the outgoing links for my site. For
example...
domain-1.com/links.php
Here is the PHP code that I am using on my
domain-1.com/links.php page...
<?PHP
$go = $_GET['go'];
if ($go == "") {$link = "http://www.domain-1.com/";}
if ($go == "GX40T") {$link = "http://domain-2.com/?masked=GX40T";}
if ($go == "YR57W") {$link = "http://domain-2.com/?masked=YR57W";}
if ($go == "PB24Y") {$link = "http://domain-2.com/?masked=PB24Y";}
header("Location: $link");
exit();
?>
Here is what I am doing...
I am loading a .php page with an URL that
includes a "masked" variable. For example,
the URL would look like this...
domain-1.com/mypage.php?masked=GX40T
I am then using PHP on that .php page to
pull the "masked" variable into the links
on that .php page. The "masked" variable
would be passed as the "go" variable in
the links. For example, the links on the
.php page would look like this...
domain-1.com/links.php?go=GX40T
I am then using the PHP code above to
pass the "go" variable back to a "masked"
variable in the outgoing link. In this
case, the outgoing link would be...
http://domain-2.com/?masked=GX40T
Here is what I would like to do...
Currently, I am forced to list list tons of
outgoing links on my domain-1.com/links.php
page because I have tons of "masked" values.
I would like to be able to insert some PHP
in the example code above to dynamically
pull whatever the original "masked" variable
is.
In effect, I would only have the following
code (it is only an example and I think it's
bad code, but hopefully you'll get the idea)...
<?PHP
$go = $_GET['go'];
if ($go == "") {$link = "http://www.domain-1.com/";}
if ($go == "<?php echo $_GET['masked'];?>") {$link = "http://domain-2.com/?masked=<?php echo $_GET['masked'];?>";}
header("Location: $link");
exit();
?>
Is this possible? If so, does anyone know
how I can easily do this?
I'm a real knucklehead with PHP. I've been
looking for hours in various forums for the
solution, but most of it is way above my
head.
Any advice would be greatly appreciated.
Thanks!
[edited by: eelixduppy at 5:02 pm (utc) on June 19, 2007]
[edit reason] delinked [/edit]
<?php
$go = $_REQUEST['go'];
if ($go == "") {$link = "http://www.domain-1.com/";}
if ($go == $_REQUEST['masked']) {$link = "http://domain-2.com/?masked=$_REQUEST['masked']";}
header("Location: $link");
exit();
?>
Now, in brief let us know what is not working.
Habtom
before you pass variables as checked, better check them if they are what you allow:
The easiest to expand is:
<?PHP$go = $_GET['go'];
$allowed = "GX40T, YR57W, PB24Y";//here pass all values that you allow, they have to be delimited by $delimiter
$delimiter = ", ";
$allowed_arr = explode($delimiter, $allowed);if (in_array($go, $allowed_arr)){ //if value is in array, then pass it further
header("Location: http://domain-2.com/?masked=$go");
}
else {//if not in array, then show main page
header("Location: http://www.domain-1.com/");
}?>
Security is not to be omitted :)
Michal
[edited by: eelixduppy at 8:13 pm (utc) on June 19, 2007]
[edit reason] delinked [/edit]
sorry about the rogue ampersand ;-) I just copied and pasted your variable and missed that off!
Also, about the secrity check, it's a good shout. But I can't see why in this instance there would be any security issues? The variable handling is quite harmless, presumably they are being converted into URL's via hardcoded PHP and no SQL calls?
If the latter is true, there would need to be other, quite simple security in place.
<?PHP
$go = $_GET['go'];
if ($go!= ""){
header("Location: http://domain-2.com/?masked=$go");
}
else {
header("Location: http://www.domain-1.com/");
}
?>
[edited by: eelixduppy at 8:30 pm (utc) on June 19, 2007]
[edit reason] delinked [/edit]