skip to Main Content

I want to display the login page before submitting the comment. When the user is not logged in and when he clicks on submit button it has to redirect to login page.. when the user is logged in the comment has to be posted. Here is the code.. Before user can comment if he is not logged in he has to redirect to login.php page.

<form action="" method="post">
          

 <div class="row">
                                <div class="col-md-12">
                                    <input type="hidden" class="form-control" id="email" placeholder="Name" name="name"  value="<?php echo $_SESSION['name'];  ?>" required>
                                </div>
                               <div class="col-md-12">
                                    <textarea  class="form-control" id="mes" name="mes" cols="30" rows="10" placeholder="Message"></textarea>
                                </div>


                                <div class="col-md-12 text-center">
                                <input type="submit" name="post" value="Post" class="texty" class="btn newspaper-btn mt-30 w-100"  style="border:1px solid black;">
                                </div>
                            </div>
                        </form>

2

Answers


  1. You can use the $_SESSION,
    check the following on your comment button

    if(!$_SESSSION['email']')
    {
    
    //display your login box 
    
    }
    
    Login or Signup to reply.
  2. You can try like this.

    if (isset($_POST['post'])) {
        if ($_SESSION['name'] == false) {
           // Go to login page.
           header('location:login.php');
        } else {
         // here your comment process.
       }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search