0

I really tried searching about this in the internet but came upon diverse search results which barely specified what must be done specifficaly.

I'm now running ubuntu and php5 through nginx, amongst other things.

How is it that I can specify different layout and functionalities for mobile devices under the url "https://m. (...)"?

m for mobile (I'm aware this signature is not always used)

5
  • 2
    generally look at the browser string and then decide whether to forward to mobile or show desktop Jan 5 '15 at 13:59
  • 1
    @ratchetfreak generally, did you understand my question at all? :) Jan 5 '15 at 14:06
  • Searching with the keywords nginx and subdomain and possibly folder should set you up.
    – Allmighty
    Jan 5 '15 at 14:12
  • @Adimeus apparently those keywords don't exist (and I can't add them...) Thanks for the help anyway :) Jan 5 '15 at 14:22
  • 3
    You would probably be better off searching, or asking a question like this one about nginx, on http://serverfault.com/ instead of programmers.stackexchange.com. Good luck!
    – Allmighty
    Jan 5 '15 at 14:31
2

Firstly ensure that your view logic and domain logic are separate, you can search for "Model View Controller PHP" on Google for more information about this.

Once your view is separated from your logic it becomes a simple case of including a different view for mobile devices. There are many libraries for detecting if the client is a mobile browser such as http://mobiledetect.net/. These usually work via inspecting the User Agent string of the $_SERVER superglobal. http://php.net/manual/en/reserved.variables.server.php

Hope this helps

2

One approach is to create 2 web sites.

One's your normal everyday site: http://www.example.com

The other is a copy of the everyday site, except you modify the CSS and make whatever other changes are needed to support your mobile users. By convention, you have your server folks set that up with the address http://m.example.com.

Now for the clever bit: in your main web site, you look at the browser string that accompanies every request. If that string looks like it belongs to a mobile device, you respond to the request with a 302 Redirect (or similar - there's a lot of different ways to do this).

If you need the specifics on how to look at the browser string or do the redirect using your particular tool set, you'd be best off posting a separate question (or two) on Stackoverflow instead of here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.