473,889 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to detect if mobile phone is viewing php page or PC

3 New Member
PHP version 4.027
I want to change between style sheets when page is viewed on a mobile phone or a PC.

The pages looks fine on both when I manually set a key in the script.
My problem is how to determine if its viewed on a phone or PC.

I have used $_SERVER['HTTP_USER_AGEN T']; to show the browser details
RESULTS from php pages.

HTC Mobile phone;
HTC_Pro_T7272 Opera/9.50 (windows NT5.1;U; en)

My PC;
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)

I'm not sure how to tell from these results what is what.
I can see I can pick out the HTC_Pro string to set my key, but that would not be there on a different make of phone.
If phone or PC cannot be determined from $_SERVER['HTTP_USER_AGEN T']; have you any idea how.

Thanks in advance, Barry.
Oct 31 '08 #1
8 12632
Tarantulus
114 New Member
User agent is the correct way, but as there are so many moble browsers you would need to account for them all (or as many as is feasible)

http://www.zytrax.com/tech/web/mobile_ids.html is a good start
Oct 31 '08 #2
Markus
6,050 Recognized Expert Expert
The user agent shouldn't be trusted, though, as it can be faked.
Oct 31 '08 #3
nathj
938 Recognized Expert Contributor
Why bother?

Can't you simply link in a media type specific style sheet?

CSS Media Type

so you can either have a separate complete style sheet or you can have multiple style sheets -

1. layout.css media="all" that defines layout in percentages
2. Screen.css media ="screen" that defines things for screens
3. handheld.css media ="handheld" that defines mobile styles
4. print.css media = "print" that defines printing
5. color.css media="all" that defines you general color scheme

That's pretty much what I do, there are loads of tutorials around and about on this, check out A List Apart for further ideas.

This way there is no need for browser detection which, as posted above, is unreliable.

Cheers
nathj
Oct 31 '08 #4
barrybee
3 New Member
Hi, thanks for the very speedy replies.
I have read a lot on the web and in some books and they do seem suggest that media types could be what I need, but nothing I have tried seems to work. I can still get the correct appearance of my target page when viewed on a phone or a PC but only if I change to the correct style sheet manually.

Natj, I just love it when someone says, 'Can't you simply link in a media type specific style sheet?'. I think thats what I'm trying to do, but I don't know how. Could you please show me how?

Thanks; Barry.
Nov 3 '08 #5
nathj
938 Recognized Expert Contributor
Hi Barry,

In the head section of your document you need to put:

Expand|Select|Wrap|Line Numbers
  1. <link rel="stylesheet" href="../css/layout.css" type="text/css" media="all"/>
  2. <link rel="stylesheet" href="../css/colour.css" type="text/css" media="all" />
  3. <link rel="stylesheet" href="../css/print.css" type="text/css" media="print" />
  4.  
When linking style sheets like this the order is important. So in this case the main layout comes first, then colour is added and finally an alternative is given. The use of media type 'all' ensures that the main styles are available to all devices but these can then be overwritten in the specific using display:none.

A great example is the menu - this is needed in the main layout and any other non-printed layouts but not in the print layout so you simply add the definition of display; none to the element in the print style sheet.

I hope that makes sense

nathj
Nov 3 '08 #6
ak1dnar
1,584 Recognized Expert Top Contributor
If you still looking for script to detect the device, WURFL PHP Library is the best solution for you. wurfl contains information about capabilities and features of many mobile devices.

Basically it's good to create a separate mobile friendly web site for the home web.
home web site: http://domain.com
mobile version: http://mobile.domain.c om or even now http://domain.mobi extension is there for mobiles.

Try the wurfl and redirect mobile/hand held devices to the mobile version.
Nov 3 '08 #7
barrybee
3 New Member
Hi Nathj
Thanks, thats sort of what I've been trying but the order might not have been right.
Thanks again I will try again tomorrow.
Barry
Nov 3 '08 #8
kyleyoung
1 New Member
Another method you may want to consider is just serving up an alternative site or CSS based on the detected screen resolution. For example:

Expand|Select|Wrap|Line Numbers
  1. function detectRes() {
  2. if (screen.width < 400) location.replace('http://mobile.epiphanet.com');
  3. }
  4.  
or for CSS based...
Expand|Select|Wrap|Line Numbers
  1. if (screen.width < 400) {
  2. document.write('<link rel="stylesheet" href="mobile.css" type="text/css" media="all"/>');
  3. } else {
  4. document.write('<link rel="stylesheet" href="layout.css" type="text/css" media="all"/>');
  5. }
  6.  
This way always made sense to me. The reason we are building an alternative view in the first place is because the device uses a lower resolution.

Kyle Robinson Young
<link removed>.
Sep 3 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4800
by: Mario | last post by:
Hello, Excuse me if I am not so clear on what I a looking for, but its getting very hard to find any software,application or information that will let me access or get a frame(still image) from a web cam or ip cam. I have different ip cams connected to the internet, they continuously send images refreshed over the internet.
3
9149
by: Sara | last post by:
HI, I want to code a program to detect GSM mobile (any kind) which connected through serial port to computer and then be able to send SMS through this mobile phone to other mobile phones, could anyone help me and guide me, I wrote a program which could open COM port but still couldn't detect mobile phone and send SMS through it. I searched internet and I didn't find right answer to my question. please if anyone could guide me. the...
4
7016
by: Sara | last post by:
Hi I want to code a program which could send SMS through web page to mobile phone, but because there is no Service here such as SMPP , therefore I have GSM mobile phone which connected directly to the server which run these aspx pages. now my question is 1- how to detect this mobile phone which connected through serial ports 2- how I could send SMS through this mobile to other mobile devices, if anyone has any suggestion please help me
4
1874
by: InnoCreate | last post by:
Hi everyone, I've developed a couple of asp.net1.1 websites and these are viewable using my mobile phone. I've now moved over to asp.net2 and i'm unable to view asp.net2 websites on my phone. I've stripped a page down to only output HTML4.01 and a single line of text with no formatting and it's still not viewable. Can anyone help me - i don't want to develop a asp.net2 mobile website - i want to develop a standard asp.net2 website that...
6
1694
by: psylencer | last post by:
Hi guys, I'm working on my first ASP web site. The idea of the site is to calculate which mobile phone plan is right for you. The idea is that the user answers a few questions about their calling habits, and the server calculates the ammount of talk time for each plan and then recommends on or two. I've created 2 excell sheets already. One is a user input sheet, the other is a database of all the plans available.
0
1424
by: PEO from ITALY | last post by:
How to detect where is a mobile phone? It's very simple: just clic the link, insert the mobile phone number and press the key "Localizzare". In few seconds you will know where is your wife / husband / friend / sister / son / boss... http://www.studiopasquali.it/satphone/index.htm Attention: sometimes it's better don't know...
4
2292
by: Sjef | last post by:
Is there information available about testing webpages on a mobile phone? Is there a test application? I searched on google but didn't find anything Thanxs, Sjef
3
2248
by: ajtrichards | last post by:
I have a web application that uses $_SESSION; to see if the session is logged in. Everything works fine when using an internet browser (Firefox, IE, Flock, Safari) but when I try to access the page on my mobile phone (Blackberry Curve) it doesn't register the session. Can anyone explain this??? Regards,
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11186
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7991
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5825
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6015
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.