Jump to content

Display only on the correct devices.


Go to solution Solved by .josh,

Recommended Posts

If you have a look at The attached picture, taken on my iPad just now you will see 3 app downloads buttons. The top One links to app.php?id=android the middle one links to app.php?id=iphone and the bottom one links to app.php?id=ipad. Obviously on this occasion only the 3rd link should be visible and the other 2hidden as I am viewing on my iPad.

 

If I was to view on my iPod touch then only the middle one should be visible.

 

My code for the index.php page in the screenshot is this:

 

<?PHP

include_once('include/connection.php');

include_once('include/article.php');

 

$category = new category;

$articles = $category->fetch_all();

 

 

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Xclo.mobi</title>

 

<link type="text/css" rel="stylesheet" href="other.css" />

<link rel="apple-touch-icon" href="homescreen.png" />

<link href="startup.png" rel="apple-touch-startup-image" />

 

<script type="text/javascript">

var bodyclass ='desktop';

if ( (navigator.userAgent.indexOf('android') != null) ) {

bodyclass = 'android';

} else if((window.navigator.userAgent.match('iphone') != null)||(window.navigator.userAgent.match('iPod') != null)) {

bodyclass = 'iphone';

} else if (window.navigator.userAgent.match('ipad') != null){

bodyclass = 'ipad';

}

window.onload = function(){

document.body.className += ' '+ bodyclass;

}

<script>

 

<script type="text/javascript">

 

var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA-34172259-1']);

_gaq.push(['_setDomainName', 'xclo.co.uk']);

_gaq.push(['_trackPageview']);

 

(function() {

var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

})();

 

</script>

 

</head>

<body>

 

<?php include_once('header.php'); ?>

 

 

<div id="content">

 

<ul class="pageitem"><li class="button android"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=android' " type="submit" /></li></ul>

 

<ul class="pageitem"><li class="button iphone"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=iphone' " type="submit" /></li></ul>

 

<ul class="pageitem"><li class="button ipad"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=ipad' " type="submit" /></li></ul>

 

 

<?php foreach ($articles as $article) { ?>

 

<ul class="pageitem"><li class="button">

<a href="list.php?id=<?php echo $article['promo_cat']; ?>">

<input type="submit" name="Submit" value="<?php echo $article['promo_cat']; ?>"/>

</a></li></ul>

<?php } ?>

 

 

 

 

</div>

<br><center>

<SCRIPT charset="utf-8" type="text/javascript" src="http://ws-eu.amazon-...d9-6cf16307e855"> </SCRIPT> <NOSCRIPT><A HREF="http://ws-eu.amazon-...t">Amazon.co.uk Widgets</A></NOSCRIPT></center>

 

<?php include_once('footer.php'); ?>

 

 

</body>

</html>

Any ideas on how to get this to work please. Thank you.

post-164054-0-25974900-1378298195_thumb.jpg

Link to comment
https://forums.phpfreaks.com/topic/281845-display-only-on-the-correct-devices/
Share on other sites

  • Solution

<?php
$ua=$_SERVER['HTTP_USER_AGENT'];
switch(true) {
case stripos($ua,'android') :
$device = 'android'; break;
case stripos($ua,'ipad') :
$device = 'ipad'; break;
case stripos($ua,'iphone') :
$device = 'iphone'; break;
}
?>
<ul class="pageitem"><li class="button android"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=<?php echo $device; ?>' " type="submit" /></li></ul>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.