Posted in php functions
3220
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
103
This Month
308
This Year
370

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

“Make no mistake: This is not your diary. You are not letting it all hang out. You are picking and choosing every single word.”


Dani Shapiro
Random CSS Property

:focus

The :focus CSS pseudo-class represents an element (such as a form input) that has received focus. It is generally triggered when the user clicks or taps on an element or selects it with the keyboard's Tab key.
:focus css reference