Jump to content

Pass Post vars when opening web page with php


HardCoreMore

Recommended Posts

Hi guys,

 

I know that you can open web page with $handle = fopen("http://www.example.com/", "r");

but i am wondering is there a way to pass POST vars when doing so, or there is another method that can that like you do it with ajax.

 

I have mvc application that i want to test. I am using CodeIgniter framework so i want to call my controllers

with POST values. Every controller method returns data holder object that holds the data of operation whether is successful or not. Also every method inside controller can be called with parameter input or with post input. If you omit the parameters when calling controller method than he will try to load that parameters from post and that is why i want to pass POST vars with php when calling controller for example i want to call:

 

fopen("http://localhost/MyAppFolder/index.php/controller/method");

 

but i want to pass it some POST vars if that is possible

 

Thanks.

 

I just found solution on the web. Here it is if anybody needs it:

 

 

$url =  $settings['root_url'] . 'authentication/authenticate';

 

(string)$data = '';

 

$data .= 'username=username&';

$data .= 'password=password&';

$data .= 'key=44d7db2d-2656-102e-acf7-3c78a6d744cd';

 

$params = array('http' => array( 'method' => 'POST', 'content' => $data ) );

 

$ctx = stream_context_create($params);

$fp = @fopen($url, 'rb', false, $ctx);

$response = @stream_get_contents($fp);

 

echo $response;

 

 

Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.