Jump to content

PHP Session!


01hanstu

Recommended Posts

Hi,

I am trying to get the value of a session veriable and if the variable contains a certain word it will show an error message, else just continue as normal.

 

if (isset($_POST['selectroom']))
{$_SESSION['room'] = $_POST['selectroom'];}
if (!isset($_SESSION['room']))
$room = "RoomNameA";
else
$room = $_SESSION['room'];

 

Please Advise,

- Stuart

Link to comment
https://forums.phpfreaks.com/topic/218191-php-session/
Share on other sites

missing the curlies from the else there, try to keep to one standard, don't mix and match - bad practise.

 

use isset() then !empty() this proves as it's there and has state...

 

Ideally, you need to post more of the code so we can see what else is going on in there.

 

Rw

Link to comment
https://forums.phpfreaks.com/topic/218191-php-session/#findComment-1132211
Share on other sites

Personally I'd structure it like this:

 

if (!empty($_POST['selectroom']))
{
    $room = htmlentities($_POST['selectroom']);
    $_SESSION['room'] = $room;
}
elseif (isset($_SESSION['selectroom']))
{
    $room = $_SESSION['selectroom'];
}
else
{
    $room = "RoomNameA";
}

 

Perhaps drop the htmlentities call if you escape the value somewhere else.

Link to comment
https://forums.phpfreaks.com/topic/218191-php-session/#findComment-1132218
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.