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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.