PHP函數tempnam()

來源:互聯網
上載者:User

標籤:

該函數相關介紹:http://php.net/manual/zh/function.tempnam.php

tempnam函數能夠在指定目錄產生一個具有唯一檔案名的檔案名稱。通常應用於自訂SESSION檔案名稱的情況。

這個函數還是非常有用的。例如如果我們要使用curl偽造一個session,那麼就可以這樣用。

相關資料:http://www.phpjx.com/show_5919.html

<?php    function vlogin($url,$request){     session_start();    $cookie_jar = tempnam('./tmp','cookie');//在目前的目錄下產生一個隨機檔案名稱的臨時檔案     $ch = curl_init($url); //初始化curl模組     curl_setopt($ch, CURLOPT_HEADER, 0);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_POST, 1);//post方式提交     curl_setopt($ch, CURLOPT_POSTFIELDS, $request);//要提交的內容     //把返回$cookie_jar來的cookie資訊儲存在$cookie_jar檔案中     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);     $xianshi=curl_exec ($ch);     curl_close($ch); //get data after login       $curl="http://phpjx.local.com/login/session/show.php";//要抓取資料的頁面,該頁面有session判斷許可權    $ch=curl_init($curl);    curl_setopt($ch, CURLOPT_HEADER, 0);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_POST, 1);     curl_setopt($ch, CURLOPT_POSTFIELDS, "sitename=phpjx.com&siteurl=http://www.phpjx.com");    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);    $xianshi=curl_exec($ch);    curl_close($ch);    return $xianshi;    }    $url="http://phpjx.local.com/login/session/check.php";//我們向該頁面傳值,用來產生session,接著傳遞到想要抓取的那個頁面    $request="username=yansy";    echo vlogin($url, $request)?>


可以自行百度一下相關資料。

PHP函數tempnam()

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.