在php中提交评论之前显示登录页面 [英] Display login page before submitting the comment in php

查看:47
本文介绍了在php中提交评论之前显示登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在提交评论之前显示登录页面.当用户未登录时,当他单击提交"按钮时,它必须重定向到登录页面.这是代码..如果用户未登录,则必须先重定向到login.php页面,然后才能发表评论.

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>

推荐答案

您可以尝试这样.

if (isset($_POST['post'])) {
    if ($_SESSION['name'] == false) {
       // Go to login page.
       header('location:login.php');
    } else {
     // here your comment process.
   }
}

这篇关于在php中提交评论之前显示登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆