当前位置:  编程技术>php
本页文章导读:
    ▪将数据库的查询结果序列化成json格式 - 庭上杨柳      <?phpclass link_mysql{private $host,$uid,$pwd,$db,$link,$res;function link_mysql($_host,$_uid,$_pwd,$_db){$this->host = $_host;$this->uid = $_uid;$this->pwd = $_pwd;$this->db = $_db;$this->link = mysql_connect($this->host,$this->.........
    ▪PHP利用GD库画曲线 - 庭上杨柳      效果: PHP代码 <?php Header('Content-type: image/png;Charset:utf-8'); //声明图片$im = imagecreate(400,200);//get color.$bg = imagecolorallocate($im,0,0,0);$red = imagecolorallocate($im,255,0,255);$white = imagecolorallocate($im,255,255,255.........
    ▪php 使用curl模拟登录discuz以及模拟发帖 - 与时俱进      <?php$discuz_url = 'http://127.0.0.1/discuz/';//论坛地址$login_url = $discuz_url .'logging.php?action=login';//登录页地址$post_fields = array();//以下两项不需要修改$post_fields['loginfield'] = 'username';$post_fields['loginsubmit'].........

[1]将数据库的查询结果序列化成json格式 - 庭上杨柳
    来源:    发布时间: 2013-11-07
<?php
class link_mysql{
private $host,$uid,$pwd,$db,$link,$res;
function link_mysql($_host,$_uid,$_pwd,$_db){
$this->host = $_host;
$this->uid = $_uid;
$this->pwd = $_pwd;
$this->db = $_db;
$this->link = mysql_connect($this->host,$this->uid,$this->pwd);
mysql_select_db($this->db,$this->link);
}
function exec_sql($sql){
//if you use insert sentence,then you must open your link;
$res = mysql_query($sql);
return $res;
}
}
$obj_link = new link_mysql('localhost','***','***','website');
$res = $obj_link->exec_sql("select * from userinfo");
$str = "[";
while($rows = mysql_fetch_assoc($res)){
$str = $str."{name:$rows[name],password:$rows[password],age:$rows[age]},";
}
$str = rtrim($str,',') ."]";
echo $str;
?>

本文链接:http://www.cnblogs.com/xtyang/p/3207422.html,转载请注明。


    
[2]PHP利用GD库画曲线 - 庭上杨柳
    来源:    发布时间: 2013-11-07

效果:

PHP代码

<?php
Header('Content-type: image/png;Charset:utf-8'); //声明图片

$im = imagecreate(400,200);

//get color.
$bg = imagecolorallocate($im,0,0,0);
$red = imagecolorallocate($im,255,0,255);
$white = imagecolorallocate($im,255,255,255);

$arrowX = array(394,97,399,100,394,103);
$arrowY = array(197,5,200,0,203,5);

//画曲线
for($i=0;$i<380;$i+=0.1){
$x = $i/20;
$y = sin($x);
$y = 100 + 40*$y;
imagesetpixel($im,$i+10,$y,$red);
}

//画X轴和Y轴
imageline($im,0,100,394,100,$white);
imageline($im,200,5,200,200,$white);

//画坐标title
imagestring($im,4,350,110,'XShaft',$white);

//画箭头
imagefilledpolygon($im,$arrowX,3,$white);
imagefilledpolygon($im,$arrowY,3,$white);

imagepng($im);
imagedestroy($im);

?>

本文链接:http://www.cnblogs.com/xtyang/p/3208495.html,转载请注明。


    
[3]php 使用curl模拟登录discuz以及模拟发帖 - 与时俱进
    来源:    发布时间: 2013-11-07

<?php
$discuz_url = 'http://127.0.0.1/discuz/';//论坛地址
$login_url = $discuz_url .'logging.php?action=login';//登录页地址


$post_fields = array();
//以下两项不需要修改
$post_fields['loginfield'] = 'username';
$post_fields['loginsubmit'] = 'true';
//用户名和密码,必须填写
$post_fields['username'] = 'tianxin';
$post_fields['password'] = '111111';
//安全提问
$post_fields['questionid'] = 0;
$post_fields['answer'] = '';
//@todo验证码
$post_fields['seccodeverify'] = '';

//获取表单FORMHASH
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
preg_match('/<input\s*type="hidden"\s*name="formhash"\s*value="(.*?)"\s*\/>/i', $contents, $matches);
if(!empty($matches)) {
$formhash = $matches[1];
} else {
die('Not found the forumhash.');
}

 

//POST数据,获取COOKIE,cookie文件放在网站的temp目录下
$cookie_file = tempnam('./temp','cookie');

$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);

//取到了关键的cookie文件就可以带着cookie文件去模拟发帖,fid为论坛的栏目ID
$send_url = $discuz_url."post.php?action=newthread&fid=2";


$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);

//这里的hash码和登陆窗口的hash码的正则不太一样,这里的hidden多了一个id属性
preg_match('/<input\s*type="hidden"\s*name="formhash"\s*id="formhash"\s*value="(.*?)"\s*\/>/i', $contents, $matches);
if(!empty($matches)) {
$formhash = $matches[1];
} else {
die('Not found the forumhash.');
}


$post_data = array();
//帖子标题
$post_data['subject'] = 'test2';
//帖子内容
$post_data['message'] = 'test2';
$post_data['topicsubmit'] = "yes";
$post_data['extra'] = '';
//帖子标签
$post_data['tags'] = 'test';
//帖子的hash码,这个非常关键!假如缺少这个hash码,discuz会警告你来路的页面不正确
$post_data['formhash']=$formhash;


$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_REFERER, $send_url); //伪装REFERER
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$contents = curl_exec($ch);
curl_close($ch);

//清理cookie文件
unlink($cookie_file);

?>


本文链接:http://www.cnblogs.com/top5/p/3208700.html,转载请注明。


    
最新技术文章:
▪PHP函数microtime()时间戳的定义与用法
▪PHP单一入口之apache配置内容
▪PHP数组排序方法总结(收藏)
▪php数组排序方法大全(脚本学堂整理奉献)
▪php数组排序的几个函数(附实例)
▪php二维数组排序(实例)
▪php根据键值对二维数组排序的小例子
▪php验证码(附截图)
▪php数组长度的获取方法(三个实例)
▪php获取数组长度的方法举例
▪判断php数组维度(php数组长度)的方法
▪php获取图片的exif信息的示例代码
▪PHP 数组key长度对性能的影响实例分析
▪php函数指定默认值的方法示例
▪php提交表单到当前页面、提交表单后页面重定...
▪php四舍五入的三种实现方法
▪php获得数组长度(元素个数)的方法
▪php日期函数的简单示例代码
▪php数学函数的简单示例代码
▪php字符串函数的简单示例代码
▪php文件下载代码(多浏览器兼容、支持中文文...
▪php实现文件下载、支持中文文件名的示例代码...
▪php文件下载(防止中文文件名乱码)的示例代码
▪解决PHP文件下载时中文文件名乱码的问题
▪php数组去重(一维、二维数组去重)的简单示例
▪php小数点后取两位的三种实现方法
▪php Redis 队列服务的简单示例
▪PHP导出excel时数字变为科学计数的解决方法
▪PHP数组根据值获取Key的简单示例
▪php数组去重的函数代码示例
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3