Android Code Snippet Register User example using OkHttpUtils2

G-ShadoW

Active Member
Licensed User
Longtime User
It's working now, I have switch to signup.php from first post.
Also, register.php is missing?
 

aeric

Expert
Licensed User
Longtime User
(Register) signup.php returns:
1. "Mail"
2. "MailInUse"

(Login) signin.php returns:
1. "Not Found"
2. "Not Activate"
3. User Name

Under Register module, it is unlikely to return "Not Found"

register.php is not used in this example. I use signup.php for register.
 

G-ShadoW

Active Member
Licensed User
Longtime User
Yes, I have modified php, it's working now.
But how to get Online user info
It should be something in service module with timer, right ?
 

aeric

Expert
Licensed User
Longtime User
Yes, I have modified php, it's working now.
But how to get Online user info
It should be something in service module with timer, right ?
I am not sure how it is done correctly. My idea is the app will periodically create a job request to a php page to update a last_login field in the database then a php page will return a query based on the difference time between current time and the last_login time. Normally Discussion forum list the online user within 5 minutes.
 

G-ShadoW

Active Member
Licensed User
Longtime User
Yes, from php it only count logins

B4X:
$res = mysql_query("UPDATE tbl_member SET logins = logins + 1 WHERE user_id = '$uid'");
    print json_encode ($row["user_name"]);

online status remain N
 

Attachments

  • online.png
    3.5 KB · Views: 630

aeric

Expert
Licensed User
Longtime User
Ya, I didn't implement the Online status. If you want to implement the Online status, I think it is not difficult to do it. As I mentioned, just update the value of last login in the table, in my table I have a time_stamp field which we can use for this purpose.
PHP:
$res = mysql_query("UPDATE tbl_member SET logins = logins + 1, Online = 'Y', time_stamp = now() WHERE user_id = '$uid'");

Then at some point before the above line or by using another php script (maybe we can use connect.php), we can run a query to update all user status to Online = 'N' when Current Time - Time Stamp > 60 seconds.
PHP:
$res = mysql_query("UPDATE tbl_member SET Online = 'N' WHERE now()-time_stamp > 60");
 
Last edited:

G-ShadoW

Active Member
Licensed User
Longtime User
I dont think that will work, there is no logout.
If user exit app, it's stay's as online.
 

aeric

Expert
Licensed User
Longtime User
I dont think that will work, there is no logout.
If user exit app, it's stay's as online.
To force logout, just add in a btnLogout button which create a job to logout. The php web service will execute an SQL which look like below:
PHP:
$res = mysql_query("UPDATE tbl_member SET Online = 'N' WHERE user_id = '$uid'");

If a user exit the app without tapping on the btnLogout button, his status will updated to Online = 'N' when another user login after 60 seconds. You can set the value 60 to 1 seconds if you like.
 

mbayik

Member
Licensed User
hi, thank you for the example, its very useful. im testing it but im taking connection problem..the app says "Connecting to server" and waiting then "error java.net sockettimeoutexpection

my server address is

Sub TestConnection
Dim Connect As HttpJob
Connect.Initialize("Connect", Me)
Connect.Download("http://www.giritliyazilim.net/connect.php")
ProgressDialogShow("Connecting to server...")
End Sub
 

aeric

Expert
Licensed User
Longtime User
You can test to access the address using web browser.
 

mbayik

Member
Licensed User
i changed my hosting to free hosting service, its connected. i will continue testing..
 

cwkoomy

Member
Licensed User
Longtime User
hi, i can register and active the user, but when login just show "an error has occured" , sorry newbie dont know which error is it
 

aeric

Expert
Licensed User
Longtime User
hi, i can register and active the user, but when login just show "an error has occured" , sorry newbie dont know which error is it
The free hosting server is facing DDOS attack. I suspect the scripts have been compromised or unable to run properly. Please upload the script to your server. Edit the domain name then test.
 

cwkoomy

Member
Licensed User
Longtime User
The free hosting server is facing DDOS attack. I suspect the scripts have been compromised or unable to run properly. Please upload the script to your server. Edit the domain name then test.
i use pay hosting, i change the signin.php update, then can login, but error " An error has occurred in sub:member_jobdone(java line:421) java.lang.NullPointerException
and Welcome :null , is it change Login.strUserName to strUserID? ?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…