需要看目标的系统的URL了。 好像还有一种方法是通过Socket访问的,具体怎么写,请看一下这段代码吧: <?php # Script 9.1 - check_urls.php/* This page validates a list of URLs. * It uses fsockopen() and parse_url() to do so. */// This function will try to connect to a URL: function check_url ($url) { // Break the URL down into its parts: $url_pieces = parse_url ($url);
// Set the $path and $port: $path = (isset($url_pieces['path'])) ? $url_pieces['path'] : '/'; $port = (isset($url_pieces['port'])) ? $url_pieces['port'] : 80; // Connect using fsockopen(): if ($fp = @fsockopen ($url_pieces['host'], $port, $errno, $errstr, 30)) { // Send some data: $send = "HEAD $path HTTP/1.1\r\n"; $send .= "HOST: {$url_pieces['host']}\r\n"; $send .= "CONNECTION: Close\r\n\r\n"; fwrite($fp, $send);
代码:
function GetWebContent($host, $method, $str, $sessid = '')
{
$ip = gethostbyname($host);
$fp = fsockopen($ip, 80);
if (!$fp) return;
fputs($fp, "$method\r\n");
fputs($fp, "Host: $host\r\n");
if (!empty($sessid))
{
fputs($fp, "Cookie: PHPSESSID=$sessid; path=/;\r\n");
}
if ( substr(trim($method),0, 4) == "POST")
{
fputs($fp, "Content-Length: ". strlen($str) . "\r\n"); // 别忘了指定长度
}
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n\r\n");
if ( substr(trim($method),0, 4) == "POST")
{
fputs($fp, $str."\r\n");
}
while(!feof($fp))
{
$response .= fgets($fp, 1024);
}
$hlen = strpos($response,"\r\n\r\n"); // LINUX下是 "\n\n"
$header = substr($response, 0, $hlen);
$entity = substr($response, $hlen + 4);
if ( preg_match('/PHPSESSID=([0-9a-z]+);/i', $header, $matches))
{
$a['sessid'] = $matches[1];
}
if ( preg_match('/Location: ([0-9a-z\_\?\=\&\#\.]+)/i', $header, $matches))
{
$a['location'] = $matches[1];
}
$a['content'] = $entity;
fclose($fp);
return $a;
} /* 构造用户名,密码字符串 */
$str = ("username=myname&password=mypass&Submit=Login");
$response = GetWebContent("www.fqws.cn","POST /web2/Members/LoginCheck.asp HTTP/1.1", $str);
echo $response['location'];
echo $response['content']."<br>";
echo $response['sessid']."<br>";
if ( preg_match('/error\.php/i',$response['location']))
{
echo "登陆失败<br>";
} else {
echo "登陆成功<br>";
// 不可以访问user.php,因为不带sessid参数
//$response = GetWebContent("www.fqws.cn","GET /Member.asp?UserID=443 HTTP/1.1", '', '');
//echo $response['location']."<br>"; // 结果:error.php?errcode=2 // 可以访问user.php
//$response = GetWebContent("www.fqws.cn","GET /Member.asp?UserID=443 HTTP/1.1", '', $response['sessid']);
// echo $response['location']."<br>"; // 结果:user.php
}
?>
还有
echo "<script language=javascript>location.href('跳转页面地址');</script>";
也可以跳转.
都一样.
好像还有一种方法是通过Socket访问的,具体怎么写,请看一下这段代码吧:
<?php # Script 9.1 - check_urls.php/* This page validates a list of URLs.
* It uses fsockopen() and parse_url() to do so.
*/// This function will try to connect to a URL:
function check_url ($url) { // Break the URL down into its parts:
$url_pieces = parse_url ($url);
// Set the $path and $port:
$path = (isset($url_pieces['path'])) ? $url_pieces['path'] : '/';
$port = (isset($url_pieces['port'])) ? $url_pieces['port'] : 80; // Connect using fsockopen():
if ($fp = @fsockopen ($url_pieces['host'], $port, $errno, $errstr, 30)) { // Send some data:
$send = "HEAD $path HTTP/1.1\r\n";
$send .= "HOST: {$url_pieces['host']}\r\n";
$send .= "CONNECTION: Close\r\n\r\n";
fwrite($fp, $send);
// Read the response:
$data = fgets ($fp, 128);
// Close the connection:
fclose($fp);
// Return the response code:
list($response, $code) = explode (' ', $data);
if ($code == 200) {
return array($code, 'good');
} else {
return array($code, 'bad');
} } else { // No connection, return the error message:
return array($errstr, 'bad');
}
} // End of check_url() function.// Create the list of URLs:
$urls = array (
'http://zirzow.dyndns.org/php-general/NEWBIE/',
'http://video.google.com/videoplay?docid=-5137581991288263801&q=loose+change',
'http://www.securephpwiki.com/index.php/Email_Injection/',
'http://www.uic.rsu.ru/doc/web/php_coding_standard.html',
'http://nfl.dmcinsights.com/MadminY/',
'http://seagull.phpkitchen.com/'
);// Print a header:
echo '<h2>Validating URLs</h2>';// Kill the PHP time limit:
set_time_limit(0);// Validate each URL:
foreach ($urls as $url) { list($code, $class) = check_url ($url);
echo "<p><a href=\"$url\" target=\"_new\">$url</a> (<span class=\"$class\">$code</span>)</p>\n";
}
?>这个好像是一个读取yahoo股票报价的小程序
body 中用user password去判断。