[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

Why won't this script recognize the parameter?

I am calling this script by the following statement (in a browser):

http://www.mysite.com/clickCounter/count.php?http://www.mysite.com/downloads/PragerInventorySetup.exe

It was working fine on a Windows server; I just switched to a Linux server and now this...
<?php
 
 
 
$COUNT_FILE = "data.txt";  // En: Absolute path and name to count data file.
 
 
 
function error ($error_message) {
 
    echo $error_message."<BR>";
 
    exit;
 
}
 
 
 
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);
 
fclose($fp);
 
header("Location: $url");
 
 
 
?>

Open in new window

0
rmmarsh
Asked:
rmmarsh
  • 4
  • 4
3 Solutions
 
hieloCommented:
Instead of:
$url = urldecode($QUERY_STRING);

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

IF that does not work, try passing it as:
http://www.mysite.com/clickCounter/count.php?theFile=http://www.pragersoftware.com/downloads/PragerInventorySetup.exe

and to retrieve the value use:
$url=$_GET['theFile'];
0
 
hernst42Commented:
Try $_SERVER["QUERY_STRING"]

maybe your script relies on register_globals to be turned on?
0
 
rmmarshAuthor Commented:
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.

Thanks...
0
Industry Leaders: 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!

 
hieloCommented:
>> but now it won't find the file
Provide the full path to the file. So if the file resides on:
C:\Test\data.txt

use:
$COUNT_FILE = "C:\\Test\\data.txt";
0
 
rmmarshAuthor Commented:
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?
0
 
rmmarshAuthor Commented:
Line 47 above refers to line 91 in attached code snippet
0
 
hieloCommented:
>>Warning: Cannot modify header information ..
start your file with:
<?php
ob_start();
0
 
rmmarshAuthor Commented:
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!
0
 
hieloCommented:
>>would be nice to know why I'm doing something!
LOL. I hear you!

>>Thanks again!
You are welcome!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now