Php Counter Problems/questions.

windows

Guest
Hi<br /><br />I've posted a few times while creating this and now I'm starting to regret taking on writing a "simple" counter script myself?But I'd still like to finish what I started. <br /><br />I created a script called counter.php(shown below) and uploaded it into my public_html folder. I have also placed <?php @include_once <!-- w --><a class="postlink" href="http://www.mysite.com/counter.php">www.mysite.com/counter.php</a><!-- w -->? into the pages I want counted. My problem is that when I load the html pages, it doesn't seem to get a $URL variable from the $URL=$_SERVER('HTTP_REFERER'); line in my counter.php.<br /><br />When I place the counter.php script in the same directory of my html pages $URL gets an ugly value of<br /><a href="http://www.mysite.com:2082/frontend/x2/files/select.html?dir=/home/mySiteId/public_html/mywebpagedirectory&file=index.htm" target="_blank">http://www.mysite.com:2082/frontend/x2/fil...&file=index.htm</a> <br /><br />Does anyone know why I can't get a value for $URL when the counter.php is located in any folder other than the one my webpages are in? Is there some file permissions in public_html that I'm missing? Is there a better way I can accomplish this? I've read other msg boards/php sites that say HTTP_REFERER doesn't always act as it should but I can't find anything else comparable.<br /><br /><?php<br />require_once('mysql_connect.php');<br /><br />$URL=$_SERVER['HTTP_REFERER'];<br />$dt = date("Y-m-d");<br />$q1 = "SELECT url FROM counter WHERE url='$URL' and date='$dt'";<br />$r1 = mysql_query($q1);<br /><br />if(mysql_num_rows($r1) == 0) { //url has not been counted on date=$dt<br />$query = mysql_query("INSERT INTO counter(url,count,date) VALUES('$URL', '1','$dt')");<br />}<br />else {<br />$query = mysql_query("UPDATE counter SET count=count+1 WHERE url='$URL'");<br />}<br /><br />?><br /><br />Thanks for your help<br />Mike<!--content-->
I believe your problems may stem from the 'include_once' statement you've added to your web pages. With the domain name as you have it, PHP won't see it as a valid URL or file path. I don't believe you want a full URL there, as this will cause PHP to issue a second page request to run your script, and you lose access to the server variables from the first page request (your web page with the included PHP code). I'd suggest using the following:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php @include_once /home/cpanelName/public_html/counter.php?><!--c2--></div><!--ec2--><!--content-->
Thanks for your help.<br /><br />I didn't realize that about the include function, it's good to know. My work around was to pass a PHP_SELF into the counter.php url and then GET that.<br /><br />Thanks to everyone who helped!<br />Mike<!--content-->
 
Back
Top