php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79609 Warning in session_create_id Example #1
Submitted: 2020-05-17 20:46 UTC Modified: 2020-05-20 18:13 UTC
From: software_onbekend at hotmail dot com Assigned:
Status: Duplicate Package: Session related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: software_onbekend at hotmail dot com
New email:
PHP Version: OS:

 

 [2020-05-17 20:46 UTC] software_onbekend at hotmail dot com
Description:
------------
---
From manual page: https://php.net/function.session-create-id
---
Warning: session_create_id(): Failed to create new ID in index.php on line 20.
Generating new session id is not allowed when the session is already started.

Also at line 16, the if statement need an integer because the output of session_status is an integer.
https://www.php.net/manual/en/function.session-status.php
Can the documentation for the "session-status" also be updated with the integer return values?
 
The example also uses "session_commit()", this is an alias of "session_write_close", wouldn't it be better to use "session_write_close" instead of "session_commit" ?
https://www.php.net/manual/en/function.session-commit.php

Have a nice day



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-05-17 21:59 UTC] requinix@php.net
-Status: Open +Status: Feedback -Package: Documentation problem +Package: Session related
 [2020-05-17 21:59 UTC] requinix@php.net
Are you sure you're looking at https://www.php.net/manual/en/function.session-create-id.php?
Because,

> Warning: session_create_id(): Failed to create new ID in index.php on line 20.
> Generating new session id is not allowed when the session is already started.
The example is working for me.

> Also at line 16, the if statement need an integer because the output of session_status is an integer.
It does that already.

> Can the documentation for the "session-status" also be updated with the integer return values?
It does that too.

> The example also uses "session_commit()", this is an alias of "session_write_close", wouldn't it be
> better to use "session_write_close" instead of "session_commit" ?
The alias is not deprecated, but it probably would be better, yes.
 [2020-05-17 21:59 UTC] a at b dot c dot de
For the first question: The sample code is working fine for me.

What version are you using?

Do you perhaps have session.auto_start enabled?

For the second question: PHP_SESSION_ACTIVE is an integer.
 [2020-05-18 17:21 UTC] software_onbekend at hotmail dot com
The def. environment is PHP 7.4.3 (xamp installation on Windows).
session.auto_start = "Off".
"display_errors" and "display_startup_errors" values are "On".
Here I get the warnings.

Tested example in prod. environment with PHP 7.3.17.
session.auto_start = "Off"
No warning because the most hosted platform has the "display_errors" and "display_startup_errors" at "Off" so the warnings and errors are suppressed. No output to webbrowser.

About the session-status.
echo session_status; gives int. as answer in the browser (values 0 or 1 or 2)
The explanation of the return values doesn't explain the link between these values 0, 1 & 2.
The contributed note from "sasi dot viragelet at gmail dot co" gives the answer.
Perhaps we can use that info to improve the documentation.

Just my 2 cents.
Have a nice day.
 [2020-05-18 18:17 UTC] requinix@php.net
> Here I get the warnings.
Exactly what are they?

> The explanation of the return values doesn't explain the link between these values 0, 1 & 2.
Use the constants. If you want something you can read, use the constants to output human friendly strings like "active".
 [2020-05-18 19:03 UTC] software_onbekend at hotmail dot com
Exact warning: from def. environment:
Warning: session_create_id(): Failed to create new ID in E:\xampp\htdocs\8\index.php on line 20
 [2020-05-18 21:14 UTC] requinix@php.net
The only way I see session_create_id failing is either (a) you don't have good enough crypto, or (b) you're using a custom session handler that's not behaving well.

So what are you session settings?
 [2020-05-19 15:59 UTC] software_onbekend at hotmail dot com
Session Support				enabled
Registered save handlers		files user
Registered serializer handlers		php_serialize php php_binary

Directive				Local Value		Master Value
session.auto_start			Off			Off
session.cache_expire			180			180
session.cache_limiter			nocache			nocache
session.cookie_domain			no value		no value
session.cookie_httponly			no value		no value
session.cookie_lifetime			0			0
session.cookie_path			/			/
session.cookie_samesite			no value		no value
session.cookie_secure			0			0
session.gc_divisor			1000			1000
session.gc_maxlifetime			1440			1440
session.gc_probability			1			1
session.lazy_write			On			On
session.name				PHPSESSID		PHPSESSID
session.referer_check			no value		no value
session.save_handler			files			files
session.save_path			E:\xampp\tmp		E:\xampp\tmp
session.serialize_handler		php			php
session.sid_bits_per_character		5			5
session.sid_length			26			26
session.upload_progress.cleanup		On			On
session.upload_progress.enabled		On			On
session.upload_progress.freq		1%			1%
session.upload_progress.min_freq	1			1
session.upload_progress.name		PHP_SESSION_UPLOAD_PROGRESS	PHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefix		upload_progress_	upload_progress_
session.use_cookies			1			1
session.use_only_cookies		1			1	
session.use_strict_mode			0			0
session.use_trans_sid			0			0

I hope, this is the info you asked for.
Have a nice day.
 [2020-05-19 23:35 UTC] requinix@php.net
The settings look fine, in that you're using the regular files handler.

But I find it hard to believe the crypto is the problem. Are you able to use random_bytes() without problems?
 [2020-05-20 08:48 UTC] cmb@php.net
This is most likely a duplicate of bug #79413, which is fixed as
of PHP 7.3.17 and 7.4.5, respectively.
 [2020-05-20 17:43 UTC] software_onbekend at hotmail dot com
Yesterday evening I discovered that Example #1 was working correctly on an older version op XAMPP (PHP 7.2.9)(other pc)
Updated my current XAMPP with PHP 7.4.6.
Example works fine.

Thank you both for your time and support.
 [2020-05-20 18:13 UTC] requinix@php.net
-Status: Feedback +Status: Duplicate -Type: Documentation Problem +Type: Bug
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Aug 19 11:05:45 2022 UTC