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.
Related
I want to set my own (php2.ini) file, with just a few lines that must overwrite the first php.ini settings - only for those lines.
So I start looking on google and it seems like what I need is the parse_ini_file function.
Ok. Now, in index.php I have:
parse_ini_file("php2.ini");
phpinfo();
exit();
But those settings from php2.ini are not loaded...
Trying to see if the file php2.ini is read-it and it is, beacause if I set parse_ini_file("php2-not-exist.ini"), it tells me that the file cannot be found. So the file php2.ini is read, but the settings are not overwritten.
The php2.ini file has inside the next lines:
error_log = "errors.log"
display_errors = "0"
max_execution_time = "300"
upload_max_filesize = "60M"
post_max_size = "60M"
date.timezone = "Europe/Bucharest"
default_charset = "UTF-8"
mbstring.internal_encoding = "UTF-8"
mbstring.http_output = "UTF-8"
mbstring.encoding_translation = "On"
mbstring.func_overload = "6"
Trying to let this file with just one line like post_max_size = "60M", but still not overwriting the general php.ini settings.
What am I missing here?
I know that some settings can be setted only and only using the php.ini file configuration. So setting a second file with parse_ini_file witch is a function from php... something is not correct, because some servers doesn't allow you to edit the general php.ini file. So how can the php let you set a second php ini file if you don't have access to the general one ? I don't know if that has something to do with my problem. I'm just saying that maybe here is the problem.
Right now I'm using wamp with php 5.5.12. I just want when I upload my website up, to be all done. I know that some hosting servers lets you to have a second php.ini file that must be uploaded in public_html or whatever folder it is. This is why I want to set my php2.ini file. To have the website clean when I'll upload to hosting.
Thank you.
The php parse_ini_file() function reads an ini file into an associative array. It does not set them up as settings like the php.ini file.
There is not a convenience function to override the server settings like this. What you may want here are .user.ini (the leading dot is important) files:
Since PHP 5.3.0, PHP includes support for configuration INI files on a per-directory basis.
and:
In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the document root, only its directory is scanned.
For full documentation on that feature, take a look at http://php.net/manual/en/configuration.file.per-user.php.
Note that only a subset of settings can be changed here:
Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognized in .user.ini-style INI files.
I'm using phpinfo to find out where the server's php.ini file is located:
<?php phpinfo() ?>
When I log-onto the server using FTP, I don't see it in the path under Loaded Configuration File.
How can I download/edit the php.ini file?
Can I create a custom php.ini file for one directory (and its sub directories), so that the global PHP settings are not changed?
probably you don't have permissions to view the file.
what you can do is make a custom_settings.php and use ini_set() to change the configurations and include that file where ever need, to change the configuration settings.
Please refer to http://us1.php.net/ini_set
If you have Direct Admin installed, you can login as admin and edit it there.
It should be on location
/etc/php.ini
If not found there, you can search it by using
locate php.ini
If you want to change any values, try to do it in .htaccess file
Examples:
php_flag display_errors Off
php_value upload_max_filesize 2M
php_value error_reporting 0
php_flag magic_quotes_gpc Off
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'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.
Hi I'm used shared hosting. I want to turn off php safe_mode off for my site. My provider gave me a php.ini file and asked me to put it with my settings in my public_html folder to override the settings, but it didn't work.
You can also try to create a file called php.ini in the root (public_html or other) folder, and putting the following in it:
safe_mode = Off
Depending on server settings, this may or may not work.
Your service provider might have forgot to tell you that you need to enable your user defined php.ini configuration by adding this line in the .htaccess file that you find in your public_html folder:
#Activates php.ini config located in main folder to work also recursively for all subfolders
suPHP_ConfigPath /home/YOUR_CPANEL_USER_NAME/public_html
Obviously replace YOUR_CPANEL_USER_NAME with your cPanel user name.
I'm supposing your server has got suPHP module(which is quite common in nowdays).
BTW: the php.ini file need to be in /home/YOUR_CPANEL_USER_NAME/public_html too and inside you should write this:
safe_mode = Off
And remember that Safe Mode is deprecated in PHP 5.3.0 and is removed in PHP 6.0.0.
TRY:
You can turn it off by adding the following line to a .htaccess file in your root (public html) folder.
If the .htaccess file doesn't exist, you can create it using a simple text editing program.
php_flag safe_mode Off