0

I am not able to set php session

for starting the session I am using below code

session_start();
$_SESSION['username'] = $username;

For checking the session I m using

<?php
if (!isset($_SESSION['username'])) {
header('Location: index.html');
}
?>

But the session is not being set as I am not able to grep it. Please help urgent.

4
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by IIM
0

If you try to make a session after you have sent text you'll get a message like this:
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at
Is that your problem? If you're receiving an error message, please show it.

0

No I am not geeting any error. I am simply redirected to index.html page

0

Print the session variable and see,i think so $username is empty,that's why it is behaving like this.
Do one thing:-
echo $username;
and after setting into session,i.e.,
$_SESSION['username'] = $username;
echo $_SESSION['username'];
If this is also showing correct ,then the probleem is this:-
<?php
session_start();
if (!isset($_SESSION['username'])) {
header('Location: index.html');
}
?>

As the example you are showing doesn't start the session.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.