homepage Welcome to WebmasterWorld Guest from 54.237.54.83
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
specifying domain root from different directories
Trying to write errors to file on root from scripts running in various dire
snowweb




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

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

 

PHP_Chimp




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

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]

snowweb




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

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

snowweb




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

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

snowweb




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

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

PHP_Chimp




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

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.

snowweb




msg:3469853
 11:11 am on Oct 5, 2007 (gmt 0)

Thanks for that mate. Will do as you suggest.

Regards

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved