Jump to content

Accessing mysql DB data on remote website


n8frog

Recommended Posts

What I am trying to accomplish is to display data on a website that is stored in a db on another website.

 

I have a script that stores statistics for webmasters in a mysql db.  (sort of like an ad click counter) I want to allow these webmasters to display this data on their own website.

 

Sudo-Example:

My script stores hit count of remote site in a mysql db at myscript.com (fake name)

 

My script user wants to display count of hits on his/her page at countedsite.com (fake name)

 

How do I do this? I tried using

include 'http://myscript.com/whatever.php';

(whatever.php has a mysql query that fetches the data) in the remote website but nothing is displayed.

 

I would like to provide a line of code similar to above that the webmaster can include in the source of their website to display the count.

Any ideas?

In order for your users to be able to include a remote file they would need to have allow_url_include enabled within there php.ini. This is disabled by default.

 

A better option would be for them to call....

 

<?php echo file_get_contents('http://myscript.com/whatever.php'); ?>

 

as allow_url_fopen is enabled by default or for them to use curl, either way, what your providing should be sufficient. You will however likely require your users to pass an id via the querystring so that your script can identify them and get the correct data. eg;

 

<?php echo file_get_contents('http://myscript.com/whatever.php?id=someuniquecode'); ?>

Thank you I was able to get this working using the example you provided. I have to say this website is amazing. Every question I have had thus far has been answered by the users here. I can't wait until I become knowledgeable enough with php to do the same for others.

 

Thanks again you guys are great! :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.