[英]user photo on comment if logged in
I am making a comment function on a design view page and I just have a single question about displaying a picture if a user is registered. 我正在设计视图页面上执行评论功能,如果注册了用户,我只是有一个关于显示图片的问题。
I want to display a users profile picture if he/she is logged in. What is the best way to do this? 如果他/她已登录,我想显示他的个人资料图片。执行此操作的最佳方法是什么? Can I set an
<input type="hidden" name="userid" value="1" />
and autofill the name input field on the comment form if the user is logged in, or what is the best approach to do this? 如果用户已登录,是否可以设置
<input type="hidden" name="userid" value="1" />
并在评论表单上自动填写名称输入字段,或者最好的方法是什么?
When a user log in the following fields a set in the login function: 用户登录以下字段时,将在登录功能中进行设置:
$_SESSION["user_id"] = $row["user_id"];
$_SESSION["user_name"] = $row["name"];
$_SESSION["user_logged_in"] = 1;
When a comment are posted by are non-registered or non-logged-in user, a silhouette will be displayed instead of a normal picture. 当非注册用户或未登录用户发表评论时,将显示剪影而不是普通图片。
why don't you simply put if..else 你为什么不简单地把if..else
To add name of user logged in you can simply store his/her name into $_SESSION['name'] and display it name input field of comment box and if you do not want to let them change a name you can disable input field. 要添加已登录用户的名称,您只需将其名称存储在$ _SESSION ['name']中并在注释框的名称输入字段中显示它,如果您不想让他们更改名称,则可以禁用输入字段。
Follow the code given below : 请遵循以下代码:
if($_SESSION['user_logged_in']==1) {
//show the proper profile pic of user along with name in name input field.
<img src="$path_to_profile_pic" height="anything" width="anything" />
<input type="text" name="name" value="<?php echo $_SESSION['name']; ?>" disabled="disabled" />
}else{
// show silhouette image along with name Anonymous.
<img src="$path_to_silhouette _pic" height="anything" width="anything" />
<input type="text" name="name" value="anonymous" />
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.