Activating account with php oop language


If the information is coming as part of the URL, you will surely need to use $_GET rather than $_POST?


That's what I was thinking as well. But then the OP posted a few other codes and said that he can't get $user->data()->username to work. Which is confusing because he is using the filename activate.php, but apparently "wants" the user to type in something. That is why I want the OP to take it step by step so that we can figure out what is really wrong.


I guess I should try to make it clearer. I manage to get it work in my profile.php with these codes...

require_once 'core/init.php';

if(!$username = Input::get('user')) {
} else {
     $user = new User($username);
     if(!$user->exists()) {
     } else {
          $data = $user->data();

     <h3><?php echo escape($data->username); ?></h3>
     <p>Full name: <?php echo escape($data->name); ?></p>
     <p>Username: <?php echo escape($data->username); ?></p>
     <p>Joined date: <?php echo escape($data->joined); ?></p>
     <p>Email address: <?php echo escape($data->email); ?></p>
     <p>Group: <?php echo escape($data->group); ?></p>

      <li><a href="login.php">Log out</a></li>
      <li><a href="update.php">Update details</a></li>
      <li><a href="changepassword.php">Change password</a></li>



But I can't get it to work in my activate.php even when I have set $data = $user->data();

My codes for my activate.php are:

require_once 'core/init.php';

$user = new User($username);

echo $user->data()->username;

It should say the username and I do have a method called data() in my user.php, i think...


You will receive an Undefined Index because $username is not defined. What you really want in activate.php file is the email and the token. Like I have said before in post #32.

Take this and apply it to your activate.php file.


Thanks for the advice... I have been following this tutorial and it seems to work.. any suggestions whether is this a good website or not?


That tutorial is nine years old, and things move very quickly in terms of the Web. If you are going to try to learn from tutorials, then check the date and ensure they are recent, or you will end up learning outdated or obsolete coding practices, and have to relearn things the right way.


Enough said.


You can call it like that but the code doesn't make much sense tho. Just a quick test:

class User {
    private $data;
    public function __construct(Data $data) {
        $this->data = $data;
    public function data() {
        return $this->data;

class Data {
    public $token = '21445';

$user = new User(new Data());
$token = 'token';
echo $user->data()->$token;



Strange, as it seems. It does actually work. But like you said, it doesn't make sense. Though the reason why I said it wasn't going to work was because doing ->$ might cause a problem.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.