I have created a database and trying to access it using php. I execute these scripts from my phone. Now the issue is that when I try to perform any operation on the DB from the real device (my MOBILE PHONE) it says "unfortunately Closed" but works fine from the virtual device.
URL for real android device:
[http:// 127.0.0.1:8888 //android_connect/get_product_details.php]
URL for the virtual device:
[http:// 10.0.2.2 /android_connect/get_product_details.php]
The 127.0.0.1 is a loopback address so the android device or any other computer will not able to connect to it. Get a webserver (there's a lot freely available to test PHP scripts) , drop all the files in there and you will be able to access it.
say.. http://somefreewebhost.com/android_connect/get_product_details.php
Alternatively...
If you are using a webserver like WAMP, you will have an option called "Put Online". Go to your command prompt and type "ipconfig" and note down that IP address and you can even use that (provided if you are not behind any firewall)
Related
I have a MySQL wamp server running on my laptop. I created a php file to run a SQL query on the database and return some rows. When I run the php file on a browser in my laptop with the URL
http://192.168.2.10/getData.php?sender=x
I get the result. I can get the same result with the same URL on a browser of my mobile phone connected to the same network. But, I cant get the result when I use mobile data instead of the network used by the laptop.
I studied about it and found out I have to use
GRANT ALL PRIVILEGES ON chats.* TO 'user'#'%' IDENTIFIED BY 'password'
which I did. Then, on the mobile phone I figured I have to use some combination of global and local IP of the server. But what combination should I use?
When your using php, the connection made needs to be "seen" from the server which executes the .php script (that can be different ip then your mysql server). In that case you need to make sure the user used has either user#% where % means allow form any ip, or user#ip where ip is the ip connecting from.
On your mobile phone you enter the ip of the webserver + the path to the .php script. In your case that seems to be http://192.168.2.10/getData.php?sender=x
Now you need to make sure that the webserver is bound to your external ip adress (and not localhost) in that case you the url will not work. To be sure all works, take another pc/laptop (in the same network) and check if you run the script from the browser.
Logically if your phone is connected to mobile + LAN, you should able to access the link (http://192.168.2.10/getData.php?sender=x) without grant anything to mysql user, since the getData.php is using "localhost" to connect to mysql, correct me if i'm wrong.
If your requirement is : Laptop (LAN) and Phone (on mobile data), and you want to use your mobile to access the laptop url, then you will need external IP of your LAN connection and proper port 80 forwarding to your laptop IP from router/modem. After that, you should able to access to your laptop using the http://LAN'sExternalIP/getData.php?sender=x using your phone. If your LAN connection is without internet connection. Then it is not possible to access it from phone (mobile data).
Other than that, you will also need to do some setting to your wamp's apache configuration, which you can refer here. And also need to Put the wamp to online by right click its icon near taskbar.
I have a local php(Laravel) server. I can access the domain "mydomain.dev" from an simulator but it does not work when I try to access it from a real device. I have the app running with the device connected to the same wifi network but it still does not work.
Open your command prompt/terminal
Type
windows ipconfig
linux ifconfig -a or ip addr show
write your IPv4 adress
exemple (windows)
Then Run your server php artisan serve or whatever you are using (wamp/laragon or easyphp ..etc)
then go to your browser in your phone and navigate to mydomain.dev
This should work.
Please try to use IP address instead of mydomain.dev. When running on a real device, it will search dns server to look up mydomain.dev. If the dns server can't recognize this url, your device can't open it.
I am developing an application which basically starts with registration system using the wampserver to connect to mysql database through localhost/phpmyadmin as a back-end and android client using genymotion emulator as a front-end and both front and back end communicates through php/mysql API.
I have followed different tutorials to achieve all this but since none of them actually used genymotion I am missing the part of which IP, I should put for this mechanism to follow smoothly.
when you use emulator on you pc , your emulator will connect to virtual network interface that you can change it ....
you should check emulator network interface and enter your pc ip in that network interface ...
i attached a picture of setting of my emulator and you can see my emulator use my wifi network interface .... thus i should insert my computer ip address of wifi network interface
finally you should get your pc ip as network interface that your emulator connected to that and use that ip in emulator for connect to your webserver in your pc.....
in Wampserver, you can not access to apache from outside ...
you should change apache config (httpd.conf) and make access for outside connection ...
Hello I have a problem in accessing the localhost in my android device. I can't open my localhost in my browser. I installed an application that supports httpd, php and mysql. But when I have a connection in the Internet there's no error in displaying the localhost. But if I disable it, I can't open the localhost. Is there a configuration file that I need to configure in my device? I am using ICS. I am using 127.0.0.1 as my localhost I also did 127.0.0.1:8080 but it doesn't work also.
If you're trying to access your web server over your local network, then you'll need to bind the web server to an IP address that the device can access - this is not 127.0.0.1. Assuming you're on wifi with your android, you'll want to have your web server listen to something along the lines of 192.168.1.X. If you use 0.0.0.0 it will accept on all interfaces, this should work as well. Either case, you'll need to access your web server from your device using your web server's local IP address, not localhost and not 127.0.0.1
Localhost as the url in a browser should access the server running on that device.it sounds to me maybe you are connected to a remote desktop or something. Tcp/ip utilities in particular try tracert localhoast or route. config /release maybe your touting tables are messed up,weird
The localhost refers to the device on which the code is running, in this case the emulator.
If you want to refer to the computer which is running the Android simulator, use the IP address 10.0.2.2 instead 127.0.0.1. You can read more from here.
I encountered the same problem while working with my localhost too. The problem turns out to be with the antivirus that i was using. I was able to access my locahost again after turning the antivirus off. But because i cannot continue using my machine without an antivirus I just have to change the antivirus to another one. It worked for me, Hope it will for you too.
I'm trying to create android apps which able sending data through wifi connection to my laptop Apache Server and MySQL database. I use the samsung galaxy tab 10.1 as my mobile device. and the protocol i used is HttpGet or HttpPost. And i use XAMPP( with Apache& SQL) to do the server and process the php. But, due to android cannot detect adhoc network from laptop, i use Virtual Router ( for window 7) to create virtual access point and make the tablet able connect to my laptop. But the problem is:
In my apps (client-android), where the httpget or httppost to which url? localhost in my laptop- 127.0.0.1 or localhost in android 10.0.0.1? or the ip address of the virtual router?
So, if I want access from android to the localhost(laptop-Apache) to call the php to run? which port? which ip address /url that i need to put in android apps(httpget)? and do I need to modify anything in httpconfig for XAMPP?
Find out your Ip address in your laptop using ipconfig . use that address in the phone instead of 127.0.0.1.
as long as you know the I.P Address of the Computer with Apache on it , Since external MySQL access is quite tricky to set up id recommend sending JSON requests to your PHP scripts and getting the return value via Java then what you want to do with the output is upto you.