0

I plan to do a web site home page with java script and flash. Both are separate pages.

What i want means, If the user's internet connection is slow means, script page want to be load. If the user have fast internet, Flash site want to be load.

How to do it with php ?

Kumar
  • 371
  • 1
  • 4
  • 12
  • Did you try anything, at least a Google Search ? – Mihai Iorga Aug 28 '12 at 10:00
  • 3
    Can't be done with PHP, PHP runs on the server side and doesn't have access to the information required to measure the speed a client downloads from the server. In the time it takes to measure someone's download speed effectively you could serve them with ether page. – George Reith Aug 28 '12 at 10:00
  • 1
    @KumarP check this link.. JS code http://www.ehow.com/how_5804819_detect-connection-speed-javascript.html also u can check this link http://stackoverflow.com/questions/6994061/how-to-detect-slow-internet-connections – swapnesh Aug 28 '12 at 10:03
  • 1
    @swapnesh thank you, I'll feedback after complete my work. – Kumar Aug 28 '12 at 10:32

1 Answers1

1

This is working for me, Made some changes in following tutorial http://www.ehow.com/how_5804819_detect-connection-speed-javascript.html

<html>
<head><Title>Test Speed</title>
<script type="text/javascript" language="Javascript">
var imageAddr = "/myimage.gif" + "?n=" + Math.random() ;
var startTime, endTime ;
var downloadSize = 5500 ;
var download = new Image() ;
download.onload = function() {
endTime = (new Date()).getTime() ;
showResults () ;
}
startTime = (new Date()).getTime() ;
download.src = imageAddr ;
function showResults () {
var duration = Math.round((endTime - startTime) / 1000) ;
var bitsLoaded = downloadSize * 8 ;
var speedBps = Math.round(bitsLoaded / duration) ;

if (speedBps <= 50000){
    window.location = "/script.html";
    }
    else{
    window.location = "/flash.html";
    }

}
</script>
</head>
<body>
<center>Page Loding</center>
</body>
</html>
Kumar
  • 371
  • 1
  • 4
  • 12
  • Please, please, please.. don't do this. Downloading a tiny file over new TCP connection will only add more latency, and won't give you any reliable measurements. You're better off checking the user agent on the server (binary check for mobile or not), or even using CSS3 media queries to layout and render the correct content. – igrigorik Aug 28 '12 at 22:51
  • @igrigorik actually i don't want to measure exact value. I just want to switch page based on internet speed. If possible give me link for checking user agent and CSS3 media queries. I am new to it. so – Kumar Nov 21 '12 at 09:49