Posted in php functions
3134
3:11 am, October 24, 2021
 

php post data back to a url with a function

this function uses curl to post back data to a url, this acts like a _POST form request from within a function.

Function usage:

$url

the url to post the data back to

e.g: $url = "https://kruxor.com/";

$myvars

the variables and data to post back to the url, you can add them in a string like the following example

$myvars = 'myvar1=' . $myvar1 . '&myvar2=' . $myvar2;

Usage

echo $response = post_data($url, $myvars);

PHP

public function post_data($url, $myvars) {
  		//$url = 'http://www.someurl.com';
  		//$myvars = 'myvar1=' . $myvar1 . '&myvar2=' . $myvar2;

  		$ch = curl_init( $url );
  		curl_setopt( $ch, CURLOPT_POST, 1);
  		curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
  		curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
  		curl_setopt( $ch, CURLOPT_HEADER, 0);
  		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

  		return $response = curl_exec( $ch );
  	}

View Statistics
This Week
88
This Month
408
This Year
284

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
For a long time it had seemed to me that life was about to begin - real life. But there was always some obstacle in the way, something to be gotten through first, some unfinished business, time still to be served, or a debt to be paid. Then life would begin. At last it dawned on me that these obstacles were my life.
Alfred D. Souza
Random CSS Property

max-height

The max-height CSS property sets the maximum height of an element. It prevents the used value of the height property from becoming larger than the value specified for max-height.
max-height css reference