Need help for redirect by sub-ID with PHP and SQL

Code:
Header('Location: http://mysite.com/'.$subid)
?
 
How many SubIDs do you have?
strpos() will probably be faster than preg_match();
 
Maybe you can use something like this?

PHP:
<?php
$subid1 = 'http://example.com/1';
$subid2 = 'http://example.com/2';
$subid3 = 'http://example.com/3';

$subid = $_GET['subid'];

header('Location: ' . $$subid);
?>
 
Code:
Header('Location: http://mysite'.$subid.'.com');

This should work.
 
From the top of my head, may have errors :)

Code:
$mySid = $_GET['subid'];

$sites2sid = array (
    'http://www.siteA.com' => 'sid1',
    'http://www.siteB.com' => 'sid2'
);

if ($key = array_search($mySid, $sites2sid) ) {
    header('Location: '. $key);
}
 
I would've done it vice versa, but jazzc's solution will work.
PHP:
$subid=$_GET['subid'];
$id2site = array (
     'sid1' => 'url1',
     'sid2' => 'url2'
);
if (!empty($id2site[$subid])) {
     header('Location: '.$id2site[$subid]);
}
else{
     //do something else
}
?>
 
I don't like it when things stay open, so...:
We've done it with MySQL and a little modification of jazzc's and mine code examples. There are many sub-ids and it would have been absolutely uncomfortable to manage them inside the script.

Every example would've worked, and it's nice to see several different approaches to a solution. :)
 
Back
Top