Jump to content

Display only on the correct devices.


KevHopwood

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


<?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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.