【发布时间】:2017-06-14 08:38:04
【问题描述】:
这是我的 html 代码:
<div id="view" class="login-box animated fadeInUp"<?php if ($reg===true){?>style="display:none"<?php } ?>>
</div>
<div id="popup"<?php if ($reg===false){?>style="display:none"<?php } ?>>
</div>
这是我的 php 代码的一部分:
<?php
ob_start();
session_start();
error_reporting( ~E_DEPRECATED & ~E_NOTICE );
$conn = mysqli_connect('localhost','root','','slide-uploader');
if ( !$conn ) {
die("Connection failed : " . mysqli_connect_error());
}
$error = false;
$reg = false;
/*Verifico i campi della form*/
if ( isset($_POST['submit']) ) {
$email = trim($_POST['user_email']);
$email = strip_tags($email);
$email = htmlspecialchars($email);
$mailValidation = explode('@',$email)[1];
$matricola = trim($_POST['user_matricola']);
$name = ucfirst(explode('.',$email)[0]);
$surname = ucfirst(preg_replace('/[0-9]+/', '', explode('@',explode('.',$email)[1]))[0]);
$queryS = "SELECT * FROM studente WHERE Matricola ='$matricola'";
$resS = mysqli_query($conn,$queryS);
$count = mysqli_num_rows($resS);
if($count<1){
$query = "INSERT INTO studente (Matricola, Nome, Cognome, User) VALUES('$matricola','$name','$surname','$email')";
$res = mysqli_query($conn,$query);
}else{
some code...
}
if ($res) {
some code...
unset($email);
$reg = true;
some code...
} else {
some code...
}
}
}
ob_end_flush();
?>
我登录用户,然后返回上一页(window.history.go (-1)),但$reg 似乎没有设置。
我应该如何在 html 页面中设置 $reg 变量? html页面和php页面是两个独立的文件。
我应该使用变量$ _SESSION吗?
【问题讨论】:
-
当您说
$reg variable in the html page?时,您是指.html 文件吗? PHP 不能在 html 文件中运行。 -
@Andreas 实际上可以将您的服务器配置为将 .html 文件解析为 PHP。但不推荐。
-
您的代码容易受到 SQL 注入的影响,您需要解决这个问题。
-
@StuntHacks 这听起来很奇怪。实在看不出来这有什么意义。我的意思是你只需要将文件从 .html 重命名为 .php
-
@Andreas 我知道。我不知道为什么有人会这样做。只是想说,这确实是可能的。