please help redirect

Started on the old forum in May 2014 · view the original in the archive · old links redirect here

4 replies · 181 views · started 12 years ago · 1 min read

4 participants
jsyguy23 Developer · 134 posts #1

does anyone please have a code that would pick up touch phones if they in use, im building a script and one side of it im doing a touch verson but need to redirect a touch phone to the right side if anyone could help, please do, many thanks.

$http=$_SERVER['HTTP_USER_AGENT']; if((substr($http,0,5)=='Opera' and !strpos($http,'Mini')) or substr($http,0,7)=='Mozilla' or substr($http,0,6)=='Galaxy' or substr($http,0,12)=='AmigaVoyager' or substr($http,0,8)=='CyberDog' or substr($http,0,5)=='Dillo' or substr($http,0,7)=='HotJava' or substr($http,0,15)=='IBM WebExplorer' or substr($http,0,4)=='iCab' or substr($http,0,10)=='LeechCraft' or substr($http,0,5)=='Links' or substr($http,0,4)=='Lynx' or substr($http,0,11)=='NCSA Mosaic' or substr($http,0,7)=='NCSA Mosaic' or substr($http,0,6)=='retawq' or substr($http,0,6)=='Webkit' or substr($http,0,4)=='Uzbl' or substr($http,0,3)=='w3m' or substr($http,0,12)=='WorldWideweb') { header("Location: http://$_SERVER[SERVER_NAME]/index.php"); normal web side }else{ header("Location: http://$_SERVER[SERVER_NAME]/touch/index.html"); ///touch side }

this does work but it pick's up phones and pc's

something else Fellow · 2,296 posts #2

Detecting touch screen by php is kind of long winded way of doing it as you would have to get so many browser names >.< I would suggest doing it via javascript eg:

<script type="text/javascript">

function is_touch_device() {
 return (('ontouchstart' in window)
      || (navigator.MaxTouchPoints > 0)
      || (navigator.msMaxTouchPoints > 0));
}
 
if (is_touch_device()) {
 window.location='http://<?=$_SERVER[SERVER_NAME]?>/touch/index.html';
}

if the device has no javascript then it will ignore the code.

jsyguy23 Developer · 134 posts #3

thanks m8 nice one 😉

giant_hacker Junior · 11 posts #4

something else wrote: Detecting touch screen by php is kind of long winded way of doing it as you would have to get so many browser names >.< I would suggest doing it via javascript eg:

<script type="text/javascript">

function is_touch_device() {
return (('ontouchstart' in window)
|| (navigator.MaxTouchPoints > 0)
|| (navigator.msMaxTouchPoints > 0));
}

if (is_touch_device()) {
window.location='http://<?=$_SERVER[SERVER_NAME]?>/touch/index.html';
}

if the device has no javascript then it will ignore the code.

Now This will not work on many phones Specially if you use ucweb browser/operamini/etc etc on yout touch phones except default browsers

jsyguy23 Developer · 134 posts #5

what do you recommend m8 ??

something else Fellow · 2,296 posts #6

giant_hacker wrote: Now This will not work on many phones Specially if you use ucweb browser/operamini/etc etc on yout touch phones except default browsers

Its pointless redirecting opera mini and ucweb to a better site - they will get there and still not be able to use most of the stuff you have put time into coding. if someone is willing to downgrade there web experience to ucweb or opera mini then give them a downgraded site. No point in trying to give them anything else

jsyguy23 Developer · 134 posts #7

same way i was thinking

wapxtech Developer · 189 posts #8

agree with giant_hacker, what if your browser doesn't support java (old phones) javascript will not do so, I'm thinking of redirecting android phones and IOS =) they are the most touchscreen devices, IOS have a keyword apple or safari in their user-agent while android is too common, you don't need to pick all those browsers, just pick the most common like android and IOS, the above code will do

compatibility is your site's asset so don't just disregard it =) more compatible browser more users

External image (may be gone) http://wapx.amob.com Applications, Games, Wallpapers, Ringtones, Videos, Themes, Screensaver and More!!!

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close