Forum Moderators: coopster
The example below has two (not sure about the term) (sub?) arrays, fire and water. What this script does is detect strings in the referrer and if any part of the referrer contains a string in the array the visitor is immediately redirected by the server. The redirect.php simply handles the HTTP query and works just fine (allows me to monitor outbound traffic if this script is triggered). I want to modify the script so that any strings in the water sub-array ultimately redirected to redirect.php?lookingfor=water and of course visitors with referrers that match the fire sub-array strings to be redirected to redirect.php?lookingfor=fire.
I had more then just a little help getting this working in the first place so I'm not sure how to even approach this right now. Is there a specific or general term for what I'm trying to do?
- John
<?php
$referer = $_SERVER['HTTP_REFERER'];$searchstrings = array
(
'fire' => array // $searchstrings['fire']
(
'fire',
'hot',
'lava',
),
'water' => array // $searchstrings['water']
(
'water',
'liquid',
'h20',
)
);if ($referer == '') {
$result = FALSE;
}else{
$result = FALSE;
foreach ($searchstrings as $group) {
foreach ($group as $ua){
if (stristr($referer,$ua)) {
$result = TRUE;
break 2;
}
}
}
}// Redirect
// if ($result == true) {header("Location: http://www.example.com/redirect.php?lookingfor=fire");}
// if ($result == true) {header("Location: http://www.example.com/redirect.php?lookingfor=water");}
?>
<?
$keywords = array("fire", "lava");
if(in_array($keywords, $searchstrings['fire']){
//redirect to fire page
}
elseif(in_array($keywords, $searchstrings['water']){
//redirect to water page
}
else{
//default
}
?>
$referer = $_SERVER['HTTP_REFERER'];
$searchstrings = array
(
'fire' => array // $searchstrings['fire']
(
'fire',
'hot',
'lava',
),
'water' => array // $searchstrings['water']
(
'water',
'liquid',
'h20',
)
);
$result = false;
foreach ($searchstrings as $group) {
foreach ($group as $ua){
switch ($ua) {
case 'fire':
$result = 'fire';
break;
case 'water':
$result = 'water';
break;
default:
// dont know if you want something in here
break;
}
}
}
//////////////////////// or even - ///////////////////////////
$result = $ua;
// Redirect
switch ($result) {
case 'fire':
header("Location: http://www.example.com/redirect.php?lookingfor=fire");
break;
case 'water':
header("Location: http://www.example.com/redirect.php?lookingfor=water");
break;
default:
// go back
break;
}
////////////////////// or even - /////////////////////////////
header("Location: http://www.example.com/redirect.php?lookingfor=$result");
?>
foreach ($searchstrings as $groupname => $group) {
Complete code:
<?php
$referer = $_SERVER['HTTP_REFERER'];
$searchstrings = array
(
'fire' => array // $searchstrings['fire']
( 'fire', 'hot', 'lava', ),
'water' => array // $searchstrings['water']
( 'water', 'liquid', 'h20', )
);
$lookingfor = false;
$foundwith = false;
if ($referer!= '') {
foreach ($searchstrings as $groupname => $group) {
foreach ($group as $ua){
if (stristr($referer,$ua)) {
$lookingfor = $groupname;
$foundwith = $ua;
break 2;
} } } }
// Redirect
// if ($lookingfor!= false) { header("Location: http://www.example.com/redirect.php?lookingfor=".$lookingfor); }
?>