Shehroz Ahmed
Shehroz Ahmed

Reputation: 537

Condition in PHP class

I have login.php and signup.php. Both send POST requests to the controller class.

How can I identify which script the request is coming from?

using isset($_POST['signup']) was working perfectly, but then

public function __set($name,$value)

in the signup() function gives an error.

<?php

class Controller{

    public $model;      
    private $full_name;
    private $email;
    private $password;
    private $user_name;

    public function __construct(){
        if(isset($_POST['signup'])){
            $this->full_name = $_POST['full_name'];
            $this->email = $_POST['email'];
            $this->password = $_POST['password'];
            $this->user_name = $_POST['user_name'];
        }
    }

    public function __set($full_name,$value){
    }
}

Upvotes: 0

Views: 81

Answers (2)

comment

But it gaves error unexpected public. I used this setter in a method in the class.

class methods go in the general class scope, not in functions.

class foo {
    public function __get() {
    }
}

comment

But both signup.php & login.php form is sending request to this class. So there are a lot of difference in the fields of them

it makes no sense that your controller is validating your fields in the constructor. Either make it a LoginController and SignupController, or have a separate class validate your inputs.

Upvotes: 1

DrLazer
DrLazer

Reputation: 3113

you can add a hidden input on your forms. for example on the login form you can add

<input type="hidden" name="requestType" value="login" />

and on the signup form

<input type="hidden" name="requestType" value="signup" />

then on your PHP script you can get the value of the hidden input

$_POST['requestType']

Upvotes: 1

Related Questions