Jump to content

Session on page


oz11

Recommended Posts

 

Hey.. i have this code. Though the form is shown on the page after entering the password, and its gone as desired when I reload the page.. how do I get it to not show on the next page before having to reload??

$room = $_GET['room'];
$salt = 444422;
if($_SESSION['in_chat']!=$room.$salt){
    $stmt = $pdo->prepare("SELECT pass_code FROM `chatrooms` WHERE name =?");
    $stmt->execute([$_GET['room']]); 
    $pass_checker = $stmt->fetch();

    $hash = $pass_checker['pass_code'];
    if($hash!=null AND $_SESSION['in_chat']!=$room.$salt){
    ?>
        <form action="" method="POST" name="passcheck">
        <input type="password" name="password_"><input type="hidden" name="chat_pass"><input type="submit" value="Submit"></form>
    <?php
    }   
    if(isset($_POST['password_'])) {
        if(!password_verify($_POST['password_'], $pass_checker['pass_code'])) {
            echo "Wrong password";
            exit;
        }  else{
           $_SESSION['in_chat'] == $room.$salt; 
        }
    } else{
        exit();
    }
}

Note: "salt" is just there so i can test the sessions without resetting.

Thanks!

Link to comment
Share on other sites

Dunno how helpful this is, but if I were you I would put all the relevant PHP code before the HTML so I didn't keep breaking in and out of it.

I suppose the reason why the form is showing on the next page is that it's in the HTML, but someone with more experience may have a better solution.

Link to comment
Share on other sites

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.