I am using sessions to send a success or error message to the next site where I use an include php file to show that message.
because of any reason, the message.php file isn't able to refer to the sessions I set before.
For example: The login script sets sessions depending whether the login was successful or not. Then it redirects you to the next page, where I use message.php
as an include to every site I have. This is supposed to show an message on every site, when sessions got set before.
<?php
session_start();
if (isset($_SESSION['msgType']) AND isset($_SESSION['msgMessage'])) {
if ($_SESSION['msgType'] != "" AND $_SESSION['msgMessage'] != "") {
if ($_SESSION['msgType'] == "error") {
?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Fehler!</strong> <?php echo $_SESSION['msgMessage']; ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<?php
} elseif ($_SESSION['msgType'] == "warning") {
?>
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<strong>Warnung!</strong> <?php echo $_SESSION['msgMessage']; ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<?php
} elseif ($_SESSION['msgType'] == "success") {
?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Erfolg!</strong> <?php echo $_SESSION['msgMessage']; ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<?php
}
}
}
$_SESSION['msgType'] = "";
$_SESSION['msgMessage'] = "";
?>
<?php
session_start();
$_SESSION['msgType'] = "success";
$_SESSION['msgMessage'] = "some message";
?> <script> window.location = "some URL"; </script> <?php
exit;
The first code is the message.php file where sessions are translated in messages. The second code is a piece of the login script. Where a session is set and you get redirected.
Because of any reason no message gets displayed at all. Can you see any problem in my code?
Also, if someone can tell me, why I can't use header('Location: URL')
for redirection and have to use <script> window.location = "some URL"; </script>
instead, just let me know pls.