PHP 5.4 sessions not working correctly - php

I recently switched over from PHP 5.3 to 5.4 and now my sessions are not saving correctly. I am getting errors saying that the location of the session folder does not exist but when I check my phpinfo(), it is the correct location. Also, I am unfortunately using godaddy for my hosting so I cannot access my php.ini file. I have stated session_start() on every page, I tried setting the save path to something else and that got rid of the errors but after that the sessions still were not saving.
Here is one of the errors.
Warning: session_start(): open(D:\Temp\php\session\sess_c6p2sphcn5m00g4ev48vfmj3h4, O_RDWR) failed: No such file or directory (2) in D:\Hosting\12059488\html\log.php on line 4

I don't have an answer for this problem yet, but here is what I have learned so far:
In Godaddy shared hosting, you do not have access to "D:\Temp\php\session", which is the default location where PHP will try to use to store its session data.
You can create a folder in root of your own directory (e.g. tmp), give write access to web server and make it unreadable from web (using File Manager), then in your PHP code before "session_start();" add something like this:
session_save_path("D:\Hosting\12059488\html\tmp");
Even this may file if you are using the new "Web Hosting" plans (in contrast to "Classic" plans) as Godaddy says these new plans do not support sessions and shared files.

Related

Drupal broken site after settings.php change

While I was working on a drupal site I encountered a critical error, I tried to edit settings.php file (for changing database credentials) but when I saved the file (I use register.it control panel) i received an XMLRPC fault error, now when I browse my site it shows installation page and nothing else.
Do some of you know what happened and how to restore it?
I tried to rename the file default.settings.php but it says that there is already a settings.php file (that I can't see anyway )
If you see installation page that means that Drupal is not aware of existing database (can't connect to it) so it want to start new installation - setup new database.
So if database is ok problem must be in your settings file: bad credentials (i.e. maybe you can't use "localhost" for host but something host company provided) or file it self is not accessible (insufficient permissions?)

IIS Plesk Shared Hosting Wordpress started to give 500.50 error out of nowhere for some files

I have my Wordpress on Shared IIS hosting using Plesk. Today, just by itself, some of my uploaded files started to give this error:
HTTP Error 500.50 - URL Rewrite Module Error. The page cannot be
displayed because an internal server error has occurred.
Most likely causes: IIS received the request; however, an internal
error occurred during the processing of the request. The root cause of
this error depends on which module handles the request and what was
happening in the worker process when this error occurred. IIS was not
able to access the web.config file for the Web site or application.
This can occur if the NTFS permissions are set incorrectly. IIS was
not able to process configuration for the Web site or application. The
authenticated user does not have permission to use this DLL. The
request is mapped to a managed handler but the .NET Extensibility
Feature is not installed.
Things you can try: Ensure that the NTFS permissions for the
web.config file are correct and allow access to the Web server's
machine account. Check the event logs to see if any additional
information was logged. Verify the permissions for the DLL. Install
the .NET Extensibility feature if the request is mapped to a managed
handler. Create a tracing rule to track failed requests for this HTTP
status code. For more information about creating a tracing rule for
failed requests, click here.
The interesting thing is that, when a file is uploaded, it's other dimension versions are created, and I have no problem accessing those. But when I try to access the original file, I'm getting that error. When I try to inspect file permissions on my Plesk control panel, the wp-content and the uploads folder does have the write permission to my user, but when I check the problematic file, Plesk can't access it from the control panel too:
Unable to get the object (C:\Inetpub\vhosts\PATH-TO-MY-IMAGE) security
info: (5) Access is denied. at execute "C:\Program Files
(x86)\Parallels\Plesk\admin\bin\filemng.exe" MY_USER_NAME
--permissions --list-common "--file=C:\Inetpub\vhosts\PATH-TO-MY-IMAGE"
"--accounts=tmpB575.tmp"(RunTime::RunAsUser::run line 260) (Error code
1)
---------------------- Debug Info -------------------------------
I can't even read the permissions on that file. Trying to delete the file using FileZilla results in an error too. This happened to SOME files today, and NOT to others, regardless of upload order, file name or type.
I've checked out many pages regarding this, but they all point to one thing: editing PHP.ini file to change the upload folder. After some search I've created a new PHP.ini like this:
upload_tmp_dir = "C:\Inetpub\vhosts\PATH_TO_A_FOLDER_THAT_I_CAN_WRITE_TO_IN_MY_HTTPDOCS_FOLDER"
Uploaded it to my httpdocs folder, restarted my app pool from Plesk, but no avail. I try uploading new files and I still get the same error. What I haven't understood is that why this started happening today and why is this happening completely randomly (I haven't changed any setting, I haven't entered into any settings pages for weeks). Is this something related to my configuration or should I contact my hosting provider?
It turned out to be a problem with my hosting company at their side. There was nothing I could do.

failed to open stream: no suitable wrapper could be found

hello i am implementing php files from one website into another and here is the following error message i am getting when trying to open the following page with implemented php files:
http://www.holidaysavers.ca/europe-destinations-canada.php
basically the php files i am importing from one website into another are identical , however they work on the original website but when i implement them into a new website it does not work anymore.
could you assist me in trying to get this resolved?
thank you
You can't include a PHP script that is on an external website/server into your local script - unless you enable allow_url_include on your php.ini (if you have access to it)
Instead, you can let that website/server render the page and get the resulting html output on your local script.
Replace this line in your script:
include('http://www.holidaysavers.ca/europe-canada.php?detour');
With this:
echo file_get_contents('http://www.holidaysavers.ca/europe-canada.php?detour');
Could you post the code from "europe-destinations-canada.php"? It looks like the script is asking to do stuff that's not configured in your php setup on this new site/server
I don't really know what kind of host you are using or if you are using Xampp, I do have an easy fix to it, for xampp and possibly other web server software. Go to your php.ini file, which you can search for or just look for it in c:\\xampp\php\php.ini, the php.ini should be in the php folder in the server software folder. Now search for allow_url_include in the php.ini file and than replace Off with On, if it isn't already on or something. This is most likely the fix because it worked for me.
I might be able to help further if I know if you are using a hosting or home server. If you are using a hosting website than please share what kind of hosting service you are using so I could inspect it further.
Using as example a random remote php file.
The goal is to use this remote file locally, make sure it hasn't change or be altered. The remote file will be downloaded one time only.
Hard coding the sha256 signature avoid to use the network on startup. This is just a base that can be turned to many scenarios, like checking for updates, depending your needs.
<?php
$lib_url = "https://raw.githubusercontent.com/getopt-php/getopt-php/master/src/CommandInterface.php";
$lib_filename = basename($lib_url);
// SHA256 signature
$lib_signature = hash_file("sha256",$lib_url); // "dba0b3fe70b52adbb8376be6a256d2cc371b2fe49ef35f0c6e15cd6d60c319dd"
// Hardcode the signature to avoid a network call on startup:
//$lib_signature = "dba0b3fe70b52adbb8376be6a256d2cc371b2fe49ef35f0c6e15cd6d60c319dd";
if (!is_file($lib_filename) || $lib_signature != hash_file("sha256",$lib_filename)){
// No local copy found, or file signature invalid, get a copy
copy($lib_url, $lib_filename);
}
require $lib_filename;
It is very useful if you intent to share a program as a single file, without composer.
For the case of a file hosted on Github, an ETag HTTP header is provided, it can be used to avoid to download the whole file.
php -r 'var_dump(json_decode(get_headers("https://raw.githubusercontent.com/getopt-php/getopt-php/master/src/CommandInterface.php", 1)["ETag"]));'
//string(64) "c0153dbd04652cc11cddb0876c5abcc9950cac7378960223cbbe6cf4833a0d6b"
The ETag HTTP response header is an identifier for a specific version
of a resource. It lets caches be more efficient and save bandwidth, as
a web server does not need to resend a full response if the content
has not changed.
Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/content/91/8151691/html/HolidaySavers.ca/europe-destinations-canada.php on line 52
says it all. I believe this is called XXS. It appears you're attempting to include a URL based file which is denied in your server configuration which is either one of two things.
You're attempting to include the file on site B from site A which you would then use instead of include('WhateverFile'); file_get_contents('WhateverFile'); however this will only return the client side data as it is an HTTP request;
You've duplicated the file on site B and forgot to update the domain configuration. Be sure that the include path reflects the site you're running the script on ie.
include(dir($_SERVER['SCRIPT_FILENAME']) . DIRECTORY_SEPARATOR . 'WhateverFile.php');
In any case. I would have to actually examine the line 52 on the said file to see why PHP is complaining to you in detail lol

500 internal server error or blank accessing php files

I keep getting either 500 internal server error or blank page when trying to access a php file in localhost, depending on the file.
I know this might be a recurrent problem but I can't find the solution.
I reinstalled a local website that basically access a mysql database. It worked in this computer before, so I assume the code is OK. I already reinstalled the database also.
Phpinfo.php is working.
I've seen that usually is a permission problem, I already set everything to 755 and the owner of the files is "root".
I don't use a .htaccess file and I've enabled the mod_rewrite which I've seen also can cause this problem.
Any hints?
session_is_registered() was deprecated in php 5.3, and removed in php 5.4. Using session_register(), session_unregister() and session_is_registered() was discouraged for a long time.
Your code should simply use the $_SESSION superglobal, it is persisted between requests and available in scripts after calling session_start().
If you want to know if you session has a given variable, simply do an isset for the array key:
isset($_SESSION["key"])

How to handle this "session failed to write file" error in PHP?

I am using the Kohana 3 framework, and am using the native session driver.
For some reason, occasionally the sessions fail to write to their file.
Warning: session_start() [function.session-start]: open(/tmp/sess_*****, O_RDWR) failed: Permission denied (13) in /home/site/public_html/system/classes/kohana/session/native.php on line 27
I am pretty sure Kohana has its own in built error handler, but it is not triggered with this error (i.e. it shows up like a normal PHP error, not the Kohana error).
(source: alexanderdickson.com)
Anyone that has ever used Kohana will notice this seems to have bypassed Kohana's error handling (perhaps set with set_error_handler()).
Is there anyway to stop this error from appearing without switching from the native session (i.e. file based) driver?
Should I just give good practice the boot and prepend an # error suppressor to session_start() in the core code of Kohana? Should I relax the error_reporting()?
Thanks
You call ini_set('session.save_path', APPPATH.'sessions') (replace APPPATH.'sessions' with the directory you want) in bootstrap.php to force sessions to be written to application/sessions. This will increase the security of using native sessions and should solve your issue.
It's up to php's session.save_path directive, you can override it to some writable folder in php.ini, or you can try this in your .htaccess;
php_value session.save_path '/path/to/folder/you/can/write'
Edit: just so I don't forget, put your custom session folder level below the htdocs/public_html/whatever.
Although, all this is a little overkill since you can ask your server admin politely to check what's the problem with permissions.
This means your php interpreter has no write permissions in /tmp.
Ask your server administrator to fix that - it's unrelated to your app.
In case there are collisions with session files from different php processes (running under different users): Giving them different session temp dirs would help.
For example, you could move them away from /tmp to /path/to/homedir/phptmp and use a structure like that:
/path/to/homedir/
/path/to/homedir/htdocs
/path/to/homedir/phptmp
/path/to/homedir/logs

Categories