Share My Creation (PHP/MySQL/API) User Login App

Web API






Android App




 
Last edited:

winjiadh

Active Member
Licensed User
Longtime User
I suspect something wrong in the db connection.
Make sure you have set up the MySQL username, password and generate the tables using the sql file.
I click the http://test.d99p.cn//user
it's [{"Connected":1}] the MySql is connected
but click the http://test.d99p.cn//user/register
display the error

Warning: array_key_exists() expects parameter 2 to be array, null given in C:\FTP\api\api\models\user.php on line 82

Fatal error
: Call to a member function prepare() on null in C:\FTP\api\api\classes\Model.php on line 35
If some places need to set up the PHP can use?
 
Last edited:

aeric

Expert
Licensed User
Longtime User
I click the http://test.d99p.cn//user
it's [{"Connected":1}] the MySql is connected
but click the http://test.d99p.cn//user/register
display the error
/user/connect does not check for DB connection.

You can modify user.php in models directory (NOT controllers directory) as following:
user.php:
    public function connect()
    {
        $success = array("Connected" => 1);
        $failed = array("Connected" => 0);
        if ($this->open())
        {
            print json_encode(array($success));
        }
        else
        {
            print json_encode(array($failed));
        }
    }

 
Last edited:

winjiadh

Active Member
Licensed User
Longtime User
Try use adminer.php to login to your MySQL.
You can download from https://www.adminer.org
now if i use the root to login,the api is all right
but registed succesed no email send to the mailbox
 

aeric

Expert
Licensed User
Longtime User
no email send to the mailbox
You need to change the email settings in config.php

PHP:
// Define Email Sender
define("ADMIN_EMAIL", "mailer@computerise.my");
define("NOREPLY_EMAIL", "no-reply@computerise.my");

ADMIN_EMAIL = the email you want to receive message if a new user register. It can be any email such as google, yahoo, qq.com, 163.com
NOREPLY_EMAIL = the email account set up in your hosting server for sending out email

You can do a test with this php script:

PHP:
<?php
    define("NOREPLY_EMAIL", "admin@d99p.cn");
   
    // Email header
    $headers = "From: ".NOREPLY_EMAIL."\r\n";
    $headers .= "Reply-To: ".NOREPLY_EMAIL."\r\n";
    $headers .= "X-Mailer: PHP/".phpversion();

    mail("someone@qq.com", "test email subject", "The content of the test email.", $headers);
?>

You can also check the SendEmail function in user.php
 

hitesh.k

Member
Hello thanks for api and app i try and it is working . could you sugest me on following points
1: no reply mail is going in spam folder
2 : how to display web page at acc activation link
3 : i like to dig more in to php sugest some ide for php api development
4 : can rest and token could be added in php api
 

aeric

Expert
Licensed User
Longtime User
I have missed this message.

1. Not sure. Maybe misconfigured email account settings or delay in email delivery.
2. You can edit the $html inside the activate() in user.php (models)
PHP:
$html = "<h1>Activation</h1>
<p>Your account is now activated!</p>";
echo $html;
3. I don't use any fancy IDE like PHPStorm. Sublime Text, Notepad++ or VSCode is fine.
4. Sure you can extend the project either with plain PHP or use a PHP Web framework.
 

aeric

Expert
Licensed User
Longtime User
Warning: array_key_exists() expects parameter 2 to be array, null given in C:\FTP\api\api\models\user.php on line 82
May be adding a check would fix the warning. Repeat this with other functions which read $Map1.
PHP:
    public function register()
    {
        try
        {           
            $eml = null;
            $pwd = null;
            $name = null;
            $json = file_get_contents("php://input");

            $Map1 = array();   
            $Map1 = json_decode($json, true);
            if (!$Map1)
            {
                $msg_text = "[Invalid JSON Object]";
                $this->LogUser("user/register", "fail", $msg_text, 0);
                $this->ReturnError("Error-No-Value");
                return;
            }           
            if (!array_key_exists("eml", $Map1))
            {
                $msg_text = "[Email Not Set]";
                $this->LogUser("user/register", "fail", $msg_text, 0);
                $this->ReturnError("Error-No-Value");
                return;
            }
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…