how to access database from one website to another website - php

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....

Related

How would you create a server without port-forwarding for a website?

I'm at school and in on Campus housing which means I don't have access to the router to get the admin password to allow me to port-forward my website for my senior Capstone. I would like to know how to host a server that I can insert a MySql database, as well as my sight files from my own machine; how would I even go about getting around this without port forwarding?
There is an "Open Windows Firewall Ports for network access" embedded within MySQL Server download prosses theoretically if clicked would it allow me to embed a Website within MySQL Server and host it?? or would that just allow my database to be assessable threw my vulnerable network.
One solution would be to use reverse proxy services like https://pagekite.net/

How can i access to my PHP application on my smartphone using a DNS local adress

I have a PHP application running on wamp3. I have being able to enable people of my local network getting access to the application while typing 192.168.2.22/myapps. I'm looking how to make them instead type www.myapps.dev for to get access to the application.
French speaking to... but answer will be in English ;)
So, in order to access a server, you need its IP.
First way to access
Like you already do, directly through the IP
Common way to access
The user is calling a DNS name which is translated by an IP using a DNS server. Using this technique will imply technical abilities in server management and networking.
Developer way
The user configures the specified host on his terminal. On Linux and Android, you can update /etc/hosts file in order to add IP / DNS correlations. You may find "Hosts editor" application in Play Store.
Note that this technique won't be available for iOS users.

Access mysql server remotely from another network

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.

Connecting to database as a remote user

I know that you can access a database from a domain name with a user like this user#example.com but will this user also be able to access the database if they are trying to connect via another page on that domain i.e. example.com/page?
I am asking this as I am trying to connect from a domain name that will be establishing connections from different pages and sub folders i.e. example.com/admin/page, will setting it up with just example.com as the ending will all variables of that domain be accepted from the database connection or would each page need to be set up as seperate users on the database?
EDIT:
when I say "I know that you can access a database from a domain name with a user like this user#example.com" I mean that you can create a remote mysql user that can access from a domain name, the statement in mysql would look like GRANT ALL PRIVILEGES ON *.* TO user#example.com IDENTIFIED BY 'password' WITH GRANT OPTION; what im asking is, can this user access from all variables of example.com?
I think you are confusing a few concepts here.
The "page" as in webpage, or domain as in www.example.com are of little concern when connecting to a database.
You seem to be using mysql, so what you need to do is make sure your process that handles some web request (eg your apache server, or IIS, or whatever) can connect to the database.
eg:
If you apacheserver is running on 1.2.3.4, make sure your mysql allows connections from 1.2.3.4
The webpages themself are not important.
Yes users from different pages will be able to connect.
No you do not need to create different users for each url in your application.
The domain part of the user name is determined by MySQL doing a DNS resolution on the connecting IP. It has nothing to do with the page request to your PHP script.

What is a safe way to connect to a API on a separate domain?

Background : I am creating a website (in the typical LAMP environment) that connects to a database via a PHP/XML based API on a different domain (but on the same server). The reason for this is that I do not want to have database connection details sitting on the domain I am working on. In order for this to work I've enabled "allow-url-fopen" setting for that domain.
My question is, since this is the only way I know how to do this, does anyone know a better i.e. safer and more secure method of achieivng this result?
If both the domains reside on the same server you do not need to use HTTP to get connected to MySQL, you can still login to your MySQL server locally providing the right credentials for your domain where the connection information is stored.
But it does not really serve a great security purpose, as if your connection details reside even on the same domain it is not a security loop hole as your PHP pages will not be server in any raw form as long as your webserver is configured to use PHP fine. You can and probably should keep them on same domain. In fact having a publically accessible API for database connection is a bigger loophole

Categories