get data from external script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpnewbie112
Forum Newbie
Posts: 6
Joined: Tue Jun 17, 2008 3:11 pm

get data from external script

Post by phpnewbie112 »

I don't know if I used the correct term in the "topic" but I need your help with advices, tips or tutorials that can show how can I create something similar to the following request:

let's say I have a database with username,password,balance with a php script that works fine managing users etc...

how can I create for ex:
http://domain/script.php?username=user1 ... getbalance

in this way anyone can use this http URL to get the balance from my database using his own script. this also applies to get other actions and tasks...

Thanks a million
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: get data from external script

Post by WebbieDave »

phpnewbie112 wrote:in this way anyone can use this http URL to get the balance from my database using his own script
This statement is difficult to understand. Can you please expound?
phpnewbie112
Forum Newbie
Posts: 6
Joined: Tue Jun 17, 2008 3:11 pm

Re: get data from external script

Post by phpnewbie112 »

for example you create your own php code with let's say

$bal = "http://domain/script.php?username=user1 ... getbalance"

and when you do

echo $bal;
the result should be to retrieve the value of the balance. for sure database connection is to be included inside the 'script.php'
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: get data from external script

Post by WebbieDave »

You can use URI's with many PHP file functions. For instance:

Code: Select all

$contents = file_get_contents("http://mydomain/test.php");
phpnewbie112
Forum Newbie
Posts: 6
Joined: Tue Jun 17, 2008 3:11 pm

Re: get data from external script

Post by phpnewbie112 »

sorry I did not understand could you pls clarify further in an example for the balance. thanks a million
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: get data from external script

Post by WebbieDave »

You'll want to read the documentation for further clarification:
http://www.php.net/file_get_contents
phpnewbie112
Forum Newbie
Posts: 6
Joined: Tue Jun 17, 2008 3:11 pm

Re: get data from external script

Post by phpnewbie112 »

I think you misunderstood me, I read the documentation about file_get_contents I don't think that's the needed. my request is kind of related to create an api for other users to get my data...
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: get data from external script

Post by WebbieDave »

Well, what questions regarding coding an API do you have?
Post Reply