Solved

Why won't this script recognize the parameter?

Posted on 2008-06-17
9
216 Views
Last Modified: 2013-11-05
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
Comment
Question by:rmmarsh
  • 4
  • 4
9 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 21807178
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
 
LVL 48

Expert Comment

by:hernst42
ID: 21807188
Try $_SERVER["QUERY_STRING"]

maybe your script relies on register_globals to be turned on?
0
 

Author Comment

by:rmmarsh
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.

Thanks...
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 82

Assisted Solution

by:hielo
hielo earned 500 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:
C:\Test\data.txt

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

Author Comment

by:rmmarsh
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?
0
 

Author Comment

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

Assisted Solution

by:hielo
hielo earned 500 total points
ID: 21807641
>>Warning: Cannot modify header information ..
start your file with:
<?php
ob_start();
0
 

Author Comment

by:rmmarsh
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!
0
 
LVL 82

Expert Comment

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

>>Thanks again!
You are welcome!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
000webhost.com default error log 1 28
Curl & PHP Command Help 4 23
PHP not parsing ' character 12 40
What does this formatting equate to? 7 11
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

777 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