I'm trying to turn off magic_quotes_gpc in PHP. I'm running PHP with Apache and Ubuntu.
I have in my config file (/etc/php5/apache2/php.ini):
magic_quotes_gpc Off
Where I create a page with phpinfo() it shows magic_quotes_gpc as on. I've also looked in Additional .ini files parsed and there is no setting for it.
Why is PHP ignoring this?
try to add/edit in php.ini
magic_quotes_gpc = Off
after adding restart your apache services for taking effect this
You can turn them off using .htaccess with:
php_flag magic_quotes_gpc Off
and also using php if writable php.ini
ini_set('magic_quotes_gpc' , 0 );
Firstly, it is deprecated so, don't rely on it. Mmmmmmmkay?
Secondly, Check
Loaded Configuration File
Under phpinfo()
Also Add :
php_flag magic_quotes_gpc Off to your .htaccess file.
Cool?
Did you recently make this change? If so, you have to restart PHP for it to take effect.
Related
I disabled magic quotes at the end of my php.ini file in my root directory and there was no change. I am still getting backslashes in front of single quotes in $_POST entries. So I put a php.ini file in the same directory as the PHP file being run and only included the lines disabling magic quotes, but there still isn’t any change.
What am I missing here?
PHP 5.3.24 on a GoDaddy shared server.
The php.ini file:
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off
Note: As of php 7.4 this option is deprecated and it is removed in php 8.0
You could try it with a .htaccess file. You will need this line:
php_flag magic_quotes_gpc Off
As GoDaddy Shared Server doesn't accept this above option try this instead:
You have to make a file named like php5.ini and place this in the root folder. You can add just only the three lines you need or you can copy the php.ini file that you have on your local computer and edit the changes you want.
I can't seem to change some values in php.ini.
For example: display_errors = On
I can only turn it on on runtime.
I suspect that suhosin is messing with this, is there any way to bypass it?
Yes I'm sure I'm editing the right files, but look at this, taken from phpinfo():
Additional .ini files parsed /etc/php5/fpm/conf.d/pdo.ini, /etc/php5/fpm/conf.d/suhosin.ini
But I open suhosin.ini and there is nothing there, only extension=suhosin.so
Try adding this to your php.ini or suhosin.ini:
suhosin.disable.display_errors = Off
I am trying to use PHP's built-in function get_browser(). I followed the instructions in this useful post, but I'm still getting the error
browscap ini directive not set.
I downloaded the php_browscap.ini file and moved it into the same directory as my .htaccess file, so that its location is home/hostname/subdomain/php_browscap.ini Since I do not have access to my php.ini file, I am trying to edit the browscap property using .htaccess. This is what I entered:
php_value browscap home/hostname/subdomain/php_browscap.ini
I don't know if it matters, but below that there's some Rewrite Engine code.
As forementioned, I am still getting the error above. What did I do wrong?
Thanks.
The browscap PHP value has a changeable mode of PHP_INI_SYSTEM meaning it can only be set in php.ini or httpd.conf (not .htaccess).
Do a phpinfo() to understand your PHP runtime config. If your system is configure as "CGI/FastCGI" then it is probably running suPHP as the PHP initiator. In this case you can specify your own php.ini file. By default suPHP looks in the script directory but you can override this by the following directive in your .htaccess file:
suPHP_ConfigPath (expects a path name)
This option tells mod_suphp which path to pass on to the PHP-interpreter (by setting the PHPRC environment variable). Do NOT refer to a file but to the directory the file resists in.
E.g.: If you want to use "/path/to/server/config/php.ini", use "suPHP_Config/path/to/server/config".
If you don't use this option, PHP will use its compiled in default path.
Also you must use a properly formed path in your browsercap directive e.g.
browscap="/home/hostname/subdomain/php_browscap.ini"
(Note the leading /)
Addendum
I've just check and the Dreamhost shared hosting plan uses suEXEC. With suEXEC you can normally override the php.ini patch by copying the system php.ini (phpinfo() tells you where to find this) into a private directory, say _private as well as the browsercap.ini then adding
SetEnv PHPRC /home/hostname/_private
to your .htaccess file. If this doesn't work then the issue is specific to Dreamhost's suEXEC config and you need to ask this Q on http://discussion.dreamhost.com/
There are two potential problems here.
Perhaps your host does not allow you to override ini settings in the .htaccess file.
Maybe browscap does not like the path you have provided. Try:
php_value browscap /home/hostname/subdomain/php_browscap.ini
And ensure that permissions on that file allow the web user to read it.
If you are on a shared hosting and do not have access to the system php.ini then you can use the following standalone replacement of php's native "get_browser()" implementation.
https://github.com/garetjax/phpbrowscap
In which file can I change the value of
magic_quotes_gpc = 0
in PHP?
Thanks in advance.
The configuration file is php.ini. The actual configuration value you're looking for is magic_quotes_gpc
On linux/unix systems it's usually
/etc/php.ini
On windows it's dependent on the installation path, so you'll have to search for it.
Beside on php.ini you can also change magic_quotes_gpc by using .htaccess. Put following line on your .htaccess:
php_value magic_quotes_gpc off
I opened the notepad, inserted 3 lines in it, saved it as php.ini, and uploaded it in public_html, but I am still getting an error that requires to first switch the magic quotes off. The syntax of the three lines is as following:
magic_quotes_gpc = 0
magic_quotes_runtime = 0
magic_quotes_sybase = 0
What am I doing wrong?
use phpinfo() function to see what php.ini file you're actually using
You can probably alter these settings in a .htaccess configuration file as well:
php_flag magic_quotes_gpc off
php_flag magic_quotes_runtime off
php_flag magic_quotes_sybase off
See PHP: How to change configuration settings.
Most hosting companies lets you define a local ini file. Check their support pages, and see where you should put your php.ini file for it to be read by the php engine. If they have an option for this, you don't have to worry about restarting the server.
If you can't find any info about it, create a page with the following code:
<?php phpinfo(); ?>
And look for the property named "Configuration File (php.ini) Path". This is where you should put the file.
It's not meant to be placed in the public_html folder... it should be in your PHP installation folder.
Php.ini is not usually located in public_html. If you can't access your real php.ini, try writing
php_flag magic_quotes_gpc off
in a .htaccess file (in public_html).
Most hosting companies won't let you play around with the php.ini unless you rent a dedicated server from them. On that, you could try on page php.ini settings like the following:
ini_set("magic_quotes_gpc", "0");
ini_set("magic_quotes_runtime", "0");
ini_set("magic_quotes_sybase", "0");
If that doesn't work, then you'll have to ask your hosting company about it.
On CentOS 8 run
service php-fpm restart
To read the edited php.ini file
Well, you have to change your main php.ini which I don't think is in public_html.
Moreover, in order to see the changes you have to restart your php engine.