1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'PHP & Perl' started by darkstar69, Mar 12, 2012.

  1. darkstar69

    darkstar69 Jr. VIP Jr. VIP

    Joined:
    Nov 15, 2008
    Messages:
    806
    Likes Received:
    880
    Occupation:
    Big Boss
    Location:
    On The Dark Side
     
  2. Xp3r7

    Xp3r7 Regular Member

    Joined:
    Sep 9, 2011
    Messages:
    286
    Likes Received:
    386
    Occupation:
    Freelancer
    Location:
    In the middle of nowhere
    Code:
    Header('Location: http://mysite.com/'.$subid)
    ?
     
  3. 45415

    45415 Junior Member

    Joined:
    Feb 5, 2009
    Messages:
    194
    Likes Received:
    92
    How many SubIDs do you have?
    strpos() will probably be faster than preg_match();
     
  4. darkstar69

    darkstar69 Jr. VIP Jr. VIP

    Joined:
    Nov 15, 2008
    Messages:
    806
    Likes Received:
    880
    Occupation:
    Big Boss
    Location:
    On The Dark Side
     
  5. 45415

    45415 Junior Member

    Joined:
    Feb 5, 2009
    Messages:
    194
    Likes Received:
    92
    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);
    ?>
     
  6. Xp3r7

    Xp3r7 Regular Member

    Joined:
    Sep 9, 2011
    Messages:
    286
    Likes Received:
    386
    Occupation:
    Freelancer
    Location:
    In the middle of nowhere
    Code:
    Header('Location: http://mysite'.$subid.'.com');
    This should work.
     
    • Thanks Thanks x 1
  7. darkstar69

    darkstar69 Jr. VIP Jr. VIP

    Joined:
    Nov 15, 2008
    Messages:
    806
    Likes Received:
    880
    Occupation:
    Big Boss
    Location:
    On The Dark Side
     
  8. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,642
    Likes Received:
    11,376
    Occupation:
    Pusillanimous Knitter
    Location:
    Buenos Aires
    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);
    }
    
     
    • Thanks Thanks x 1
  9. 45415

    45415 Junior Member

    Joined:
    Feb 5, 2009
    Messages:
    194
    Likes Received:
    92
     
    • Thanks Thanks x 1
  10. darkstar69

    darkstar69 Jr. VIP Jr. VIP

    Joined:
    Nov 15, 2008
    Messages:
    806
    Likes Received:
    880
    Occupation:
    Big Boss
    Location:
    On The Dark Side
     
    Last edited: Mar 12, 2012
  11. tripper_john_md

    tripper_john_md Newbie

    Joined:
    Feb 21, 2011
    Messages:
    40
    Likes Received:
    35
    Location:
    Southern Germany
    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
    }
    ?>
     
    • Thanks Thanks x 2
  12. darkstar69

    darkstar69 Jr. VIP Jr. VIP

    Joined:
    Nov 15, 2008
    Messages:
    806
    Likes Received:
    880
    Occupation:
    Big Boss
    Location:
    On The Dark Side
     
  13. tripper_john_md

    tripper_john_md Newbie

    Joined:
    Feb 21, 2011
    Messages:
    40
    Likes Received:
    35
    Location:
    Southern Germany
    I've skype, just pm me your name ;)
     
  14. tripper_john_md

    tripper_john_md Newbie

    Joined:
    Feb 21, 2011
    Messages:
    40
    Likes Received:
    35
    Location:
    Southern Germany
    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. :)
     
    • Thanks Thanks x 2