[英]PHP Dynamic signup page
I wanted to create a dynamic signup.php. 我想创建一个动态signup.php。 The algorithm is as follow:
算法如下:
The problem I'm having right now is how am I going to check whether it's the first time user request for signup.php or not? 我现在遇到的问题是如何检查用户是否是首次请求signup.php?
Use isset() to check if $_POST contains data. 使用isset()检查$ _POST是否包含数据。
To answer your question, "how am I going to check whether it's the first time user request for signup.php or not?", honestly, probably for other users...... 要回答您的问题,“老实说,“我将如何检查这是否是用户首次请求signup.php?”……
There are a few ways, cookies, storing request ips in a database, bleh, bleh, bleh. Cookie有几种方法,可以将请求ips存储在数据库中,bleh,bleh,bleh。 But...... None of them are guaranteed.
但是……他们都不能保证。 The user can disable cookies, use a dynamic ip, etc. You could issue a unique hash and place it as a login.php?q=encValueForUniquePageRequest
用户可以禁用cookie,使用动态ip等。您可以发出唯一的哈希并将其放置为login.php?q = encValueForUniquePageRequest
but...... The architecture you laid out won't be practical. 但是……您布置的体系结构不实用。
Sorry :( 对不起:(
To check that request is POST: 要检查该请求是否为POST:
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
//process new user
}
?>
Example: 例:
<?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'));
}
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.