Display invoice message before generating new session id

hi all

when user completes checkout he is redirected to checkout success page

on reaching checkout_success page i want to show user the message

<?php 
echo "your checkout is complete and your invoice number is 1234 etc"
?>

on this checkout success page i want to regenerate session id also

this above message contains invoice number which is fetched from database but will be of previous session.

this below code works fine and generates new id

<?php
session_start();
session_regenerate_id(true);
$_SESSION=array();
?>

But the problem is the above code works only if inserted on top of page.

if i insert it in the bottom or footer then i get this error

Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent

this invoice number message should stay there till user browse to another page.

if user hits back button or browser to another page then he should not see any previous session data.

If i insert the above code on top of my checkout_success page then the new session id is generated

but message is not displayed because he gets redirected to homepage because new session id is generated and old gets destroyed.

i know headers already sent error occurs when we echo something before header redirect

But i want to echo the message about order completion on checkout_success page before regenerating session id.

if i redirect user without showing the message then he will wonder what happened to his order, why was he redirected to homepage.

also i want to display message till user navigates to any other page

vineet

I’m not sure what your goal is here. Do you want to destroy the session? In that case you should use session_destroy and not session_regenerate_id. You use session_regenerate_id to keep the session but give it a new ID, to avoid session fixation for example.

thanks scallioXTX

i will try it

vineet

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.