jaypabs
jaypabs

Reputation: 1567

Page not found error on redirect

I have the following code in the head tag of my page:

<script type="text/javascript">
var startime = (new Date()).getTime();

window.onload = function()
{
    record_visit('ol');         
    setInterval("record_visit('update')", 300000);
}

window.onbeforeunload = function(){ record_visit('obul'); } //obul = onbeforeunload

function record_visit(value) {
    var x = (window.ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
var url='<?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>';
x.open("GET", "/sc/count_visit.php?t=" + (((new Date()).getTime() - startime) / 1000)+"&type="+value+"&url="+url, false);
    x.send(null);
}

It works great but on my drupal site under recent log messages I received an error:

page not found  02/27/2012 - 23:04  count_visit.php Anonymous (not verified)

Since I have around 6k visitors a day that error appears many times in just a minute.

Am I missing something on the code above? I believe it's not count_visit.php that has problem.

Upvotes: 0

Views: 624

Answers (1)

skyronic
skyronic

Reputation: 1635

You have to url encode your url variable. encodeURIComponent(url)

Upvotes: 1

Related Questions