Page 2 of 2 FirstFirst 12
Results 31 to 47 of 47

Thread: Auto-detecting PC/Mobile and then Redirecting

  1. #31
    New Member
    Join Date
    Feb 2010
    Posts
    5

    Default I too am having that same problem

    Seems no matter HOW I implement the code or the value for:

    header(’Location: / mysite / mobile); <This is line 39 referenced below
    } else {
    header(’Location: / mysite / pc);


    I receive the following error message:

    Parse error: syntax error, unexpected ':' in / home / customwo / public_html / index.php on line 39 (when accessing the page)

    I have tried it with the full URL, including the "w w w" "h t t p://" "mysite..." etc (can't post links as I am a first time poster)
    Without it, and all possible variations of it... seems to REALLY not like the ":" for some reason.

    For the "index.php" page that we create from the code provided at the VERY first of this post, do there need to be ANYTHING else on that page, or JUST the provided cose ? I am not a php guy so I am really not sure.. (meaning the <html> or <head> or <body> tags or anything else...

    I am just at a loss...

    Thanks for any assistance you can provide for this noob

  2. #32
    New Member
    Join Date
    Sep 2009
    Posts
    24

    Default

    Quote Originally Posted by claydaddy64 View Post
    Seems no matter HOW I implement the code or the value for:

    header(’Location: / mysite / mobile); <This is line 39 referenced below
    } else {
    header(’Location: / mysite / pc);


    I receive the following error message:

    Parse error: syntax error, unexpected ':' in / home / customwo / public_html / index.php on line 39 (when accessing the page)
    Did you really used this character : ´ ?

    This is not a valid way to enclose a string in PHP, use a single quote like this: ' !

    For example:

    header('Location: http://mysite/mobile');

    Don't forget to mark the end of the string with another ' , see http://php.net/manual/en/language.types.string.php

  3. #33
    New Member
    Join Date
    Feb 2010
    Posts
    5

    Default

    I could only type what I could becuase I am a first time poster. Therefore I am not allowed to create LINKS....

    I have no idea what you are saying though...

    the reference was to the ':' : symbol...

    as in if you go to the page where I have this set up... of which I will have to type out the URL with spaces so I can post... (please remove spaces to see the link) www . customwoodbox . com you will see the error I am getting.

    I am not stupid, I just don't understand this stuff and ya'll programmer types don't make stuff real clear.

    I was TRYING to copy and paste the code from the ORIGINAL post.. this forum would not LET me post that.

    PLEASE look at what I am getting and advise, without saying something demeaning like "did you really use this character?" I am trying... honestly... but the thing is NOT working the way it is posted... at least I can't get it to and I don't seem to be the only one here with the same problem.

  4. #34
    New Member
    Join Date
    Feb 2010
    Posts
    5

    Default here is what I have...

    Again, Cannot post "links" due to this being only my 3rd post and the forum requires me to have 10 to do so, so there are spaces... Anywhere you see a space that there should NOT be one, assume there is not...

    if($mobile_browser>0){
    header(’Location: http : // www . customwoodbox . com / mobile ');
    } else {
    header(’Location: : http : // www . customwoodbox . com / pc ');
    }

    With the line of the first URL being "line 39" that is where I get the error... From the site... right after the word "unexpected".... ':'

    Parse error: syntax error, unexpected ':' in / home / customwo / public _ html / index . php on line 39 (PLEASE remove all the spaces)

  5. #35
    New Member
    Join Date
    Sep 2009
    Posts
    24

    Default

    Quote Originally Posted by claydaddy64 View Post
    Again, Cannot post "links" due to this being only my 3rd post and the forum requires me to have 10 to do so, so there are spaces... Anywhere you see a space that there should NOT be one, assume there is not...

    if($mobile_browser>0){
    header(’Location: http : // www . customwoodbox . com / mobile ');
    } else {
    header(’Location: : http : // www . customwoodbox . com / pc ');
    }

    With the line of the first URL being "line 39" that is where I get the error... From the site... right after the word "unexpected".... ':'

    Parse error: syntax error, unexpected ':' in / home / customwo / public _ html / index . php on line 39 (PLEASE remove all the spaces)
    OK, I see .. just copy and paste, sorry for that programmer slang ...

    It is not my script in the first post, but this should work:

    Code:
    if($mobile_browser>0){
       header('Location: http://www.customwoodbox.com/mobile');
    } else {
       header('Location: http://www.customwoodbox.com/pc');
    }

  6. #36
    New Member
    Join Date
    Feb 2010
    Posts
    5

    Default no worries... just frustrated on this end...

    Unfortunately, THAT is exactly what I have in there... word for word, dot for dot, exactly to a tee... and you saw the error message I was getting... It simply does not seem to like the " : " sign... I am befuddled...

  7. #37
    New Member
    Join Date
    Feb 2010
    Posts
    5

    Default

    in spite of the EXTRA : : on the second line... that was a typo on my part but is NOT in the code on the page...

  8. #38
    New Member
    Join Date
    Sep 2009
    Posts
    24

    Default

    Hm, looks like there is something wrong before line 39. Maybe there is already a string token open.

    Please PM me everything inside index.php and I'll have a look.

  9. #39
    New Member
    Join Date
    Sep 2009
    Posts
    24

    Default

    Quote Originally Posted by dakna View Post
    Hm, looks like there is something wrong before line 39. Maybe there is already a string token open.

    Please PM me everything inside index.php and I'll have a look.
    I had a look, and there were wrong quotes in the script. But it was not the fault of claydaddy64, because it is wrong in the original code in first post. I notified Andres about that, I guess he will change it when he's got some time...
    Last edited by dakna; 02-05-2010 at 09:01 AM.

  10. #40
    New Member
    Join Date
    Jan 2010
    Posts
    2

    Default

    finally got it working great programing works perfectly BUT! one little problem. the company I work for use windows server 2003 they are using IE 5 it cannot get past the new index.php any Ideas

  11. #41
    First time poster!
    Join Date
    Mar 2010
    Posts
    1

    Default "Pretty" URL?

    Hello,
    First off I want to say thank you for this, it works wonders.

    I'm not having any problems with using this, but I do have one question.
    What this does is if you are using a PC it goes to mywebsite.com/home.html and if you are using a mobile device it sends you to m.mywebsite.com.

    Is there a way to make it so if it detects you are on a PC then it will show in the URL box or stay on "mywebsite.com" and if it detects a mobile device it will show "m.mywebsite.com" in the URL box. I know that this is nit picking and not really necessary but I would really like it if my URL on the PC is "pretty" and not have a /home.html or something along those lines.

    thank you for your help.
    -tim
    ______________________________________________
    Edit -
    If anyone is interested here is how to do what I'm talking about:

    Code:
    <?php
     
    $mobile_browser = '0';
     
    if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
    $mobile_browser++;
    }
     
    if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) {
    $mobile_browser++;
    } 
     
    $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
    $mobile_agents = array(
    'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
    'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
    'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
    'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
    'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
    'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
    'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
    'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
    'wapr','webc','winw','winw','xda','xda-');
     
    if(in_array($mobile_ua,$mobile_agents)) {
    $mobile_browser++;
    }
     
    if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) {
    $mobile_browser++;
    }
     
    if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
    $mobile_browser=0;
    }
     
    else {
    if($mobile_browser>0) {
        header("Location:  YOURWEBSITEHERE"); /* Redirect browser */
        exit;  /* Make sure that code below does not get executed after redirect. */
    } 
    } 
     
    ?>
    Last edited by JoblessPunk; 03-16-2010 at 12:25 AM.

  12. #42
    First time poster!
    Join Date
    Sep 2010
    Posts
    1

    Default

    Thanks, this is exactly the solution i was looking for. Hope it works for Drupal and Joomla.

  13. #43
    First time poster!
    Join Date
    Oct 2011
    Posts
    1

    Default force regular page

    This is neat code and works great. What if someone wants to view the normal page on their phone?

  14. #44
    MobiEnthusiast coast's Avatar
    Join Date
    Jul 2007
    Posts
    4,720

    Default

    Quote Originally Posted by dkerlee View Post
    This is neat code and works great. What if someone wants to view the normal page on their phone?
    It's manual but it works: Put a link to the full version of the site in the footer (or header)
    Need a developer? MobileSiteStore.com | More good stuff at Drosty.com
    Accepting Quality guest posts via PM only for mobiEnthusiast.mobi
    (NO press releases or story ideas, completed, unique articles only
    )

  15. #45
    First time poster!
    Join Date
    Oct 2011
    Location
    Cambodia
    Posts
    1

    Thumbs up This code is work fine

    Hi thanks for this code it work find for me. but my problem is problem is how can we return to PC when we are in Mobile.

    EX:

    <a href="#">View Mobile Site</a>
    <a href="#">View Full Site</a>

    Thanks in advance for help.

    Regards,

    Andy

  16. #46
    First time poster!
    Join Date
    Dec 2011
    Posts
    1

    Default want to show different css

    i want to show different css to mobile and pc user how it possible??
    dont tellme that it is not done .
    bcz its ake by some guys

  17. #47
    First time poster!
    Join Date
    Feb 2012
    Posts
    1

    Default question about seo

    i have a question:
    This code isaffect SEO, isn't it? and how?



Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
A Yup.mobi Mobile Site
Mobile Dating