QU

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
barview
Forum Newbie
Posts: 4
Joined: Mon Apr 21, 2008 6:49 pm

QU

Post 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.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: QU

Post 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?
barview
Forum Newbie
Posts: 4
Joined: Mon Apr 21, 2008 6:49 pm

Re: QU

Post 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.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: QU

Post 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;
 
barview
Forum Newbie
Posts: 4
Joined: Mon Apr 21, 2008 6:49 pm

Re: QU

Post 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.
barview
Forum Newbie
Posts: 4
Joined: Mon Apr 21, 2008 6:49 pm

Re: QU

Post by barview »

Also, will this work with authentication?
Post Reply