Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] How to access remote server using php?


[SOLVED] How to access remote server using php?

Reply
  #1 (permalink)  
Old 05-04-08, 03:46 PM
douffle douffle is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] How to access remote server using php?

Can anyone tell me if you can code a script running on one server to access a MySQL database on remote server?

I want to have a script compare the domain name that the script is running on to the domain name that is stored in a MySQL database on a remote server.

I am pretty sure that it can be done and if it can be, could someone show me a sample of the code that would be needed to achieve this?

I know how to get the domain name of the server that the script is running on using the $domain=$_SERVER['HTTP_HOST']; function but I need to know how to access the MySQL database on the remote server to compare it to.

Thanks
Reply With Quote
  #2 (permalink)  
Old 05-05-08, 03:12 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
It's pretty easy: have a look at the mysql_connect function. The 1st parameter you have to enter is the name of the server the MySQL server is running on. So if you want to connect to a remote server, simply enter the domain where the MySQL is running on:
PHP Code:

mysql_connect ('mysql.on_remote_host.com''username''password') or die (mysql_error ()); 

There might be a chance that this won't work as there's an option in the MySQL server configuration that, if set to true, only allow connections via localhost to it's server. In that case, you'll have to write a php script that runs on the remmote server, and that will grab the data from the MySQL server. Instead of connecting to the remote MySQL server, you'll have to fetch the output of the php page
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #3 (permalink)  
Old 05-05-08, 11:18 PM
douffle douffle is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you for your help.
I will give that code a try and see what happens.

I checked with my Host provider to see if they allowed remote connections and they said yes but it has to be set up in the cpanel so I will give it a shot.

Thanks again. Very much appreciated.
Reply With Quote
  #4 (permalink)  
Old 05-06-08, 12:38 AM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
If you have cpanel you will need to go into the Mysql section and allow the remote hosts. This will mean you will have to enter the ip and access before you can connect, it's easy and there is a form.
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] it works on localhost but not on hosting account? myslowquietlife PHP 42 12-19-08 09:31 AM
Sr. PHP Dev Contract w/ Fortune Pharma (100% Remote) TurnberryFNM Job Offers & Assistance 0 02-27-08 10:11 AM
calling a remote access through a php script soloWebDev PHP 2 01-02-08 12:45 PM
Manage Microsoft Exchange Server with PHP? scott2500uk PHP 1 08-22-07 04:29 AM
PHP code on a remote file tonniar .rm PHP 2 05-24-04 02:32 AM


All times are GMT -5. The time now is 07:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.