1

I was trying to pass data to my php API as JSON. API was hosted in localhost using Wamp.

then there was an error in android logcat -

org.json.JSONException: Value <html><body><script of type java.lang.String cannot be converted to JSONObject

full log -

2019-05-13 23:35:48.159 5767-5866/codecanyon.getpills I/REGISTRATION RESPONSE::: Response{protocol=http/1.1, code=200, message=OK, url=http://mywebsite.com/index.php/rest/user/login}
2019-05-13 23:35:48.163 5767-5866/codecanyon.getpills E/codecanyon.getpills.LoginActivity@ee4c317: <html><body><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("23dfd56dd81de61accd776ec4c11e6ca");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://getpills.rf.gd/index.php/rest/user/login?i=1";</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>
2019-05-13 23:35:48.165 5767-5866/codecanyon.getpills W/System.err: org.json.JSONException: Value <html><body><script of type java.lang.String cannot be converted to JSONObject
2019-05-13 23:35:48.166 5767-5866/codecanyon.getpills W/System.err:     at org.json.JSON.typeMismatch(JSON.java:111)
2019-05-13 23:35:48.166 5767-5866/codecanyon.getpills W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:163)
2019-05-13 23:35:48.166 5767-5866/codecanyon.getpills W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:176)
2019-05-13 23:35:48.167 5767-5866/codecanyon.getpills W/System.err:     at util.CommonAsyTask.doInBackground(CommonAsyTask.java:106)
2019-05-13 23:35:48.167 5767-5866/codecanyon.getpills W/System.err:     at util.CommonAsyTask.doInBackground(CommonAsyTask.java:24)
2019-05-13 23:35:48.168 5767-5866/codecanyon.getpills W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:333)
2019-05-13 23:35:48.168 5767-5866/codecanyon.getpills W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2019-05-13 23:35:48.168 5767-5866/codecanyon.getpills W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
2019-05-13 23:35:48.169 5767-5866/codecanyon.getpills W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
2019-05-13 23:35:48.169 5767-5866/codecanyon.getpills W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
2019-05-13 23:35:48.169 5767-5866/codecanyon.getpills W/System.err:     at java.lang.Thread.run(Thread.java:780)

then I have followed this thread -

WAMP error: Forbidden You don't have permission to access /phpmyadmin/ on this server?

and changed -

httpd-vhosts.conf (C:\wamp64\bin\apache\apache2.4.33\conf\extra\httpd-vhosts.conf) file -

<Directory "${INSTALL_DIR}/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
</Directory>

to

<Directory "d:/wamp64/apps/phpmyadmin4.7.9/">
    Options +Indexes +FollowSymLinks +MultiViews
    AllowOverride all
        Order Deny,Allow
        Allow from all
        Require all granted

then it solved the problem for localhost

Now I want to do the same for real server with cPanel

how can I do it?

because it's showing the same json error

1 Answers1

0

If I understand correctly, you want to allow all incoming requests. Well that is possible, but it could be potentially dangerous.

A safer way would be creating an user with specific permissions and then later on using that user credentials in your config.php(or wherever you have used mysqli_connect).

On every cpanel you will get an option called MySql Databases. Inside it you should get a option called 'Add User'. Create a new user and add it to your database. There it will ask you about permissions. Set permissions per your requirements. For example if you need only read access then you can only allow 'SELECT'. Then you can have access to your phpmyadmin.

For connecting to database you can use this code snippet-

$connection = mysqli_connect("localhost", "user_name", "user_password", "database_name");

Screenshots-
https://postimg.cc/WdpsFnwY (user creation)
https://postimg.cc/MnsqyQs6 (setting permission)

Refer to this link for a detailed guide- https://support.hostgator.com/articles/cpanel/how-do-i-create-a-mysql-database-a-user-and-then-delete-if-needed

Abir Partha
  • 123
  • 2
  • 8
  • yes but, it's for a general user account, I mean the app user has to create an account for their self. there will be a lot of users so it is not possible to create every user permission manually. – Shakil Ahmed Shaj May 14 '19 at 07:31
  • you don't need lot of users, just create one and give it only the permissions it need. as you've mentioned your users will be able to create account by themselves, so allow the db user write and update permission and it should be done. – Abir Partha May 15 '19 at 05:40