Welcome to WebmasterWorld Guest from 50.16.112.199

Forum Moderators: coopster & jatar k

specifying domain root from different directories

Trying to write errors to file on root from scripts running in various dire

   
10:33 am on Oct 4, 2007 (gmt 0)

5+ Year Member



I have a custom SQL error reporting function which I'm using to write errors to a file at the domain root.

To be exact, the site is running in a subdomain and I want to write the errors to a file in the subdomain route.

My problem is that if I use...

error_log($msg, 3, "/sql_remote_error_log.log")

when the script that causes the error is not in the root directory, eg. '/docs/bad_script.php' the error is written to the '/docs/' directory instead. I wouldn't mind but I have lots of directories and it's getting really tedious trying to check all the logs!

The error function is only referenced by the bad_script.php, I can't type the full path in my function because if I do it will be incorrect when accessed from other locations.

I also tried specifying an absolute path from 'http://..' but it failed with an error (something about http wrapper does not support writable connections.

Is there an easy way around this please?

Regards, peter

11:47 am on Oct 4, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Durr I should read your post properly before replying...
Try using fopen [uk3.php.net] as it accepts http:// or server paths /var/vpopwww/htdocs/whatever. The fwrite [uk3.php.net] what you need.

[edited by: PHP_Chimp at 11:50 am (utc) on Oct. 4, 2007]

12:06 am on Oct 5, 2007 (gmt 0)

5+ Year Member



Thanks for that PHP_Chimp, I hadn't thought about doing that. fopen etc is not something I've used much but it could solve my problem.

Will go bury my head in the manual for a while and let you know if it solves my problem.

pete

12:38 am on Oct 5, 2007 (gmt 0)

5+ Year Member



I've now tried fopen and unfortunately it failed too, with the following error message:

"Warning: fopen(http://mydomain.ph/sql_remote_error_log.log) [function.fopen]: failed to open stream: HTTP wrapper does not support writeable connections. in /usr/home/mydomain/domains/mydomain.ph/public_html/functions/common_funcs.php on line 46
Cannot open error log."

Here is the code I used:


// begin write to file

$filename = 'http://mydomain.ph/sql_remote_error_log.log';

// We're opening $filename in append mode.
if (!$handle = fopen($filename, 'a+b')) {
echo "Cannot open error log.";
exit;
}

// Write $msg to our opened file.
if (fwrite($handle, $msg) === FALSE) {
echo "Cannot write to error log.";
exit;
}

fclose($handle);


// end write to file

The example in the manual uses an http path, so I can't understand why this is failing?

Any ideas pls?

PHP5, by the way.

pete

12:54 am on Oct 5, 2007 (gmt 0)

5+ Year Member



I've done it now.

I changed to an absolute server path which then gave me a "Permission denied" error.

I had to make the file read and writeable for PUBLIC, before it would work though. Still, should be safe enough, since the filename is not easily guessable.

Thanks for your help.

peter

7:56 am on Oct 5, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



As you are using a server path put the file in the level below your web pages, htdocs or whatever they have decided to call it.
The it may well be open to the public, but they cant get access.
11:11 am on Oct 5, 2007 (gmt 0)

5+ Year Member



Thanks for that mate. Will do as you suggest.

Regards

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month