Help with implementing a PHP script

7 replies
I was toying around the web, to find a niche for my website and I came across a website which tells your iOS version for iphone users and android version for well android users. I currently took the design and layout for the website from an existing one, but ofcourse as you know the PHP files can't be copied. If someone out there could help me set the script i'd appreciate it.
Sources:

This is my website currently:
Code:
http://myios.us/myiosversion/index.htm
The website which hosts the script:
Code:
http://whatismyandroidversion.com/
Code:
http://whatismyiosversion.com/
I would like the PHP scripts that it uses, it may be custom coded, but there are plenty of scripts similar to these out there, but somehow I can't find any.
#implementing #php #script
  • Go look in the iOS API and in the Android API for the various library functions that tell you the operating system version.

    Once you have those, the PHP scripting is very trivial.
    Signature

    Bros find strictly platonic dudes on seekBromance.com
    _______________________________________________
    "It's pretty simple. You work hard, you believe anything is possible, and you try to make the world better."

    {{ DiscussionBoard.errors[8613535].message }}
  • Profile picture of the author kellithean
    That's the problem, I'm zero at coding php files. I know how to redirect them and read general codes, only basics really.
    I did read about a few scripts but they don't fit the description of the website. If anyone out there could spend 10-15min of his time to find/code/modify existing codes for me i'd appreciate it.
    A little kindness goes a long way
    {{ DiscussionBoard.errors[8613591].message }}
    • Originally Posted by kellithean View Post

      That's the problem, I'm zero at coding php files. I know how to redirect them and read general codes, only basics really.
      If you have ever programmed in any language, PHP scripting is easy to pick up. I highly recommend creating a "sandbox" page in a protected directory on one of your accounts and practicing your PHP there. It pays to get comfortable with the language.
      Signature

      Bros find strictly platonic dudes on seekBromance.com
      _______________________________________________
      "It's pretty simple. You work hard, you believe anything is possible, and you try to make the world better."

      {{ DiscussionBoard.errors[8616328].message }}
  • Profile picture of the author Brandon Tanner
    Originally Posted by kellithean View Post

    there are plenty of scripts similar to these out there, but somehow I can't find any.
    If you can't find any, then how do you know there are any out there?

    All joking aside... PHP source code resides on the server, so there's no way to get at the PHP source code on someone else's site (unless of course you have admin access to their server).

    That said, it's fairly trivial to detect a visitor's browser type and version via "user agent".

    In PHP...

    <?php
    echo $_SERVER['HTTP_USER_AGENT'];
    ?>


    The user agent string contains a lot of info about the browser, so if you only want the browser version, then you'll have to extract it via regex, or the 'explode' function, etc.

    You can also detect user agent via Javascript, or most other web scripting languages. PHP is probably the most reliable way to do it though.
    Signature

    {{ DiscussionBoard.errors[8613670].message }}
  • Profile picture of the author kellithean
    Originally Posted by Brandon Tanner View Post

    If you can't find any, then how do you know there are any out there?
    here's an example of one find, it doesn't suit me because it's java:
    Code:
    function iOSversion() {
      if (/iP(hone|od|ad)/.test(navigator.platform)) {
        // supports iOS 2.0 and later: <http://bit.ly/TJjs1V>
        var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
        return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
      }
    }
    
    ver = iOSversion();
    
    if (ver[0] >= 5) {
      alert('This is running iOS 5 or later.');
    }
    All joking aside... PHP source code resides on the server, so there's no way to get at the PHP source code on someone else's site (unless of course you have admin access to their server).
    That much I've established and agree

    That said, it's fairly trivial to detect a visitor's browser type and version via "user agent".

    In PHP...

    <?php
    echo $_SERVER['HTTP_USER_AGENT'];
    ?>


    The user agent string contains a lot of info about the browser, so if you only want the browser version, then you'll have to extract it via regex, or the 'explode' function, etc.

    You can also detect user agent via Javascript, or most other web scripting languages. PHP is probably the most reliable way to do it though.
    Here's the whole code for the index of the site
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    	<meta name="description" content="Quickly check your phone or tablet's Android version and other details online" />
    	<meta name="keywords" content="android version, android, version, desktop, mobile, detect, resolution, screen size, device name, phone, tablet" />
    	<meta name="viewport" content="width=480, maximum-scale=1" />
    
    <meta property="og:title" content="Check your phone or tablet's version and screen resolution online" />
    <meta property="og:site_name" content="What is my Android version?" />
    <meta property="og:type" content="website" />
    <meta property="og:url" content="http://myios.us/myiosversion/index.htm.com" />
    <meta property="og:description" content="Check your phone or tablet's Android version and screen resolution" />
    <meta property="og:image" content="http://myios.us/myiosversion/index.htm.com/android-funny.jpg" />
    <meta property="fb:app_id" content="320764858034873" />
    <meta property="fb:admins" content="100001866019297" />
    
    	<meta name="hcirn-verification" content="d4f494b2497bde82aeb2fead9e4608c5" />
    	<meta name="webutation-site-verification" content="webutation127c817bcc43cdb5f446fba42b5a2db6" />
    	<meta name="norton-safeweb-site-verification" content="mqmb-9lkgj2-v-mqigjyfgzz5k9wklv9qkgar09ol92ea1zzxd3-vpwtqcdar8i7609j3smxuswd9e8tw8-hymtpcpthr725qu7m353o-iwkq6r67h2qgymy1fgz2lt4" 
    	<meta name="alexaVerifyID" content="VhqVz1OcbELMKE-4ZQtb6EteUgI" />
    	<meta name="netinsert" content="0.0.1.12.35.1">
    	<meta name="check-stats" content="58dc3db9b21728961b91-1357245471.49" />
    	<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.classify.org/safesurf/" L gen true for "http://myios.us/myiosversion/index.htm.com" r (SS~~000 1))' />
    	<meta name="cancanit-site-verification" content="056312013241101"/>
    
    <!--
    -->
    	<link rel="stylesheet" type="text/css" href="style.css" tppabs="http://myios.us/myiosversion/index.htm.com/style.css" media="screen" />
    <script type="text/javascript">
    if (window.screen.width<=480)
     document.write('<link rel="stylesheet" type="text/css" href="style-small.css"/*tpa=http://myios.us/myiosversion/index.htm.com/style-small.css*/ media="screen" />');
    </script>
    <!--
    	<title>What is my Android version? - Check your tablet or phone's Android version and screen size</title>
    -->
    	<title>What is my Android version? | Online Android version checker</title>
    </head>
    <body>	<div id="content-wrapper">
    	<div id="content">
    <!--
    		<p id="top">Duis rutrum dapibus diam. Sed turpis sem, suscipit et, ullamcorper vel, aliquam in, tellus.</p>
    <div class="g-plusone" data-size="medium" data-align="right" data-href="http://myios.us/myiosversion/index.htm.com"></div>
    -->
    		<div id="top">
    <!-- Facebook -->
    <!--
    <iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmyios.us/myiosversion/index.htm.com&amp;send=false&amp;layout=button_count&amp;width=0&amp;show_faces=false&amp;font&amp;colorscheme=light&amp;action=like&amp;height=21&amp;appId=320764858034873" 
    scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe>
    -->
    <iframe src="../www.facebook.com/plugins/fi000001." tppabs="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FWhat-is-my-Android-version%2F135961419896816%3Fbookmark_t%3Dpage&send=false&layout=button_count&width=90&show_faces=false&font&colorscheme=light&action=like&height=21&appId=320764858034873" 
    scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe>
    
    <!-- Place this tag where you want the +1 button to render. -->
    <div class="g-plusone" data-annotation="none" data-align="right" data-href="index.htm" tppabs="http://myios.us/myiosversion/index.htm.com/"></div>
    		</div>
    <!-- Place this tag after the last +1 button tag. -->
    <script type="text/javascript">
      (function() {
        var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
        po.src = '../apis.google.com/js/plusone.js'/*tpa=https://apis.google.com/js/plusone.js*/;
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
      })();
    </script>
    
    		<div id="logo">
    <!--
    			<h1><a href="index.php">distinctive</a></h1>
    -->
    			<h1><a href="index.htm" tppabs="http://myios.us/myiosversion/index.htm.com/">what is <br>my Android <br>version?</a></h1>
    		</div>
    <div id="about-results" style="width:auto; font-size:.8em; min-height:30px; margin:10px 0 8px 20px;">
    <h1 style="color:#444; font-size:1.6em; color:#283;"><b>Online Android version info</b></h1>
    <!--
    <div style="float:left;">
    <img src="info-small2a.png">
    </div>
    -->
    <div style="float:left; width:230px; margin:7px 0 0 0px; color:#126; font-size:1.05em; 
    line-height:1.22em;">
    <i>Displays the Android version, release name, device id and screen resolution of your phone or tablet.</i>
    <br>
    </div>
    </div>
    <div style="clear:both; height:0px;"></div>
    		<div class="line"></div>
    <!--
    		<ul id="menu">
    			<li class="current"><a href="/">Home</a></li>
    			<li><a href="privacy.php">Privacy</a></li>
    		</ul>
    -->
    <div style="clear:both; width:468px; height:60px; border-bottom:1px solid #ddd; margin:-15px 0 10px 0; padding-bottom:5px;">
    <script type="text/javascript"><!--
    google_ad_client = "ca-pub-8959601970688211";
    /* wimav banner1 */
    google_ad_slot = "3198882650";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript" src="../pagead2.googlesyndication.com/pagead/show_ads.js" tppabs="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    
    </div>
    		<div id="pitch">
    			<div id="robot">
    <img style="opacity: 0;position: absolute;top:0; left:-200px;" src="android-funny.jpg" tppabs="http://myios.us/myiosversion/index.htm.com/android-funny.jpg" alt="android funny">
    
    <script type="text/javascript">
    /*
    if (window.screen.width<=480) {
    } else {
    */
    icon_size='<img src="images/Android_NoRobot2_100.png"/*tpa=http://myios.us/myiosversion/index.htm.com/images/Android_NoRobot2_100.png*/ style="width:100px; height:133px;">';/*
    }
    */
    document.write(icon_size);
    </script>
    			</div>
    
    			<div id="results">
    <!--
    			<h2>Your version of Android is reported as:</h2>
    -->
    			<h2>Your version of Android is:</h2>
    			<h1>
    			Android not detected                        
    			</h1>
    			</div>
    		<div style="clear:both;"></div>
    		</div>	 <!-- end pitch div -->
    
    			<div id="about-icon">
    			<h3>Information</h3>
    			</div>
    			<div id="about-results">
    <!--
    			<h3>About these Results</h3>
    -->
    			<p>
    No Android details were reported by your web browser.<br><br>If you are using an Android device to visit this page, your browser may be in 'Desktop mode' or configured to emulate 
    a different device (using a User Agent setting).<br>			</p>
    			</div>	
    		<div style="clear:both;"></div>
    <!--
    		<div class="darkline"></div>
    -->
    <br>
    		<div class="line2"></div>
    		<div id="attrib">
    <i>
    Android is a trademark of Google Inc.<br>
    <br>
    The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the 
    Creative Commons 3.0 Attribution License.<br>
    <br>
    The site myios.us/myiosversion/index.htm.com is not connected or affiliated with Google or Android.<br>
    <br>
    			<a href="about.php.htm" tppabs="http://myios.us/myiosversion/index.htm.com/about.php" style="color:#316;">About</a> -
                            <a href="contact.php.htm" tppabs="http://myios.us/myiosversion/index.htm.com/contact.php" style="color:#316;">Contact us</a> -
    			<a href="privacy.php.htm" tppabs="http://myios.us/myiosversion/index.htm.com/privacy.php" style="color:#316;">Privacy policy</a> -
                            <a href="javascript:if(confirm(%27http://myios.us/myiosversion/index.htm/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?%27))window.location=%27http://myios.us/myiosversion/index.htm/%27" tppabs="http://myios.us/myiosversion/index.htm/" style="color:#316;">Check your iPad/iPhone/iPod version</a>
    
    </i>
    		</div>
    		<div id="footer">
    <!--
    			<p><a href="privacy.html" title="Privacy">Privacy</a></p>
    -->
    		</div>	
    	</div>
    &nbsp;
    	</div>
    <!-- Quantcast Tag -->
    <script type="text/javascript">
    var _qevents = _qevents || [];
    
    (function() {
    var elem = document.createElement('script');
    elem.src = (document.location.protocol == "https:" ? "https://secure" : "http://edge/") + ".quantserve.com/quant.js";
    elem.async = true;
    elem.type = "text/javascript";
    var scpt = document.getElementsByTagName('script')[0];
    scpt.parentNode.insertBefore(elem, scpt);
    })();
    
    _qevents.push({
    qacct:"p-b1n2FazLkClhE"
    });
    </script>
    
    <noscript>
    <div style="display:none;">
    <img src="http://www.warriorforum.com/pixel.quantserve.com/pixel/p-b1n2FazLkClhE.gif" tppabs="http://pixel.quantserve.com/pixel/p-b1n2FazLkClhE.gif" border="0" height="1" width="1" alt="Quantcast"/>
    </div>
    </noscript>
    <!-- End Quantcast tag -->
    
    </body>
    <script type="text/javascript">
    function detectScreenRes() {
     document.getElementById('screen-res').innerHTML=window.outerWidth+" x "+window.outerHeight;
    // document.getElementById('screen-res').innerHTML=window.screen.width+" x "+window.screen.height;
    // document.getElementById('screen-res').innerHTML=screen_totals(0)+" x "+screen_totals(1);
    }
    
    function screen_totals(d) {
    var b=document.body, e=document.documentElement;
    return d?Math.max(Math.max(b.scrollHeight,e.scrollHeight),Math.max(b.clientHeight,e.clientHeight)):Math.max(Math.max(b.scrollWidth,e.scrollWidth),Math.max(b.clientWidth,e.clientWidth))
    }
    
    </script>
    <script type="text/javascript">
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-3301414-8']);
      _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>
    
    
    </html>
    I'm not sure if he's using java or php, though I have my doubts he's using php. But being a beginner at coding i'm not sure enough. Maybe you could help me out to find his source and with the implementing of the code. Would appreciate it
    {{ DiscussionBoard.errors[8613789].message }}
    • Profile picture of the author Brandon Tanner
      Originally Posted by kellithean View Post

      Maybe you could help me out to find his source and with the implementing of the code. Would appreciate it
      The source code for that webpage does not link out to any external Javascript files, other than Google +1 and Analytics. And none of the inline Javascript is relevant to what you're looking for. Which means that the code that detects the browser version is a server-side script (likely PHP, but possibly Python, Ruby, etc). Regardless, there's no way to get that source code.

      BTW- the code you posted in the first code block above is Javascript, not Java. And all it is doing is getting the browser info and then parsing it to detect if it is iOS version 5 or greater. If you use a Javascript solution though, it's not going to work for anyone who has Javascript disabled in their browser.

      If you need to get that info, the most reliable way to do it is via PHP "user agent" (using the PHP code I posted above), and then you can parse it to extract the exact bits you need from it.
      Signature

      {{ DiscussionBoard.errors[8615712].message }}
  • Profile picture of the author Andrew H
    Whenever I need a simple script to do something like this, I usually do a quick search on github.

    Example of the script below: Browser Detection
    Check this out: https://github.com/rsyring/browser-detect
    Signature
    "You shouldn't come here and set yourself up as the resident wizard of oz."
    {{ DiscussionBoard.errors[8616194].message }}

Trending Topics