I tested this script on another server and it worked fine. Do I have to set my php.ini file? And how?
<?php
ini_set('allow_url_fopen', 1);
if (!isset($_GET['url'])) {
exit();
}
echo file_get_contents($_GET['url']);
?>
From the PHP Manual on allow_url_fopen
Note: This setting can only be set in php.ini due to security reasons.
Open the PHP.ini file with an editor and change the setting accordingly. If this on shared hosting and you do not have access to the PHP.ini contact your hosting service and ask them if they could change the setting.
Related
I've created a module for my client's project that should send a file via FTPS onto a web-service. The web-service allows connection from some IP addresses only.
It works on my localhost, but some FTP-commands don't work on the client's live site.
For example, primarily I connect with ftp_ssl_connect. It works on the client's site.
Then, I log in with ftp_login. It also works on the client's site.
Then, I move to the passive mode with ftp_pasv. It also works on the live site.
But when I'm trying to get the files list with ftp_nlist command, it works on from my localhost but refuses to execute on the client's site.
Also, when I send a file with command ftp_put, it works on my localhost but refuses to work from the client's project.
$config = yrv_eboks_get_config_data();
$conn = ftp_ssl_connect($config->ftp_host, 21, 15);
if (ftp_login($conn, $config->ftp_login, $config->ftp_password)) {
if (ftp_pasv($conn, true)) {
$files = ftp_nlist($conn, ".");
var_dump($files);
}
} else {
// "Could not login via login via FTPS"
};
I don't know where is the problem and how to solve it.
Could you advise me, where can be the problem and what to do?
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
write this at the top of the file and access the php file your browser will display the error. are you sure these functions are enabled on your hosting? because shared server disable lots of function to prevent abuse for example source, symlink, ftp_put etc.
You can check which function is disabled by creating a phpfile using below code
<?php
phpinfo();
?>
save the above code as anyname.php then access it and you will see php information there. press ctrl+f (search) button and write disable_functions and there you will see all the disabled functions or create a file with the below code and access it from browser ( it may not work if your provider blocked ini_get function too)
<?php echo "Disabled functions: ".ini_get('disable_functions')."\n"; ?>
if your function is disabled you can enable them by creating php.ini file in your directory or request your hosting provider to enable them.
to enable function: create php.ini with following code
disable_functions = ""
however it may not works if your hosting environment is use default php.ini with priority so better contact with provider and request them to enable.
When I am upload a csv file with zipcode it will convert and save a latitude and logitude. The error occurring a convert a zipcode to lat,lng. In my localhost its working fine. When I am uploading in a live server. I am getting this error Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /hermes/bosnaweb05a/b1410/ipg.rwdinfotechcom/vw/zipmapping/index.php on line 29 . I have checked my google api key also. I can't able add php.ini file. If I upload php.ini file its shows internal server error.
Here my code
function getLnt($zip){
$url = "https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyDEGgYDar8y3Bx-1FpY3hq6ON4LufoRK60&address=
".urlencode($zip)."&sensor=false";
$result_string = file_get_contents($url);
$result = json_decode($result_string, true);
$result1[]=$result['results'][0];
$result2[]=$result1[0]['geometry'];
$result3[]=$result2[0]['location'];
return $result3[0];
}
First, check your PHP file with this code and then enable the fopen in your php.ini file
<?php
if( ini_get('allow_url_fopen') ) {
die('allow_url_fopen is enabled. file_get_contents should work well');
} else {
die('allow_url_fopen is disabled. file_get_contents would not work');
}
?>
Edit the php.ini file and enable using below code
allow_url_fopen = 1 //0 for Off and 1 for On Flag
Login to your Cpanel
Under Software click on MultiPHP INI Editor
demo
Click on Editor Mode and select Domain
demo
Paste allow_url_fopen = 1 and save
This solution worked for me as I couldn't access the php.ini file.
I added this function:
function curl_get_file_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
and use it instead of
file_get_contents($url)
and it worked.
The solution is better explained here, all credits to the creator of the post.
I had the same issue and I google this topic.
I could not update it from joomla direct 3.9.1 to 3.9.2 not even by uploading manually.
The reason was that before this update it forced me to upgrade php version to 7.2 so I did it from cpanel, now to solve next update will be this:
Login to cpanel
Find " MultiPHP INI Editor" under software
Choose your domain and select edit
Set :
"max_execution_time " to 90 (it was in mine 30)
"memory_limit" to 256M (it was by new php enabling 32M only !)
"post_max_size" to 100M
"upload_max_filesize" to 100M
...because every php new version is set to default.
Enjoy ;)
Try removing the lines below from .htaccess and switch to the latest version of PHP.
For me this was being caused by the following getting added to .htaccess:
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php70” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php70___lsphp .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Removing it solved the problem but it reappeared after an unknown period of time.
I noticed I was running (deprecated) PHP 7.0 and I changed it to (latest version) 7.4. I sent a support ticket to our hosting provider about the problem and they responded with:
If you've selected PHP 7.4 now, it shouldn't replace those lines any
longer, as that's what CloudLinux does - it forces the specific PHP
version to be loaded via .htaccess
It's not come back in the last hour so fingers crossed.
Try adding the Code below to your PHP File:
<?php
ini_set("allow_url_fopen", 1);
The Problem could probably be that on the Server, the PHP Setting for allow_url_fopen may have been configured differently: 0 for example. You could also do the same in your php.ini File if you have access to it.
Hope this helps....
I have multiple system running on PHP 5.3 that are 15-10 years old, I can't go on those and change anything.
Problem is: some of those system are using PHP register_globals = on that is depreciate on PHP 5.3 and doesn't even exist in PHP 5.4 (http://php.net/manual/en/security.globals.php).
I am developing a new system and would like to turn PHP register_globals = off But I can't because all those old system that NEEDS it.
So I thought about dynamically changing the register_globals to off in my script using string ini_set ( string $varname , string $newvalue ) but the documentation (http://php.net/manual/en/function.ini-set.php) baffles me a bit:
Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.
Does that mean that if I have two script running at the same time lets say... One of my old system that really needs register_globals = on and my new system that use ini_set() to register_globals = off that the old script will be running with the newly changed setting? Or will it keep the setting in my PHP.ini file and the new system will run on the ini_set() configuration?
--EDIT--
After some test (see code below) #Jacob was right and it seems PHP create a context for each script and that ini_set() only change the configuration of the script its in.
TestWithIni_Set.php
<?php
ini_set('register_globals', '0');
$i = 0;
while(true)
{
if($i == 0)
{
phpinfo();
}
$i++;
}
?>
TestWithoutIni_Set.php
<?php
phpinfo();
?>
So I ran TestWithIni_Set.php first, then will TestWithIni_Set.php was executing (the infinite while loop) I ran TestWithoutIni_Set.php.
Unfortunatly, it seams like I can't change register_globals value with ini_set(). I tried the following:
//Knowing that ini_set() parameters are strings I tried those anyway.
ini_set('register_globals', '0');
ini_set('register_globals', 0);
ini_set('register_globals', 'off');
ini_set('register_globals', 'Off');
ini_set('register_globals', false);
ini_set('register_globals', 'false');
Then to make sure I didn't had something wrong in my code I tried:
ini_set('log_errors', '0');
Just to see if it would work and it did. Then value of log_errors for the script with ini_set() was off and the value of log_errors for the script without ini_set() was on.
But now I have a different problem.
How can I change the value of register_globals for only the running script if I can't change it using ini_set()?
I added a .user.ini file to my new system dir with the only line being register_globals=off.
I also went and uncomment the following line in my PHP.ini file:
user_ini.filename = ".user.ini"
I also made sure only a local user had the rights to make changes to that dir. So somebody couldn't go and upload a new user define .ini file for my server within this dir.
For exemple: IIS user can only read the file in this dir and can't add/modify/remove any file.
I have changed php.ini's some value in php.ini file and also through php script like,
ini_set('upload_max_filesize', '10M');
ini_set('POST_MAX_SIZE', '10MB');
but when I am running phpinfo() it doesn't shows the updated value.
It shows
upload_max_filesize = 2M
I am wondering how it is possible??
Do you have access to your Apache configuration ?
Maybe theses parameters are overridden in the virtual host of the Apache configuration via php_admin_value. If this is the case, then you won't be able to change this value in the php script itself.
Also, check the following post : Changing upload_max_filesize on PHP
Good luck with that.
Firstly, it is very common for your environment to contain several php.ini files, where the one you're editing is not actually being used. Check php_info() output for the path to the loaded configuration file to double check.
If it's definitely correct, restart your web server and double-check it's still not loading.
If you still got no luck, have a look at the return values for ini_set():
if(ini_set('upload_max_filesize', '10M') === FALSE ||
ini_set('POST_MAX_SIZE', '10MB') === FALSE)
{
echo "Failed to set a configuration parameter.";
} else {
// These functions returned strings containing the old value.
}
Let us know what the above returns for you.
<?php
session_start();
if(isset($_SESSION["counter"])){
echo session_id()." ".$_SESSION["counter"];
$_SESSION["counter"]++;
}
else{
$_SESSION["counter"]=0;
echo "start counter";
}
?>
It's just a basic example code for session. It working find of my PC using XAMPP. But it doesn't work at all when I put it in to my vps webserver. The out put only include"start counter" and never changed whatever I refresh the page. I checked php.ini both on XAMPP and vps. variables_order = "GPCS" request_order = "GP" register_globals = Off session.save_handler = files Above configurations are same on XAMPP and vps.
It can be due to the reason that your session expires too fast on another server. Start by making sure you're setting the session variable correctly. It's possible that sessions either aren't enabled or aren't configured correctly in the php.ini file on your server.
You can try putting this in front of the file to see any errors. When you see the error you can figure out where you have gone wrong.
error_reporting(E_ALL);
ini_set('display_errors', 1);