Jump to content

Recommended Posts

Posted

Hi

 

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.

 

I created a script called counter.php(shown below) and uploaded it into my public_html folder. I have also placed <?php @include_once www.mysite.com/counter.php?> 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.

 

When I place the counter.php script in the same directory of my html pages $URL gets an ugly value of

http://www.mysite.com:2082/frontend/x2/fil...&file=index.htm

 

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.

 

<?php

require_once('mysql_connect.php');

 

$URL=$_SERVER['HTTP_REFERER'];

$dt = date("Y-m-d");

$q1 = "SELECT url FROM counter WHERE url='$URL' and date='$dt'";

$r1 = mysql_query($q1);

 

if(mysql_num_rows($r1) == 0) { //url has not been counted on date=$dt

$query = mysql_query("INSERT INTO counter(url,count,date) VALUES('$URL', '1','$dt')");

}

else {

$query = mysql_query("UPDATE counter SET count=count+1 WHERE url='$URL'");

}

 

?>

 

Thanks for your help

Mike

Posted

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:

><?php @include_once /home/cpanelName/public_html/counter.php?>

Posted

Thanks for your help.

 

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.

 

Thanks to everyone who helped!

Mike

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...