Access mysql server remotely from another network - php

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.

Related

MySQL connect via proxy php

I want to connect to a remote database from my localhost, but the remote DB only allows connections from whitelisted IPs.
Since I'm on a dynamic IP from my ISP, I can't have my home IP whitelisted, because it will just change again.
I have a VPS with full root access and a fixed IP, which is whitelisted.
What I want is to:
Run a php script from my local machine
Connect to the remote database via my VPS
Get the query results back to my local machine for handling
How do I do this?
Having a PHP proxy to execute arbitrary SQL statements from any IP address is really dangerous. I would suggest you abstract the SQL statements into an API, so rather than allowing any query through, you limit it to a specific set of queries to retrieve or update specific data. Your local machine could then just call that API to retrieve or update information.
The key problem you need to solve is finding a host with a static IP address you can add to the whitelist. You say that you have already solved that problem. However you have not mentioned what OS is running on the vps nor the client. If both are Linux, then you can do this with just iptables. If either or both are mswindows then you could use socat, but if it were me, I'd go with a stunnel link between the client and proxy (although if the whitelist on the server is only applied to the mysql connection, you could terminate the stunnel connection on the server and skip the proxy altogether) using client certificate authentication or an SSH tunnel.

Connecting Android device to Apache server

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)

how to access database from one website to another website

Hi I'm having problem with accessing database from one of my site to another..
I have one site say a.com and I want to replicate the database from this site to my another site say b.com...
I'm using Cpanel in both the sites. In site A.com, I have created a user with required privileges and also added the other website (b.com) in the access hosts..
Now to access a.com database from b.com, I can use the username and password I have created on a.com but I'm not sure what hostname should I use..
Website a.com use localhost as the hostname..what should I use with b.com..
if you can't connect to the database then it's better to develop some kind of api. Try this
search api to use in external websites you might get some help.
Assuming:
the database is configured to be exposed on the network (if it is designed to be used only from the same machine it shouldn't be, UNIX sockets are preferred)
there is no firewall in the way
the database permissions table grants rights to users on the other server
… then it would be the ip address of the machine the database server is running on.
You should use a.com, or a decent IP address/domain name that will correctly direct the connection to the database.
However, do note you will need to configure the incoming server to accept the connection (i.e. port forwarding, firewall etc).
we can get data from another site by using $.getJSON function of jQuery
You can get detail information from
http://api.jquery.com/jQuery.getJSON sites....

accessing php file on a computer from another computer via internet

i have php files on my computer and i can very well access those from IIS using eighter localhost or loop-back address . But now if i want to access the same file of php from another computer not in the LAN but in a different computer on the internet what should i do? i was thinking of IP address(static) as an option but then i was not successful in finding a way to do the same .
thanks in advance....
I don't completely understand your question. Is your problem
1) You don't have a static IP? Then:
There are services as "No-IP" where you can create redirects. At their site, you can create a free domain name (which is a static IP as well) such as yourdomain.no-ip.com. Then on your server computer you can run their tool. This tool updates the IP all the time so it will be always correct.
2) You don't know how to access the server from out of the LAN because the IP of your network is the same for all computers (if you're looking from the outside)? Then:
Check your router settings, normally at: http://192.168.1.1. There you will be able to define rules how to redirect requests from the outside. For http, you should redirect requests to port 80 to the IP of the server computer (note: you can even use an other port on the server computer)!

WAMP - Put online while being offline?

If I'm on a local network is there a URL that I can type that will allow all users on the local network to view a local hosted website?
There is one feature called put online but I would need to be connected to the internet. Can it be done another way?
I know this question is off subject but I get fast responses here. and its somehow related :)
You can use either your local IP or your hostname on the network.
For the hostname to work, your network needs a DNS server that updates itself from DHCP, or has a static entry for your computer, or all the systems need to have NetBEUI running. If you can type "ping " in a command prompt/console window, and it shows it pinging your network IP, then it works.
they have to enter your ip
You could use your local network IP address to address your machine. But you have to configure your webserver to deliver the right content without a specific host name.

Categories