Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending data (not forms) 1

Status
Not open for further replies.

wangbar

Programmer
Jul 23, 2001
1,906
GB
What's the best way to send data/receive from a php script? I know how to get data to a script through an HTML form, I know how to query a database from within php.

What I'm trying to do is send piece of data to a remote URL to be processed and then get an answer back but not from a form "submit" type scenario.

Do I have to get into HTTP headers etc to do this?
 
wangbar, could you please share the solution with us?
I am trying to do the same thing.

Thank you!

-A
 
It's really simple after all - just treat the remote web page as a file (which is all it is when all is said and done) and then read its contents into an array.

As a quick test I set up a script on the remote page which would accept a parameter in the URL query string and multiply it by 10 before returning it:

<?
$filename='$result=fopen ($filename,'r');
$read=file($filename);
fclose($result);
echo($read[0]);
?>
 
Actually, when using the file function you don't need to use fopen and fclose. The file function does that for you. If you would want to read it into a variable instead of an array, you could replace the $read=file($filename) with $read=fread($result,SIZE). Though you would have to know the size then, so the easiest way would probably be to use $read=impode('\n', file($filename)) if you want it in a variable. //Daniel
 
daniel,

One important thing.

When you call the file funtion, it reads all the file into an array, where each element is a row INCLUDING the \n.

So, you should do implode(&quot;&quot;,file(...)) istead of implode(&quot;\n&quot;,file(...)). If you put the \n, you will get 2 newlines where it should be only one.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Oh, right. It has been quite some time since I was dealing with files. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top