Session does not start in php via htaccess

Asked

Viewed 476 times

1

I am trying to log in to . htaccess using php_value session.auto_start 1 to avoid line duplications in php codes.

But this is not working, informs that is always off?

1 answer

4

Note: in case the author is experiencing the free version of Hostinger, which is probably limited and lacks full support (I can’t say, it’s an assumption) and this seems to be the reason for the problem

I believe the command is php_flag and not php_value, example:

php_flag session.auto_start 1

To test create an empty file called teste.php in the same folder as .htaccess with this content:

<?php
var_dump(session_id(), $_SESSION);

Must return something like:

string(26) "jgg7lol8o97733q3vgs46tm7p5" array(0) { }

This means it’s working.

Workaround

If this doesn’t work you can do the following, create a file called global.php, in it add the following content:

<?php
if (session_id() === '') {
    session_start();
}

And include this file in all necessary files, for example the file index.php

<?php
require_once 'global.php';
?><!DOCTYPE html>
<html>
<head>
Resto do html...
  • 1

    @6paq Being a server, the reason should be they disabled, because if I am not mistaken this module consumes a little more of the server, I edited the answer, try the alternative solution.

  • So I guess that’s the problem, even the amount of access to Stinger limits it. I will do it in an alternative way and when I hire the definitive server I change the codes. obg!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.