我想创建一个动态的signup.php。算法如下:
的
我现在遇到的问题是如何检查这是否是第一次用户请求signup.php?
答案 0 :(得分:1)
使用isset()检查$ _POST是否包含数据。
答案 1 :(得分:0)
要回答你的问题,“我怎么去检查这是否是第一次用户请求signup.php?”老实说,可能是其他用户......
有几种方法,cookie,在数据库中存储请求ips,bleh,bleh,bleh。但是......他们都没有保证。用户可以禁用cookie,使用动态IP等。您可以发出一个唯一的哈希并将其作为login.php?q = encValueForUniquePageRequest
但......你布置的架构不实用。
抱歉:(
答案 2 :(得分:0)
要检查该请求是否为POST:
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
//process new user
}
?>
示例:
<?php
Class signup_controller extends controller{
private $data = array();
private $model = array();
function __construct(Core $core){
parent::__construct($core);
/* load models - assign to model */
$this->model['page'] = $this->core->model->load('page_model', $this->core);
$this->model['auth'] = $this->core->model->load('auth_model', $this->core);
/* check script is installed - redirect */
if(empty($this->core->settings->installed)){
exit(header('Location: '.SITE_URL.'/setup'));
}
}
function index(){
/* do signup - assign error */
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if($this->model['auth']->create_user(1)===false){
$this->data['error'] = $this->model['auth']->auth->error;
}
}
/* not logged in */
if(empty($_SESSION['logged_in'])){
/* assign form keys */
$_SESSION['csrf'] = sha1(uniqid().(microtime(true)+1));
$_SESSION['userParam'] = sha1(uniqid().(microtime(true)+2));
$_SESSION['passParam'] = sha1(uniqid().(microtime(true)+3));
$_SESSION['emailParam'] = sha1(uniqid().(microtime(true)+4));
/* get partial views - assign to data */
$this->data['content_main'] = $this->core->template->loadPartial('partials/signup', null, $this->data);
$this->data['content_side'] = $this->core->template->loadPartial('about/content_side', null, $this->data);
/* layout view - assign to template */
$this->core->template->loadView('layouts/2col', 'content', $this->data);
}
/* signed in - redirect */
else{
exit(header('Location: ./user'));
}
}
}
?>