本文整理汇总了PHP中Snoopy::setcookies方法的典型用法代码示例。如果您正苦于以下问题:PHP Snoopy::setcookies方法的具体用法?PHP Snoopy::setcookies怎么用?PHP Snoopy::setcookies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Snoopy
的用法示例。
在下文中一共展示了Snoopy::setcookies方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getName
/**
* 学校验证
* @method getName
* @param [type] $stu_number [学号]
* @param [type] $pwd [密码]
* @return [string/bool] [验证成功返回姓名,验证失败返回false]
* @author NewFuture[newfuture@yunyin.org]
*/
function getName($stu_number, $pwd)
{
/*基本信息*/
$ACTION_URL = 'http://jw.tifert.edu.cn/2003/Logon.do?method=logon';
$INFO_URL = 'http://jw.tifert.edu.cn/2003/framework/main.jsp';
$SUCCESS_KEY = '<script language=\'javascript\'>window.location.href=\'http://jw.tifert.edu.cn/2003/framework/main.jsp\';</script>';
$START_FALG = '当前用户:';
$END_FLAG = '</td>';
$snoopy = new Snoopy();
/*设置请求头,非必需 */
$snoopy->referer = 'http://jw.tifert.edu.cn/2003/';
$snoopy->rawheaders['Pragma'] = 'no-cache';
$snoopy->rawheaders['X_FORWARDED_FOR'] = get_client_ip();
/*用户学号和密码*/
$input['USERNAME'] = $stu_number;
$input['PASSWORD'] = $pwd;
//模拟登陆
$snoopy->submit($ACTION_URL, $input);
$result = $snoopy->results;
//登录结果页面
if (strpos($result, $SUCCESS_KEY) === false) {
/*验证失败*/
return false;
} else {
/*登录成功,保存cookie信息页面抓取信息*/
$snoopy->setcookies();
$snoopy->fetch($INFO_URL);
$results = $snoopy->results;
$s = strpos($results, $START_FALG) + strlen($START_FALG);
//起始位置
$e = strpos($results, $END_FLAG, $s);
$name = substr($results, $s, $e - $s);
return trim($name);
}
}
示例2: wikiLogin
function wikiLogin()
{
global $login;
global $wikilogin;
global $snoopy;
global $wikiapi_url;
while (!$login) {
$wikilogin['action'] = 'login';
$wikilogin['lgname'] = trim(ask('wiki user name'));
$wikilogin['lgpassword'] = getPassword('wikis');
$wikilogin['format'] = 'php';
if (!$snoopy instanceof Snoopy) {
$snoopy = new Snoopy();
}
if (!$snoopy->submit($wikiapi_url, $wikilogin)) {
I2CE::raiseError("Could not log in to {$wikiapi_url}");
continue;
}
$res = unserialize($snoopy->results);
if (array_key_exists('error', $res)) {
I2CE::raiseError("Could not login:\n" . print_r($res['error'], true));
continue;
}
if (!array_key_exists('login', $res) || !is_array($res['login']) || !array_key_exists('result', $res['login'])) {
I2CE::raiseError("Error logging in:" . print_r($res, true));
continue;
}
if ($res['login']['result'] == 'NeedToken' && array_key_exists('token', $res['login']) && $res['login']['token']) {
$wikilogin['lgtoken'] = $res['login']['token'];
$snoopy->setcookies();
if (!$snoopy->submit($wikiapi_url, $wikilogin)) {
I2CE::raiseError("Could not log in to {$wikiapi_url}");
continue;
}
$res = unserialize($snoopy->results);
if (array_key_exists('error', $res)) {
I2CE::raiseError("Could not login:\n" . print_r($res['error'], true));
continue;
}
if (!array_key_exists('login', $res) || !is_array($res['login']) || !array_key_exists('result', $res['login'])) {
I2CE::raiseError("Error logging in");
continue;
}
}
if ($res['login']['result'] != 'Success') {
I2CE::raiseError("No success logging in:" . print_r($res, true));
continue;
}
I2CE::raiseError("Logged into {$wikiapi_url} as " . $wikilogin['lgname']);
$snoopy->setcookies();
$login = true;
}
return $login;
}
示例3: getName
/**
* function getName($stu_number,$pwd)
* 获取
* string name 验证成功返回姓名
* bool false /null 验证失败返回false或空值
*
* @author 梁崇军
*
* @param string $stu_number 学号
* @param string $pwd 登陆密码
* @return mixed
*/
function getName($stu_number, $pwd)
{
/*验证地址--urp密码验证页*/
$action_url = 'http://urp.nankai.edu.cn/userPasswordValidate1.portal';
$snoopy = new Snoopy();
$snoopy->rawheaders['Pragma'] = 'no-cache';
$snoopy->rawheaders['X_FORWARDED_FOR'] = get_client_ip();
$success_words = '<script type="text/javascript">location.href = \'http://urp.nankai.edu.cn/index.portal\';</script>';
$error_key = '密码错误';
$snoopy->referer = 'http://urp.nku.cn';
/*用户学号和密码*/
$input['Login.Token1'] = $stu_number;
$input['Login.Token2'] = $pwd;
$snoopy->submit($action_url, $input);
//模拟登陆
$result = $snoopy->results;
//登录结果页面
if (strpos($result, $error_key) !== false) {
return false;
} elseif (strpos($result, $success_words) !== false) {
/*登录成功,保存cookie信息页面抓取信息*/
$snoopy->setcookies();
$snoopy->fetchtext('http://urp.nankai.edu.cn/index.portal');
$text = $snoopy->results;
// $substr = substr($input, strlen($start) + strpos($input, $start) , (strlen($input) - strpos($input, $end)) * (-1));
$get_name = function ($input, $start, $end) {
return substr($input, strlen($start) + strpos($input, $start), (strlen($input) - strpos($input, $end)) * -1);
};
$name = $get_name($text, '您好,', ' 欢迎来到南开大学');
return $name;
} else {
$error = '未知错误[可能信息门户已经改版]返回信息:' . htmlspecialchars($result);
E($error);
return false;
}
}
示例4: checkhaslogin
public function checkhaslogin()
{
include_once "addons/library/Snoopy.class.php";
include_once "addons/library/simple_html_dom.php";
include_once "addons/library/phpQuery/phpQuery.php";
$snoopy = new Snoopy();
$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Win64; x64; Trident/6.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; EIE10;ENUSWOL)";
$snoopy = new Snoopy();
$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Win64; x64; Trident/6.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; EIE10;ENUSWOL)";
//dump($_COOKIE);将客户端cookie传给 本服务器$_SESSION['jwc_cookies'] 然后传给snnopy
if ($_COOKIE['ASP_NET_SessionId'] != null) {
$_SESSION['jwc_cookies'] = array('ASP.NET_SessionId' => $_COOKIE['ASP_NET_SessionId']);
}
if ($snoopy->fetch("http://210.42.38.26:81/jwc_glxt/")) {
if ($_SESSION['jwc_cookies'] != null) {
$snoopy->cookies = $_SESSION['jwc_cookies'];
} else {
$snoopy->setcookies();
}
$html = str_get_html($snoopy->results);
$view = $html->find('#__VIEWSTATE', 0)->value;
$event = $html->find('#__EVENTVALIDATION', 0)->value;
//var_dump($html->getElementById("#__VIEWSTATE"));
$_SESSION['jwc_event'] = $event;
$_SESSION['jwc_view'] = $view;
$_SESSION['jwc_cookies'] = $snoopy->cookies;
//dump($_SESSION);
}
$snoopy->cookies = $_SESSION['jwc_cookies'];
//dump($_SESSION);
if ($snoopy->fetch("http://210.42.38.26:81/jwc_glxt/Stu_Notice/Notice_Query.aspx")) {
$doc = phpQuery::newDocumentHTML($snoopy->results);
$student = pq("#ctl00_lblSignIn")->html();
if (!is_null($student) && $student != '') {
$return['result'] = "yes";
$return['data'] = "已经登录";
$_SESSION['login'] = true;
exit(json_encode($return));
//redirect(U("jwc/Index/login"));
} else {
$return['result'] = "no";
$return['data'] = "没有登录";
$_SESSION['login'] = false;
echo json_encode($return);
}
}
}