Click here to Skip to main content
15,565,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Working with core php, Using ob_start with session is gets complicated.

First Page

<?php 

session_start();
ob_start();

$_SESSION['mobile'] = "98057*****";

header("location:$nextPageUrl");

?>



Next Page

<?php
echo $_SESSION['mobile'];
?>


*It seems like $_SESSION['mobile'] does not have any value on next page. What is causing this ?


What I have tried:

Solution I already used is:
 - ob_clean() added after header().
 - ob_flush() added after header().
 - ob_end_clean() added after header.
 - ob_end_clean() at the end of the page.

But getting same problem. Any suggestions and help will be 
appreciated.
Posted

1 solution

Hello !

just make the ob_start before session_start.

PHP: session_start - Manual[^]

this case is fixed when you know that ob_start() is a new buffer creation, like does session_start()...
it's a conflict about buffer resources.
ob_start() maje the buffer area empty, so the session vars are deleted..
ob_start();
session_start();
 
Share this answer
 
v2
Comments
Satish Thakur 2022 21-Oct-22 5:11am    
putting ob_start() above not working, On the same page session giving value but not on another page. I'm still stuck :(
Do I need to use ob_clean() somewhere on page ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900