0

When user come to site by link with activation code, his account activated (changed value in DB) and I want show some info message. For this I reload page with $_SESSION['message'] = "activated" (same time removing activation code from URL). Info message block code:

<? if ($_SESSION['message'] === "activated") { 
ShowAlert('ActivatedOk-popup');

echo '
<div id="ActivatedOk-popup" class="info-popup">
<div class="popup-info-wrapper"><div class="leaflet-popup-close-button">×</div>
    <div class="popup-header">'.ACTIVATION_POP_HEADER.'</div>
    <div class="popupRecord1">
               <p>'.ACTIVATION_POP_TEXT1.$_SESSION['name'].ACTIVATION_POP_TEXT2.'</p>
    </div>
    <button class="popup-btn close_but">'.ACTIVATION_POP_BTN.'</button>
</div>
</div>';

unset($_SESSION['message']);
}
?>

But I can't understand why this pop-up doesn't appears. If I remove last line: $_SESSION['message'] = ""; everything work well, but Message variable isn't empty, and each page appears pop-up. How correctly show pop-up and then unset variable?

user2443795
  • 144
  • 7

2 Answers2

0

you got to start/initialize a session *session_start();* before trying to use any session variable. check by echoing your $_SESSION['message'] once after initializing


<? session_start(); //echo $_SESSION['message'];
?>

gursahib.singh.sahni
  • 1,559
  • 3
  • 26
  • 51
0

Your code is theoretically correct. Like the comment of anonymous states you should use session_start(); to make sure the session is active. (See PHP ini setting session "autostart" - the setting may vary on different servers).

Regarding your code: I would recommend not to use short open tags (because these may be not allowed on different configurations).. and I would recommend checking if the session varialble exists before checking for its contents, to avoid uneccessary notices, e.g.:

<? if (isset($_SESSION['message']) && $_SESSION['message'] === "activated") { 
     // foo
 }
?>

Having said that. Your problem most likley is in the function ShowAlert(). Do you mind sharing some details?

Jan.
  • 1,925
  • 15
  • 17
  • Problem definitely not in function, because in page code doesn't appears html that should be printed by echo. If remove function, it doesn't work too. – user2443795 Jun 01 '13 at 19:13