page load

Discussion in 'PHP' started by roice, Jul 19, 2010.

  1. #1
    Hello,
    I built PHP function that recognize if the user OS is mobile or regular computer. if its mobile the script will redirect the user to the site mobile version. the problem is that the site first got loaded and than after it finish it redirect the user to the mobile version.
    How can I set it so my PHP function will load first?

    Thank you in advance,
    Roi.
     
    roice, Jul 19, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Just add the following to the start of your script/site (within a global file - so it applies to all), and if its a mobile it would redirect to the mobile version, if its not it won't:

    <?php
    //detect_mobile() should be your function which should return true if mobile...
    if (detect_mobile()) {
    header("Location: /mobile");
    }
    ?>
    PHP:
     
    danx10, Jul 19, 2010 IP
  3. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, I'll try that
    is the code is the same for ASP?
     
    roice, Jul 19, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    I'd assume it would be similar, but never worked with ASP so can't be certain.

    But let me know how the PHP code goes...
     
    danx10, Jul 20, 2010 IP