file_get_contentsでPOSTリクエスト送信

PHP

ソースコード

https://example.com/sample.php?mode=test&id=001 function post_access($url=null , $queries=array()){ if(!$url){return;} $query = http_build_query($queries, "", "&"); $options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => $query, ) ); $context = stream_context_create($options); return file_get_contents($url , false , $context); }

実行

$queries = array( 'mode' => test, 'id' => 001, ); post_access('https://example.com/sample.php' , array());