Why won't this script recognize the parameter?

Posted on 2008-06-17
Medium Priority
Last Modified: 2013-11-05
I am calling this script by the following statement (in a browser):


It was working fine on a Windows server; I just switched to a Linux server and now this...
$COUNT_FILE = "data.txt";  // En: Absolute path and name to count data file.
function error ($error_message) {
    echo $error_message."<BR>";
echo $QUERY_STRING."<br>";
$url = urldecode($QUERY_STRING);  //  get the passed URL
if (! file_exists($COUNT_FILE))
    error("Can't find data file, check '\$COUNT_FILE' var...");
if ((! $url) || (! preg_match("/http:/", $url)))
error ("The URL you passed is invalid (doesn't begin with http:)");
$file_arry = file($COUNT_FILE); //  read each line of data from count.txt file into array
//list($key, $val) = each($file_arry);
//echo "key=".$key."<BR>";
//echo "val=".$val."<BR>";
while (list($key, $val) = each($file_arry)) {  //  parse each line into key/value pairs
    if ($val != "") {  //  if URL is not blank...
        list($file_url, $nb) = preg_split("/\t|\n/", $val);
        if ($file_url == $url) {
           $nb += 1;
           $file_arry[$key] = "$file_url\t$nb\n";
           $find = 1;
$file = join ("", $file_arry);
//if (! $find)  //  if URL wasn't found, put new URL into file
//   $file .= "$url\t1\n";
$fp = fopen("$COUNT_FILE", "w");
flock($fp, LOCK_EX + LOCK_NB);
fputs($fp, $file);
flock($fp, LOCK_UN);
header("Location: $url");

Open in new window

Question by:rmmarsh
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
LVL 82

Accepted Solution

hielo earned 2000 total points
ID: 21807178
Instead of:
$url = urldecode($QUERY_STRING);

$url = urldecode($_SERVER['QUERY_STRING'] );

IF that does not work, try passing it as:

and to retrieve the value use:
LVL 48

Expert Comment

ID: 21807188

maybe your script relies on register_globals to be turned on?

Author Comment

ID: 21807480
Hielo:  that seems to do the job... but now it won't find the file, so I have some homework to do before I award points...  will get back to you tomorrow.

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 82

Assisted Solution

hielo earned 2000 total points
ID: 21807531
>> but now it won't find the file
Provide the full path to the file. So if the file resides on:

$COUNT_FILE = "C:\\Test\\data.txt";

Author Comment

ID: 21807552
Hmmm... deleted the file (because it was old, and will upload new ones tonight when I get home) and am now getting this warning:

Warning: Cannot modify header information - headers already sent by (output started at /home/wwwmar1/public_html/clickCounter/count.php:10) in /home/wwwmar1/public_html/clickCounter/count.php on line 47

What do I do to fix this?

Author Comment

ID: 21807562
Line 47 above refers to line 91 in attached code snippet
LVL 82

Assisted Solution

hielo earned 2000 total points
ID: 21807641
>>Warning: Cannot modify header information ..
start your file with:

Author Comment

ID: 21807725
That did it also... I'm gonna get my PHP textbook out and start reading; would be nice to know why I'm doing something!

Thanks again!
LVL 82

Expert Comment

ID: 21807798
>>would be nice to know why I'm doing something!
LOL. I hear you!

>>Thanks again!
You are welcome!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question