Posted in php functions
3216
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
99
This Month
304
This Year
366

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
When i was a little kid, I was really scared of the dark. But then I came to understand, dark just means the absence of photons in the visible wavelength -- 400 to 700 nanometers. Then i thought, well, its really silly to be afraid of a lack of photons. Then i wasn't afraid of the dark anymore after that.
Elon Musk
Random CSS Property

symbols()

The symbols() CSS function lets you define counter styles inline, directly as the value of a property such as list-style. Unlike @counter-style, symbols() is anonymous (i.e., it can only be used once). Although less powerful, it is shorter and easier to write than @counter-style.
symbols() css reference