Page 1 of 1

get data from external script

Posted: Thu Jun 26, 2008 4:21 am
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

Re: get data from external script

Posted: Thu Jun 26, 2008 4:26 am
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?

Re: get data from external script

Posted: Thu Jun 26, 2008 4:35 am
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'

Re: get data from external script

Posted: Thu Jun 26, 2008 4:49 am
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");

Re: get data from external script

Posted: Thu Jun 26, 2008 4:58 am
by phpnewbie112
sorry I did not understand could you pls clarify further in an example for the balance. thanks a million

Re: get data from external script

Posted: Thu Jun 26, 2008 5:01 am
by WebbieDave
You'll want to read the documentation for further clarification:
http://www.php.net/file_get_contents

Re: get data from external script

Posted: Thu Jun 26, 2008 5:19 am
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...

Re: get data from external script

Posted: Thu Jun 26, 2008 3:20 pm
by WebbieDave
Well, what questions regarding coding an API do you have?