你能实现模拟POST提交登录http://bbs.lampbrother.net/ 这个网站吗??

WBOY
リリース: 2016-06-06 20:46:43
オリジナル
1721 人が閲覧しました

无论你用什么方法都行?只要能写出代码,腾讯面试题啊

回复内容:

无论你用什么方法都行?只要能写出代码,腾讯面试题啊

<code class="lang-php"><?php $post_data = http_build_query(array(
    'step' => 2,
    'lgt' => 2,    
    'forward' => '',
    'pwuser' => 'hehe@163.com',
    'pwpwd' => '123456',
    'question' => 0,
    'customquest' => '',
    'answer' => '',
    'hideid' => 0,
    'submit' => '',
    'jumpurl' => 'http://bbs.lampbrother.net/index.php',
));
$login_url = 'http://bbs.lampbrother.net/login.php';
$user_agent = ' Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0';

$cookie_file = dirname(__FILE__).'/cookie.txt';
touch($cookie_file);

$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_COOKIESESSION => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER => false,
    CURLOPT_VERBOSE => false,
    CURLOPT_COOKIEJAR => $cookie_file,
    CURLOPT_COOKIEFILE => $cookie_file,
    CURLOPT_POSTFIELDS => $post_data,
    CURLOPT_POST => true,
    CURLOPT_USERAGENT => $user_agent,
    CURLOPT_URL => $login_url,
));
$response = curl_exec($ch);
curl_close($ch);

$response = convert2utf8($response);

$login_status = preg_match('#<p>]*>您已经顺利登录</p>#u', $response, $match) ? 'success': 'failed';
echo 'login ', $login_status;

/* functions */
function detectEncoding($str) {
    return mb_detect_encoding($str, array('UTF-8', 'CP936', 'BIG5', 'ASCII'));
}

function convert2gbk($str) {
    return convertEncoding($str, 'CP936');
}

function convert2utf8($str) {
    return convertEncoding($str, 'UTF-8');
}

function convertEncoding($str, $to_encoding) {
    if ($to_encoding !== ($encoding = detectEncoding($str))) {
        $str = mb_convert_encoding($str, $to_encoding, $encoding);
    }

    return $str;
}
</code>
ログイン後にコピー
関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!