解决方案 »

  1.   

    算我话没说清楚……
    我是希望在另一个专门的页面输出我的字符串,而不是在我提交POST请求的页面上
    我现在只是用php模拟POST请求,以后要变的
    就比如,我用一个C程序向某个URL提交了一个POST请求,传了个字符串过去
    然后我希望打开一个指定的页面,例如output.php,在这上面看到我程序传过去的字符串
    刚开始学php,可能post请求的用法我理解错了……但我的需求应该说清楚了,希望各位指教我该怎么做?
      

  2.   

    可以用數據庫或文件保存。a.php<?php
    $uri = "http://localhost/handle.php";
    // 参数数组
    $data = array (
            'name' => 'tanteng' 
    // 'password' => 'password'
    );
     
    $ch = curl_init ();
    // print_r($ch);
    curl_setopt ( $ch, CURLOPT_URL, $uri );
    curl_setopt ( $ch, CURLOPT_POST, 1 );
    curl_setopt ( $ch, CURLOPT_HEADER, 0 );
    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
    $return = curl_exec ( $ch );
    curl_close ( $ch );
     
    print_r($return);
    ?>
    handle.php<?php
    $name = isset($_POST['name'])? $_POST['name'] : '';
    file_put_contents('tt.txt', $name, true);
    echo 'success';
    ?>
    b.php<?php
    echo 'this is the posted data';
    if(file_exists('tt.txt')){
    $name = file_get_contents('tt.txt');
        if(!empty($name)){
            echo '您好,',$name.'!';
        }
    }
    ?>