Advertisement
shaashwato1308

PHP - Set desktop/mobile in cookie and show that web version

Jan 12th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.55 KB | None | 0 0
  1. <html>
  2. <head>
  3.     <script type="text/javascript">
  4.         var getCookies = '';
  5.         function desktopselected(){
  6.             //alert('desktop selected');
  7.             setCookie('faversion', 'desktop', 1);
  8.             //alert('DESKTOP SET');
  9.             location.reload();
  10.         }
  11.         function mobileselected(){
  12.             //alert('mobile selected');
  13.             setCookie('faversion', 'mobile', 1);
  14.             //alert('MOBILE SET');
  15.             location.reload();
  16.         }
  17.         function listCookies() {
  18.             var theCookies = document.cookie.split(';');
  19.             var aString = '';
  20.             for (var i = 1 ; i <= theCookies.length; i++) {
  21.                 aString += i + ' ' + theCookies[i-1] + "\n";
  22.             }
  23.             return aString;
  24.         }
  25.         function getCookie(cname) {
  26.             var name = cname + "=";
  27.             var ca = document.cookie.split(';');
  28.             for(var i=0; i<ca.length; i++) {
  29.                 var c = ca[i];
  30.                 while (c.charAt(0)==' ') c = c.substring(1);
  31.                 if (c.indexOf(name) == 0) {
  32.                     return c.substring(name.length, c.length);
  33.                 }
  34.             }
  35.             return "";
  36.         }
  37.         function setCookie(cname, cvalue, exdays) {
  38.             var d = new Date();
  39.             d.setTime(d.getTime() + (exdays*24*60*60*1000));
  40.             var expires = "expires="+d.toUTCString();
  41.             document.cookie = cname + "=" + cvalue + "; " + expires;
  42.         }
  43.         window.onload = function(){
  44.             //alert(listCookies());
  45.         }
  46.     </script>
  47. </head>
  48. <body>
  49.     <?php
  50.     if($_COOKIE['faversion'] == "desktop"){
  51.         echo "TO SHOW: DESKTOP<br>";
  52.         ?>
  53.         <a href="#" onclick="mobileselected()">Mobile</a>
  54.         <?php
  55.     }else{
  56.         echo "TO SHOW: MOBILE<br>";
  57.         ?>
  58.         <a href="#" onclick="desktopselected()">Desktop</a>
  59.         <?php
  60.     }
  61.     ?>
  62.     <br>
  63. </body>
  64. <footer></footer>
  65. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement