PHP code for redirect on blackberry--HELP!

Discussion in 'PHP' started by nexgraphics, May 22, 2010.

  1. #1
    Hi, I designed a web site for a client, and I got thisredirect script to work on IPHONE, but it doesnt work on blackberry at all, even if I replace the 'iphone' with 'blackberry'.

    Any help GREATLY appreciated! Cant get this thing to work!


    <?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE)
    { header('Location: http://www.israla.com/mobile/index.php'); }
    ?>
     
    nexgraphics, May 22, 2010 IP
  2. n3r0x

    n3r0x Well-Known Member

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    120
    #2
    run a test and log the useragent blackberry sends..

    
    <?php
    
    echo $_SERVER['HTTP_USER_AGENT'].'<br />';
    $x = file_put_contents("blackberry_user_agent.txt",$_SERVER['HTTP_USER_AGENT']);
    if($x > 0) {
       echo 'user_agent written to file';
    } else {
       echo 'Could not write user_agent to file';
    }
    ?>
    
    PHP:
    save that and browse it with a blackberry..
     
    n3r0x, May 23, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    <?php
    
    //array of cellphone names
    $cellphone_names = array('iphone', 'blackberry', 'nokia');
    
    $escaped = array_map('preg_quote', $cellphone_names);
    
    if (preg_match('~\b('.implode("|", $escaped).')\b~i', $_SERVER['HTTP_USER_AGENT'])) {
    //redirect to mobile version...
    header("location: http://{$_SERVER['HTTP_HOST']}/mobile");
    }
    ?> 
    PHP:
     
    danx10, May 23, 2010 IP
  4. realturk

    realturk Active Member

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #4
    hello all;
    once class...
    browse.php
    http://www.mavrick.id.au/browser-v1-6.zip
    PHP:
    
    <?php
    include 'browser.php'; // browser class
    $browser = new Browser();
    if( $browser->getBrowser() == Browser::PLATFORM_BLACKBERRY && $browser->getVersion() >= 2 ) {
    header ("Location: http://www.israla.com/mobile/index.php");
    die;
    exit();
    }
    ?>
    
    PHP:
    good bye...
     
    realturk, May 23, 2010 IP