Forum Moderators: coopster

Message Too Old, No Replies

Redirecting, and saving the data to a log

         

skinter

7:03 pm on Dec 10, 2005 (gmt 0)

10+ Year Member



I have a script that isn't doing what it should, and I have no idea how to fix it.

I want to redirect based on a query string, and save the date it was used to a log.

Here's what I have so far (only relavent code, so if it's bug free, I'll post the whole script):

$url = $_GET['url'];
$log = '/path/to/log.txt';
$text = "[" . date ( 'd-m-Y' ) . "] -> " . $_SERVER['REMOTE_ADDR'] . " - " . $url;

$validated['url'] = stripslashes ( $url );
$urlname = $validated['id'];

if ( stristr ( $url, 'http://' ) == true )
{
header ( 'Location: ' . $urlname );

if ( is_writable ( $log ) )
{
if (!$handle = fopen ( $log. 'a' ) )
{
echo "Cannot open file!";
exit();
}

if ( fwrite ( $handle, $text ) === false )
{
echo "Cannot write to file!";
exit();
}

fclose ( $handle );
}

else
{
echo "The file is not writable!";
}
}

I have some security in place, but it worked fine with just /?file=bleh, but now it won't work at all...

EDIT: And it seems the code tags hate me...

coopster

4:43 pm on Dec 14, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What is it or is it not doing?

skinter

2:30 am on Dec 15, 2005 (gmt 0)

10+ Year Member



(sorry for the late response)

It just won't do anything.

Before it would redirect based on the first query (id), but now it won't even do that.

It basically just reloads the default page instead of loading based on the string.

If that still sounds fuzzy, let me try to clarify.
It is supposed to load a page if the query is blank, or missing. Now, though, it loads that page no matter what the query is.

jatar_k

3:48 pm on Dec 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I am guessing one of your if statements is bombing. try echo'ing a few variables and testing them. echo $url before your http test and see what it is doing, if that works test the next part.

you need to boil it down to figure out exactly which part of your script is failing.