Page 1 of 1
Permission denied in creating and writing a file from PHP
Posted: Wed Aug 22, 2007 9:15 pm
by dennislee85
Hi,
I have tried a simple PHP code to do logging in Linux + Apache2 + PHP 5. But i got error (warning) as below
Code: Select all
[error] [client 203.125.51.30] PHP Warning: error_log(/var/log/mobile365/incoming/test.log) [<a href='function.error-log'>function.error-log</a>]: failed to open stream: Permission denied in /srv/www/htdocs/gateway/sms_incoming.php on line 7
Here is my code:
Code: Select all
<?php
$s = "Hello there";
$logfile = "/var/log/mobile365/incoming/test.log";
error_log($s,3,$logfile);
echo 'done';
?>
Please advise.
Thanks
Posted: Wed Aug 22, 2007 9:20 pm
by tecktalkcm0391
does the file have 777 permissions (read and write for everyone) PHP requires it
Double Posting
Posted: Wed Aug 22, 2007 9:21 pm
by feyd
Re: Permission denied in creating and writing a file from PH
Posted: Wed Aug 22, 2007 9:22 pm
by tecktalkcm0391
Code: Select all
<?php
$s = "Hello there";
$location = "/var/log/mobile365/incoming";
chmod($location, 0777); //edited read why below
$file = "test.log";
$logfile = $location.'/'.$test.log;
error_log($s,3,$logfile);
echo 'done';
?>
Edited because PHP Manual says:
PHP Manual wrote:To ensure the expected operation, you need to prefix mode with a zero (0):
You could try that
Posted: Wed Aug 22, 2007 9:36 pm
by dennislee85
Hi,
Thats helped. Thanks for the solution and sorry for the multiple posts.
Anyway, this solution had give the permission to everyone to access the files. May I know is there any way I can assign an user and user group for php so i can chown the "/var/log/mobile365/incoming" folder which will only used by php only.
Many Thanks.
Posted: Wed Aug 22, 2007 9:45 pm
by tecktalkcm0391
dennislee85 wrote:Hi,
Thats helped. Thanks for the solution and sorry for the multiple posts.
Anyway, this solution had give the permission to everyone to access the files. May I know is there any way I can assign an user and user group for php so i can chown the "/var/log/mobile365/incoming" folder which will only used by php only.
Many Thanks.
I don't think that is possible, but if your server is /websitefiles/var/... for the log file and /websitefiles/public_html/.... for the actual files that are "live" on the internet, then there is no reason to do that because unless you have a "live" file that allows you to read the log, and internet user can't get to it..
unless they exploit you somehow on another page...freakn hackers...grrrr..
Posted: Wed Aug 22, 2007 9:49 pm
by dennislee85
Hi,
Ok, i got it. Thanks a lot.

Posted: Thu Aug 23, 2007 12:50 am
by dennislee85
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
I am trying to retrieve data from xml file POST from remote server. I am using SimpleXMLElement to do this. But when i try to use the SimpleXMLElement->getName() function, it gave me this error:
Code: Select all
[Thu Aug 23 13:46:34 2007] [error] [client 62.80.122.178] PHP Fatal error: Call to undefined method SimpleXMLElement::getName() in /srv/www/htdocs/gateway/sms_incoming.php on line 10
My codes:
Code: Select all
<?php
$files = $_POST['XmlMsg'];
$logfile = "/var/log/mobile365/incoming/test.log";
$str1 = "Start \n";
if($files){
$xml = new SimpleXMLElement($files);
$str1 = $xml->getName();
}else{
$str1 = $str1." file empty \n";
}
error_log($str1,3,$logfile);
?>
Here is my XML file:
Code: Select all
<?xml version="1.0" ?>
<SMS_MO>
<MSISDN>+6593880590</MSISDN>
<ORIGINATING_ADDRESS>+61416905690</ORIGINATING_ADDRESS>
<MESSAGE>HTTP</MESSAGE>
<PARAMETERS>
<OPERATORID>43</OPERATORID>
<ACCOUNTID>20745</ACCOUNTID>
<MESSAGEID>541603206</MESSAGEID>
<OPERATOR_INFORMATION>
<OPERATOR_STANDARD>GSM</OPERATOR_STANDARD>
<OPERATOR_CODE>
<MCC>505</MCC>
<MNC>03</MNC>
</OPERATOR_CODE>
</OPERATOR_INFORMATION>
<DCS>7b</DCS>
<CLASS>1</CLASS>
<RECEIVED_SERVICENUMBER>61416905690</RECEIVED_SERVICENUMBER>
<KEYWORD>HTTP</KEYWORD>
<RECEIVEDTIME>
<DATE>Thu, 23 Aug 2007</DATE>
<TIME>06:34:16</TIME>
</RECEIVEDTIME>
</PARAMETERS>
</SMS_MO>
Please advise
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]