Php session error and header function can not work


#1

Continuing the discussion from I am getting php session error. They are not enable in server:

This topic very old, but I have same problem just now.
I’m both paying user and free user.
I can run an application in paying environment, but cannot in 000webhost.
That may be because of PHP version and session.save_path’s access control.
Here is a sample code.
Is there anyone who can solve this problem?

===== sample code =========

<?php ini_set("display_startup_errors", 1); ini_set("display_errors", 1); /* Reports for either E_ERROR | E_WARNING | E_NOTICE | Any Error*/ error_reporting(E_ALL); if(!isset($_SESSION)){ session_start(); header("Location: http://www.google.com/"); exit; } ?> TEST

TEST

=========================

Warning: session_start(): >open(/storage/h1/859/500859/tmp/sess_8majrg7evracfvc34bo7cbt9ko, O_RDWR) >failed: No such file or directory (2) in >/storage/h1/859/500859/public_html/store/cookie.php on line 2
Warning: session_start(): Failed to read session data: files (path: >/storage/h1/859/500859/tmp) in >/storage/h1/859/500859/public_html/store/cookie.php on line 2

The problem is about the php session. They are not enable on my server. How >can i enable it and i a free hosting user


#2

Do you have a folder named tmp outside the public folder

Try php_flag output_buffering on

In your . htaccess?


#3

Thank you.
I did three things.

  1. Make tmp directory by same level to public_html
  2. call ob_start(), before start_session();
  3. downgrade PHP to version 5.6

Anyway, my application is working now.