post - PHP Dynamic signup page


I wanted to create a dynamic signup.php. The algorithm is as follow:


  1. when signup.php is requested by client, the code will attempt to check whether user send any data in $_POST.
  2. if $_POST does not contains any data (means it's the first time user request for signup.php), a signup form will be return to the user, allowing user to enter all his/her details and again send back to signup.php through submit button.
  3. if $_POST does contains data (means user has fill up the signup form and is now sending all the data back to signup.php), then the php code will attempt validate all those data and return result showing user has been successfully registered or error if failed to do so.

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?




Use isset() to check if $_POST contains data.




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......

There are a few ways, cookies, storing request ips in a database, 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

but...... The architecture you laid out won't be practical.

Sorry :(




To check that request is POST:

   //process new user


Class signup_controller extends controller{
    private $data = array();
    private $model = array();

    function __construct(Core $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 */
            exit(header('Location: '.SITE_URL.'/setup'));

    function index(){
        /* do signup - assign error */
        if($_SERVER['REQUEST_METHOD'] == 'POST'){
                $this->data['error'] = $this->model['auth']->auth->error;

        /* not 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 */
            exit(header('Location: ./user'));


People are also looking for solutions to the problem: php - Custom querystring-based routing in CodeIgniter or Phalcon


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.