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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.