我正在尝试用 php 学习 curl。我知道可以使用 curl 使用 post 方法将值发送到另一个脚本。但是,如果我想要那样,在第一次发送该值之后执行并使用 post 方法再次返回 .... 是可能的。在我的两个脚本上:
索引.php
<?php $url = 'http://localhost/curl/test.php'; $post_data = array( 'first' => '1', 'second' => '2', 'third' => '3' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $output = curl_exec($ch); curl_close($ch); print_r($output); ?>
和test.php
<?php $a = $_POST['first']; $b = $_POST['second']; $c = $a+$b; $d = $b-$a; $e = $a*$b; $output = array( 'choose' => $c, 'choose1' => $d, 'choose2' => $e ); print_r($output); ?>
这里 index.php 通过 post 方法发送,我可以使用 $_POST['first'] 访问它。如果我想从这里 test.php 传输 $output 数组并可以从 index.php 以 $_POST['choose'] 的形式访问它们,这可能吗?