0

Let's see if I can explain this and make sense at the same time... I've a website and a mobile app for that website. In some cases I'll use the view on the website in the app. I wont redirect the user to the website, but the website view will display in the application. But in this view I'll also make some changes. Lika media queries but at the same time not, because it the user is using a mobile but not the app, a the website will show as normal, but responsive of course.

UPDATE (trying to explain a bit better) If you use the mobile app, only a specific part of the website will be shown. In this case it will be product categories. Header, footer and all the other content will be gone except for the product categories. If you use the mobile and for example safari, the header, footer and all that stuff will be shown.

So the question here is how can I check, with using PHP, if the user is coming from a mobile app and thereafter display a certain view?

teninchhero
  • 153
  • 16

3 Answers3

0

You could have the mobile application open up the website with a GET variable set. Example would be the mobile app would open up www.myWebsite.com?source=mobile.

This way when the php is run on the page you can have something like:

if ((isset($_GET['source'])) && ($_GET['source'] == 'mobile'))
    {
    //This is a mobile view!
    }

A downfall to this would be that anyone could just type ?source=mobile to trick the browser into thinking it's coming from the app.

DanielRead
  • 2,288
  • 1
  • 23
  • 34
  • The thing is that if you don't use the mobile app but still the mobile, there's just going to be the website displaying with responsive design – teninchhero Oct 13 '15 at 07:24
  • So you want this 'view' to show if someone comes to your page from a mobile device in general. Whether that be from your app or through the mobile web browser. Check out this thread: http://stackoverflow.com/questions/14646918/get-specific-device-information – DanielRead Oct 13 '15 at 07:28
  • No, I want this 'view' to show if you using a mobile app from a mobile device. If you just use your mobile device, and for example safari, the 'view' will be like the website on the computer but responsive. If the user is using the mobile app, they shouldn't even notice that I redirected them to a website view. I updated my question, trying to explain it better. – teninchhero Oct 13 '15 at 07:38
  • Okay now we're just going in circles... My original answer still holds then. When you display the website in app make sure the URL you are displaying has a GET variable in it. This way you can customize what is shown based on if that variable is set or not. If it is not set just have it show the regular website with a responsive layout. This would make it so when the website is viewed through the app you get the app view, but when viewed through the Safari browser on an iPhone you get the normal website with the responsive layout. – DanielRead Oct 13 '15 at 07:46
  • Reread your answer and I get it now! Will give it a try! Thanks. – teninchhero Oct 13 '15 at 07:49
0

If you use third party mobile application you can try figure out the source of the request by HTTP User-Agent. Usually issues about views solving by CSS with @media rules. I hope I got your problem.

karma_police
  • 332
  • 2
  • 14
  • Not familiar with HTTP User-Agent but it sounds like something that could work. Any good example on how to use it and do I use media rules in a specific way thereafter? – teninchhero Oct 13 '15 at 07:29
  • I found a nice [thread](http://stackoverflow.com/questions/1005153/auto-detect-mobile-browser-via-user-agent) with similar issue – karma_police Oct 13 '15 at 07:36
  • But I need to know if the user is coming from a mobile application and not a mobile device.. – teninchhero Oct 13 '15 at 07:42
0

You can check by user agents. Using _SERVER['HTTP_USER_AGENT'];

Or else you can use 3rd party libraries like

http://mobiledetect.net or you can use bootstrap library for do that.

If you want to do different design for mobile and desktop then I prefer to you to use bootstrap library.

Jitendra Kumar. Balla
  • 1,173
  • 1
  • 9
  • 15