views:

784

answers:

5

Suppose I have developed one web portal in PHP/MySQL. I want to make it work in mobile also. What is the easiest way to do this?

Can we use PHP with any mobile based mark up languages like WML or XHTML i.e. as we can use PHP with HTML in web applications used to view in normal web browsers?

+1  A: 

Pseudo-code for each page, (or just the template page, if you have that)

<?php if(mobile()): ?>

   Mobile HTML and PHP
<?php else: ?>

   Desktop HTML and PHP

<?php endif; ?>

I use this.

Time Machine
is there a way that mobile() distinguishes between older wap phones and newer ones?
dassouki
you must write that function yourself
Time Machine
+1  A: 

Depends on what you understand under the term "mobile". Basically it would just mean to adapt your portal displayed data and css to the smaller display sizes and make as ZOMFG said an if statement to output your source accordingly. If you want to enable WAP browsing you have to output your data in the Wireless markup language.

Daff
+4  A: 

PHP has nothing to do directly with the platform you want to display your app on. PHP is just the tool to deliver the kind of markup you need for your page to be displayed on whatever platform you want. It's up to your own knowledge and creativity to render markup which suits your needs. So in other words, yes of course you can send WML, XML, XHTML, you name it to the client!

The client doesn't know anything about PHP anyways (PHP 'exists' only on the server side), the client doesn't understand PHP and doesn't need to. It understands XHTML or any other markup and that's what you have to deliver! What tool you use to do that is completely up to you. PHP is one option.

So all you need to know is for what platform/client you want to render your content and what kind of markup this platform understands and then deliver the right markup to the right platform/client including the respective CSS, js, etc.

What your app does:

  1. detect what client is requesting your site
  2. see if you're able to send the appropriate markup
  3. send this markup or if not available some default or similar markup
tharkun
+1  A: 

PHP is just a tool which generates some markup language (or anything else, actually, which might not be markup-oriented at all) that is understood by the client -- the browser.

Your PHP code will have to be able to generate two kind of different outputs :

  • a "full ouput" (likely HTML), which you already have, for computer web browsers
  • a "light ouput" (maye VML, maybe HTML too but without some heavy stuff), for mobile-based browsers.

The task you'll have to deal with is to differenciate between mobile and non-mobile users ; this might be done by user-agent sniffing, for instance, or detecting what the client requested.

A nice thing to do could be to use a special domain-name for users of mobile platforms ; something like mobile.example.com ; for instance, so they can bookmark it and directly access the "mobile-version" of your site -- can be useful if your detection doesn't work well ^^


If you are targetting advanced-mobile-machines (like iPhone) which have a not too bad browser, you might want to send them "rich" HTML pages ; just test your pages to verify they fit on the small screen of theses machines ; and, maybe you'll want to send less data (like not display some sidebars, or have a smaller menu, ... )

BTW, what kind of platform do you mean by "mobile" ? Those old phones with small screens, or more power-users-oriented phones, like iPhone / Android / stuff like that ?
This could make quite a difference, actually, as the more recent ones have nice functionnalities that the oldest didn't have ^^


In any case, one important thing to remember :

  • you will spend some time making the site work on these devices
  • you will have to spend more time maintaining it !

Which means : do something simple, and, as much as possible, use the same PHP code for both mobile and non-mobile version of the site : the less code you duplicate, the less code you'll have to maintain !

Hope these few ideas (not really well sorted, I admit) will help...
Have fun !

Pascal MARTIN
+1  A: 

Already the mobile browsers support almost full XTHML, Javascript, Flash.

My recommandations are:

  • have a light css for the mobile version
  • restrict some heavy functionalities
  • validate your code
  • optimize, optimize, optimize, although this works even for the full version.
Elzo Valugi