Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

okay on xampp but not work on-line

Status
Not open for further replies.

peterpann

Programmer
Jun 19, 2007
63
0
0
GB
THe following code works locally on xampp but not on 5 different servers on-line. How to make the code work on-line also ? The plan is to show how long successive visitors have spent on the ajaxtest.htm page. The files involved are ajaxtest.htm, ajaxtestpost.php, ajaxtestvisits.txt, ajaxtestvisits.php and are on-line at
They are also duplicated at
with the same results

<html>
<head>
<title>ajaxtest.htm</title>
</head>
<body onbeforeunload="beforeleavepage()">
ajaxtest.htm to store durations this page visited in ajaxtestvisits.txt
<script type="text/javascript">
<!--Hide
function getstarttime() //when page loads
{
var now = new Date();
return now.getTime();
}
function beforeleavepage()
{
var now = new Date();
var milliseconds = now.getTime() - starttime;
var duration = (milliseconds/1000).toFixed(1); //7.3
var httppost = new XMLHttpRequest();
httppost.open("POST", "ajaxtestpost.php", true);
var postdata = "duration="+duration;
//Send the proper header information along with the request
httppost.setRequestHeader("Content-type", "application/x- httppost.setRequestHeader("Content-length", postdata.length);
httppost.send(postdata);
}
var starttime = getstarttime(); //milliseconds
//stop hiding-->
</script>
</body>
</html>
........................
<?php
//ajaxtestpost.php
$duration = $_POST["duration"];
$file = 'ajaxtestvisits.txt';// Open the file to get existing content
$prev = file_get_contents($file);// Append new data to the file
$current .= $duration . " &nbsp; ";
$total = $current . $prev . "\n";
file_put_contents($file, $total);
fclose($file);
exit();
?>
......................
<?php
//ajaxtestvisits.php
$file = 'ajaxtestvisits.txt';
$prev = file_get_contents($file) . $message;
echo $prev;
?>
....................
6.8 &nbsp; 5.0 &nbsp; ajaxtestvisits.txt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top