Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
SOLVED - PHP function fopen only can read a file
SOLVED - PHP function fopen only can read a file
Hi everyone ...
I have recently installed Linux Debian 8.3 Jessie, with an Apache web server that works in localhost. I added PHP, MySQL and PhpMyAdmin.
Everything was fine till I started using some more specific functions.
For two purposes (generating PHP pages and creating txt files with the content of a MySQL table) I need to use the function fopen ... and it fails.
It might because I am making an obsolete use of that function, but it is probably linked to the rights that has that the server to write a file.
$fp = fopen ($fichier, "a");
if (! ($fp))
{
echo " -- Attention -- l'ouverture du fichier a échoué: vérifiez les droits d'écriture ...<br>";
return FALSE;
}
... gives that error message : Attention -- and so on.
Is there anything wrong with the server ? My use of this PHP function looks ok.
I have recently installed Linux Debian 8.3 Jessie, with an Apache web server that works in localhost. I added PHP, MySQL and PhpMyAdmin.
Everything was fine till I started using some more specific functions.
For two purposes (generating PHP pages and creating txt files with the content of a MySQL table) I need to use the function fopen ... and it fails.
It might because I am making an obsolete use of that function, but it is probably linked to the rights that has that the server to write a file.
$fp = fopen ($fichier, "a");
if (! ($fp))
{
echo " -- Attention -- l'ouverture du fichier a échoué: vérifiez les droits d'écriture ...<br>";
return FALSE;
}
... gives that error message : Attention -- and so on.
Is there anything wrong with the server ? My use of this PHP function looks ok.
Last edited by Spark on 2016-02-16 20:04, edited 1 time in total.
Re: PHP function fopen only can read a file
I have given rights 777 to all PHP files involved in this.
Instead of option a for fopen I have also tried with w.
And it still does not work. There may be something wrong with the server.
Instead of option a for fopen I have also tried with w.
And it still does not work. There may be something wrong with the server.
Re: PHP function fopen only can read a file
Well ... I found the solution watching answers given in another forum.
I had to change the rights that has the user www-data ...
chown -R www-data:www-data /var/www/html/nujna
By the way ... I remembered I had to see what's up on file php.ini
I typed :
grep -i safe_mode /etc/php5/apache2/php.ini
and was surprised the only safe_mode variable is related to MySQL.
I actually do not understand what is that safe mode.
(Sometimes I feel unsafe about so much safety)
I had to change the rights that has the user www-data ...
chown -R www-data:www-data /var/www/html/nujna
By the way ... I remembered I had to see what's up on file php.ini
I typed :
grep -i safe_mode /etc/php5/apache2/php.ini
and was surprised the only safe_mode variable is related to MySQL.
I actually do not understand what is that safe mode.
(Sometimes I feel unsafe about so much safety)
Re: PHP function fopen only can read a file
You do not want to give the world write access to a script. Really.Spark wrote:I have given rights 777 to all PHP files involved in this.
- GarryRicketson
- Posts: 5644
- Joined: 2015-01-20 22:16
- Location: Durango, Mexico
Re: SOLVED - PHP function fopen only can read a file
I use a PHP program on some websites, and the only way to edit some parts or files is to chmod them, then do the edit needed, but chmod them back to read only after
any editing or writeing is done. You should be able to modify the script so that
it does that as well. Also having it in a group and only that group can read/write,
in a nut shell there are ways to do this securly and safely.
The OP mentions this is on a "localhost" setup, so in one way
it probabley does not matter, but it is better to develope safer habits and practices, Definately do not upload this to a online server or hosting with those files
using
When I first saw this post, there are a couple of reasons I did not respond,
1. I don't know that much about PHP and MYSQL,
2nd: reason: The OP does not use code boxes for the code:
These are code boxes:[/code]
snd it will display correctly, just to demonstrate, look what happens with the above example , when I do not use code boxes:
(: any code ):can safely be (:written:)
As you can see the text shows a sad face instead of the actual symbols I used, any code or scripts may contain symbols or code that causes it to display poorly, but also
it makes it more difficult to read, and may not be showing exactly like the true code is.
Another reason, I did not respond,
Often and usually it refers to lines in the code that cause the error, that section or block of code is especially what we would need to see.
Later, just now I did translate it:
and in the code that was posted the error is in French, I did not have the time,nor desire
to have to translate it, but now I did:
the file is writable, but since the OP did not bother to translate it, I did not bother
to try to answer.
The 3rd reason, the little piece of code the OP shows, is not enough to get the complete picture. Usually it is better to show the entire script, so we can see what it is doing. Any way, with all that said, please don't get me wrong, I am not trying to be rude
or snarky, I am trying to help you, and anyone else that takes the time to read, by explaining some things that will help get faster responses, and better answers in the
future. Please use code boxes for scripts and code, that is what they are here for.
Thank you
any editing or writeing is done. You should be able to modify the script so that
it does that as well. Also having it in a group and only that group can read/write,
in a nut shell there are ways to do this securly and safely.
Is 100% correct on this.Dasein> You do not want to give the world write access to a script. Really.
The OP mentions this is on a "localhost" setup, so in one way
it probabley does not matter, but it is better to develope safer habits and practices, Definately do not upload this to a online server or hosting with those files
using
Code: Select all
chmod 777
When I first saw this post, there are a couple of reasons I did not respond,
1. I don't know that much about PHP and MYSQL,
2nd: reason: The OP does not use code boxes for the code:
These are code boxes:
Code: Select all
[code] (: any code :():can safely be (:written:)
snd it will display correctly, just to demonstrate, look what happens with the above example , when I do not use code boxes:
(: any code ):can safely be (:written:)
As you can see the text shows a sad face instead of the actual symbols I used, any code or scripts may contain symbols or code that causes it to display poorly, but also
it makes it more difficult to read, and may not be showing exactly like the true code is.
Another reason, I did not respond,
Even though I do not know much about php or mysql, what little I do know, I have never seen a error message like that, if you want help, you need to really post exactly what the error message says.gives that error message : Attention -- and so on.
Often and usually it refers to lines in the code that cause the error, that section or block of code is especially what we would need to see.
Later, just now I did translate it:
and in the code that was posted the error is in French, I did not have the time,nor desire
to have to translate it, but now I did:
That by itself would have been enough to tell the OP, check and make sureopening the file failed: check writable
the file is writable, but since the OP did not bother to translate it, I did not bother
to try to answer.
The 3rd reason, the little piece of code the OP shows, is not enough to get the complete picture. Usually it is better to show the entire script, so we can see what it is doing. Any way, with all that said, please don't get me wrong, I am not trying to be rude
or snarky, I am trying to help you, and anyone else that takes the time to read, by explaining some things that will help get faster responses, and better answers in the
future. Please use code boxes for scripts and code, that is what they are here for.
Thank you
Last edited by GarryRicketson on 2016-02-17 03:00, edited 3 times in total.
"What we expect you have already Done"
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?
- ralph.ronnquist
- Posts: 342
- Joined: 2015-12-19 01:07
- Location: Melbourne, Australia
- Been thanked: 6 times
Re: SOLVED - PHP function fopen only can read a file
If Web Hacking would be Software Engineering, one would probably have both Version Control and separations between development workspace, pre-publishing staging area and live site area.
Re: SOLVED - PHP function fopen only can read a file
I have changed rights on these files to avoid that everyone can write on them.
... and this question keeps being solved : a user can launch, through some specific files, the creation of files :
- pictures renamed or redimensioned
- text files translating the contents of a table
- php files whose html source code is made according to the data base ...
Code: Select all
root@debian002:/cdpath# chmod -R 755 /var/www
- pictures renamed or redimensioned
- text files translating the contents of a table
- php files whose html source code is made according to the data base ...
Re: SOLVED - PHP function fopen only can read a file
I am not sure I understood this.ralph.ronnquist wrote:If Web Hacking would be Software Engineering, one would probably have both Version Control and separations between development workspace, pre-publishing staging area and live site area.
I always separate a live site area and a localhost.
Only at the localhost are the files that can be modify the database or do whatever other task that could be targeted by a hacker.
Re: SOLVED - PHP function fopen only can read a file
after apache installed If you do not have permission to manipulate its contents, we give with the following. Change the directory owner and the group should use it. YOURUSER replace with the user name they are using
And next
And now you can test permiss with function is_readable() and is_writeable ()
Try this function
And other function but remplace is_readable () with is_writeable ()
Code: Select all
chown -R YOURUSER:www-data /var/www
Code: Select all
chmod -R 755 /var/www
Try this function
Code: Select all
<?php
$file-name = 'test.txt';
if (is_readable($file-name)) {
echo 'Is readable';
} else {
echo 'Is not readable';
}
?>