Page 1 of 1

QU

Posted: Mon Apr 21, 2008 6:59 pm
by barview
I am trying to connect to a php script on one server from another. This script is password protected with .htaccess. I am able to connect to it and I am able to execute it but I am not able to receive my post data variables on the other end. The code for accessing my remote script is as follows:

function do_post_request(){
$url = "http://www.testscript.com/admin/myscript.php";
$data = 'HWA=111111111111';
$header .= "Authorization: Basic " . base64_encode("username:password);
$params = array('http' => array('method' => 'POST', 'header' => $header, 'content' => $data));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'r', false, $ctx);
if (!$fp)
return "Problem generating SN [1]";
$response = @fgets($fp, 1024);
if ($response === false)
return "Problem reading data";
return $response;
}

my script on the other end is executing the following code:

if (array_key_exists("HWA", $_REQUEST))
{
$HWA = $_REQUEST["HWA"];
echo myscript($HWA);
}
else
echo "No info";

This always returns 'No info' for me. I have tried using the $POST variable instead of the $REQUEST and that didn't work for me either. I am completely at a loss as to why the post data is not being populated.

Re: QU

Posted: Mon Apr 21, 2008 9:55 pm
by yacahuma
Why dont you try

$data = implode('', file('http://www.example.com/'));

take the htaccess for now. Also, if your script produces no output without the correct password, do you need htaccess?

Re: QU

Posted: Tue Apr 22, 2008 11:44 am
by barview
Im not sure what implode would do for me since I am not dealing with an array to my knowledge. Also my script is returning output based on an else statement if there is no post data. I only get connected to my script if there is the Authentication in my script.

Re: QU

Posted: Tue Apr 22, 2008 12:46 pm
by yacahuma
reciever.php(notice not using post on example)

Code: Select all

 
$n1 = $_GET['n1'];
$n2 = $_GET['n2'];
echo $n1+$n2;
 
sender.php

Code: Select all

 
$data = implode('', file('http://localhost/test/receiver.php?n1=5&n2=7'));
echo $data;
 

Re: QU

Posted: Tue Apr 22, 2008 1:03 pm
by barview
I dont want anyone to see the variables in the url. I want to use post. Is there any way to do it this way using post.

Re: QU

Posted: Tue Apr 22, 2008 1:04 pm
by barview
Also, will this work with authentication?