使用cUrl url中的$_POST[“username”]


using $_POST["username"] in cUrl url

我有一个基本形式为的页面

<form action="r.php" method="post">
    <span>
    <input type="text" placeholder="Notch" id="minime_url_textbox" name="u">
    <label class="btn1 btn2 btn-2 btn-2g"> <input name="submit" type="submit" id="submit" value="Resolve"> </label>
    <div class="clearfix"> </div>
    </span>
    </form>

当他们在输入框中键入用户名时,按enter键,他们重定向到一个r.php,该php有一个include((的php文件,其中包含:

<?php
//Urls to scrape from.
$user = isset($_GET['u']) ? $_GET['u'] : 'safetrbgds';
$URLs = array();
$URLs[] = 'http://namemc.com/u/'.$user;
$working = '';
//Curl scraper.
foreach($URLs as $URL){
    $ch     = curl_init();
    curl_setopt($ch, CURLOPT_URL, $URL);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);        
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $page = curl_exec($ch);
    $text = strip_tags($page);
    $accounts = array();
    preg_match_all('/('w+) 's+ is 's+ available/x',$text,$accounts);
    foreach($accounts[0] as $account){
        $working .= ''.$account.''. PHP_EOL . '';
    }
}
//Put the scraped proxies into the new .txt file.
file_put_contents('accounts.txt', $working, FILE_APPEND);
?>

它确实适用于$user=isset($_GET['u']($_GET['u']:'safetrbgds';对于安全的bgd,但对于用户实际被困的那些。

我试过了:

$URLs[] = 'http://namemc.com/u/{$_POST["username"];}';

我只需要它来结束渲染,例如:$URLs[]='http://namemc.com/u/test';

<?php
//Urls to scrape from.
$user = isset($_POST['u']) ? $_POST['u'] : 'safetrbgds';
$URL = 'http://namemc.com/u/'.$user;
$working = '';
    $ch     = curl_init();
    curl_setopt($ch, CURLOPT_URL, $URL);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);        
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $page = curl_exec($ch);
    $text = strip_tags($page);
    $accounts = array();
    preg_match_all('/('w+) 's+ is 's+ available/x',$text,$accounts);
    foreach($accounts[0] as $account){
        $working .= ''.$account.''. PHP_EOL . '';
    }

//Put the scraped proxies into the new .txt file.
file_put_contents('accounts.txt', $working, FILE_APPEND);
?>

试试这个。

以下是您需要的所有数据的解决方案。

<?php
//Urls to scrape from.
$user = isset($_POST['u']) ? $_POST['u'] : 'safetrbgds';
$URL = 'http://namemc.com/u/'.$user;
$ch     = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, 1);        
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$page = curl_exec($ch);
$accounts = array();
preg_match_all('/<div class="alert alert-.*" role="alert">(.*)<'/div>/',$page,$accounts);
$data = !empty($accounts[0][0]) ? $accounts[0][0] : false;
$data = strip_tags($data, '<p></p>');
$data = str_replace('To visit Mojang and grab this name, click here.', '', $data);
$data = str_replace('<p style="margin-top: 0.5em">Want this name? Worried someone else will get it first? Snipe it with www.mcsniper.com! (Advertisement)</p>','',$data);
$data = str_replace('<p>', '',$data);
$data = str_replace('</p>', '',$data);
$data = $data.PHP_EOL;
file_put_contents('accounts.txt', $data, FILE_APPEND);
?>

输出帐户.txt

testsettestest is available! 
admin is unavailable!
Shieldon has been available since 2015-05-12 20:43:41+00. 
Zoroark will become available at 2015-06-11 18:53:57+00.