Php-mysql Course

It is possible to send POST data with file_get_contents() and get the returned content, by using it with the stream_context_create() function.
The stream_context_create($opt) creates and returns a stream context with any options supplied in the $opt array.
- $opt is an array of associative arrays in the format: $arr['wrapper']['option'] = $value .

Example stream_context_create() and file_get_contents()

- Click on the code to select it.
$postdata = http_build_query(['name'=>'some name', 'pass'=>'password']);  //data to send 'name=some+name&pass=password'
$opts = [
 'http' =>
  [
   'method'=> 'POST',  // GET or POST
   'header' => 'Content-type: application/x-www-form-urlencoded'. PHP_EOL .'Content-Length: '. strlen($postdata). PHP_EOL,
   'content' => $postdata
  ]
];
$send_data  = stream_context_create($opts);
$cnt = file_get_contents('http://domain.net/page.php', false, $send_data);  //send data and get the returned content

echo $cnt;
- The http_build_query($arr) function generates a URL-encoded query string from the $arr, returns a string like this: 'key1=val1&key2=val2'.
- The value of the key 'method' must be in UPPERCASE (GET or POST).
- The 'header' key contains http headers that must be send to "page.php".

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which HTML5 tag can be used to embed an external application (SWF, PDF) in web page?
<mark> <embed> <canvas>
<embed src="flash_game.swf" width="450" height="350" />
Which CSS pseudo-element adds a special style to the first line of a text?
:first-letter :before :first-line
#id:first-line {
  font-weight: bold;
  color: blue;
}
Click on the window object property which gets or sets the URL of current page.
window.location window.self window.status
var url = window.location;
alert(url);
Indicate the PHP function used to get the contents of a file or page and store it into a string.
fopen() file_put_contents() file_get_contents()
$homepage = file_get_contents("http://coursesweb.net/");
echo $homepage;
Send POST data with file_get_contents

Last accessed pages

  1. Working with getElementsByTagName (13084)
  2. Node.js Course (2790)
  3. html2canvas - Save page screenshoot on server (4963)
  4. Get Duration of Audio /Video file before Upload (15422)
  5. PHP Method Chaining (5451)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (318)
  2. CSS cursor property - Custom Cursors (56)
  3. PHP-MySQL free course, online tutorials PHP MySQL code (44)
  4. The Mastery of Love (41)
  5. CSS3 2D transforms (40)