php類比post模式開啟頁面

來源:互聯網
上載者:User
php類比post方式開啟頁面
我登入了後台,想在後台類比用post方式跳轉到另一個頁面並處理這些資料,可是總是彈出叫我重新登入的提示,我估計是類比post方式跳轉時,已經失去了$_SESSION值。請問該怎麼處理這種情況?
代碼如下:
$post_string='detail=addaction&subva=0&name=testadmin&password=123456&sex=1'
$context = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded\r\nUser-Agent : Jimmy\'s POST Example beta\r\nContent-length:'.strlen($post_string)+8,
'content' => 'mypost='.$post_string
)
);
$stream_context = stream_context_create($context);
$data = file_get_contents("http://xxxxxxxx/xxxx/main.php", false, $stream_context);
echo $data;

------解決方案--------------------
1)先POST資料到到登陸畫面
2)返回的結果裡會有一個Cookie:SessionID=xxxxxxxxxxxx
3) 取出SessionID,然後按照你上面的方式POST

'header' => 'Content-type: application/x-www-form-urlencoded\r\nUser-Agent : Jimmy\'s POST Example beta\r\nContent-length:'.strlen($post_string)+8,

'header' => 'Cookie: SessionID=xxxxxxxxx;Content-type: application/x-www-form-urlencoded\r\nUser-Agent : Jimmy\'s POST Example beta\r\nContent-length:'.strlen($post_string)+8,

Cookie的格式記不大清楚,以上只是Sample.
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.