Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

p0t4t0's avatar

Is there a better way to handle account verification via sms?

This is the code I have right now. I haven't tested it out yet but it looks like it's going to work? lol

RegisterController.php

protected function create(array $data)
    {
        $user = User::create([
            'first_name' => $data['first_name'],
            'last_name' => $data['last_name'],
            'mobile_number' => $data['mobile_number'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
            'authentication_code' => $this->generateAuthCode()
        ]);

        $textMessage = new SmsController($user->mobile_number, $user->authentication_code);
        $result = $textMessage->sendAuthCode();

        if ($result ) {
            // success
        } else {
            // error
        }

        return $user;
    }

SmsController.php

public function __construct($number, $message) {
        $this->number = $number;
        $this->message = $message;
    }

    public function sendAuthCode()
    {
        $postData = array(
            '1' => $this->number,
            '2' => $this->message,
            '3' => $this->apicode
        );

        $ch = curl_init();
        curl_setopt_array($ch, array(
            CURLOPT_URL => $this->url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => http_build_query($postData)
        ));

        // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        // curl_setopt($ch, CURLOPT_SSL_VERIFYUSER, 0);

        return curl_exec($ch);
        curl_close($ch);
    }
0 likes
2 replies
Snapey's avatar

How could anyone say without knowing what API you will use?

Have you validated any inputs?

Do you need to deal with country code for the user's mobile?

The line curl_close will never be called because it is after the return statement

Are you only sending a code? No text with it for explaination?

p0t4t0's avatar

@Snapey apologies, i am new to curl and this is the sample code they have on their website (the API i am using which is iTexMo btw which i don't believe anyone here has heard of since it is only a local company which is also why i didn't mention it), yes i validated my inputs, everything is working fine, my activation gets sent each time a new user registers. i just need to know a better approach and someone advised me i should consider using service providers which is what i am doing but can't figure out how to get working. yes, i am only sending code. instructions are on the page where the user gets redirected to after registering (copying google for this)

Please or to participate in this conversation.