代码如下 | 复制代码 |
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <body> |
loginajax.php文件代码
<!--{因为loginajax.php是由js形式调用输出,所以在这个文件里面的代码由于按js输出形式才能正确被显示哦。}-->
代码如下 | 复制代码 |
<?php |
本文章原创于http://www.111cn.net/phper/php.html转载注明来源,谢谢合作。
if ('source' == $_get['act']) { //查看源代码
show_source($_server["script_filename"]);
exit;
} //end if
set_time_limit(0);
for ($i = 0; $i < 5000; $i++) {
$users[] = 'tom_' . $i;
} //end for
$width = 500; //显示的进度条长度,单位 px
$total = count($users); //总共需要操作的记录数
$pix = $width / $total; //每条记录的操作所占的进度条单位长度
$progress = 0; //当前进度条长度
?>
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<style>
body, div input { font-family: tahoma; font-size: 9pt }
</style>
<script language="网页特效">
<!--
function updateprogress(smsg, iwidth)
{
document.getelementbyid("status").innerhtml = smsg;
document.getelementbyid("progress").style.width = iwidth + "px";
document.getelementbyid("percent").innerhtml = parseint(iwidth / <?php echo $width; ?> * 100) + "%";
}
//-->
</script>
</head>
<body>
<div style="margin: 4px; padding: 8px; border: 1px solid gray; background: #eaeaea; width: <?php echo $width+8; ?>px">
<div><font color="gray">如下进度条的动态效果由服务器端 php 程序结合客户端 网页特效 程序生成。</font></div>
<div style="padding: 0; background-color: white; border: 1px solid navy; width: <?php echo $width; ?>px">
<div id="progress" style="padding: 0; background-color: #ffcc66; border: 0; width: 0px; text-align: center; height: 16px"></div>
</div>
<div id="status"> </div>
<div id="percent" style="position: relative; top: -30px; text-align: center; font-weight: bold; font-size: 8pt">0%</div>
</div>
<?php
flush(); //将输出发送给客户端浏览器
foreach ($users as $user) {
// 在此处使用空循环模拟较为耗时的操作,实际应用中需将其替换;
// 如果你的操作不耗时,我想你就没必要使用这个脚本了 :)
for ($i = 0; $i < 10000; $i++) {
;;
}
?>
<script language="javascript">
updateprogress("正在操作用户"<?php echo $user; ?>" ....", <?php echo min($width, intval($progress)); ?>);
</script>
<?php
flush(); //将输出发送给客户端浏览器,使其可以立即执行服务器端输出的 javascript 程序。
$progress += $pix;
} //end foreach
// 最后将进度条设置成最大值 $width,同时显示操作完成
?>
<script language="javascript">
updateprogress("操作完成!", <?php echo $width; ?>);
</script>
<?php
flush();
?>
<input type="button" value="查看源码" onclick="document.location.href='<?php echo $_server['php_self']; ?>?act=source'" />
</body>
</html>
/*
下面这几款php生成flash文件代码,是从简单的生成swf文件到生成 flash动画文件等,每个实例都是经典的。
*/
//首先开启php扩展php_ming
$f = new swffont( '_sans' );
$t = new swftextfield();
$t->setfont( $f );
$t->setcolor( 0, 0, 0 );
$t->setheight( 400 );
$t->addstring( 'hello world' );
$m = new swfmovie();
$m->setdimension( 2500, 800 );
$m->add( $t );
$m->save( 'hello.swf' );
?>
******************************************************************************
例二:让文本动起来text.php
<?php
$f = new swffont( '_sans' );
$pt = new swftextfield();
$pt->setfont( $f );
$pt->setcolor( 0, 0, 0 );
$pt->setheight( 400 );
$pt->addstring( '1000' );
$tt = new swftextfield();
$tt->setfont( $f );
$tt->setcolor( 192, 192, 192, 90 );
$tt->setheight( 350 );
$tt->addstring( 'points' );
$m = new swfmovie();
$m->setdimension( 2500, 800 );
$pts = $m->add( $pt );
$pts->moveto( 0, 0 );
$tts = $m->add( $tt );
$tts->moveto( 1300, 200 );
for( $i = 0; $i < 10; $i++ ) {
$m->nextframe();
$pts->scaleto( 1.0 + ( $i / 10.0 ), 1.0 + ( $i / 10.0 ) );
}
$m->save( 'text.swf' );
?>
*****************************************************************************
例三:绘制一些图形 绘制简单的直线 line.php
<?php
$m = new swfmovie();
$m->setdimension( 300, 300 );
$s = new swfshape();
$s->setline( 10, 0, 0, 0 );
$s->movepento( 10, 10 );
$s->drawlineto( 290, 290 );
$m->add( $s );
$m->save( 'line.swf' );
?>
******************************************************************************
例四:旋转直线
<?php
$m = new swfmovie();
$m->setdimension( 300, 300 );
$s = new swfshape();
$s->setline( 5, 0, 0, 0 );
$s->movepento( -100, -100 );
$s->drawlineto( 100, 100 );
$ts = $m->add( $s );
$ts->moveto( 150, 150 );
for( $i = 0; $i < 100; $i++ ) {
$ts->rotate( 10 );
$m->nextframe();
}
$m->save( 'rotate.swf' );
?>
***************************************************************************
例五:
使用图片
文本和诸如直线、圆、弧、曲线和矩形之类的简单矢量图形都是十分优秀的,但在理想的情况下,您必须能访问这些 flash 动画中的图片。值得庆幸的是,ming 库使您可以轻松的使用图片,如下所示
<?php
$img = new swfbitmap( file_get_contents( 'megan.jpg' ) );
$s = new swfshape();
$imgf = $s->addfill( $img );
$s->setrightfill( $imgf );
$s->movepento( 0, 0 );
$s->drawlineto( $img->getwidth(), 0 );
$s->drawlineto( $img->getwidth(), $img->getheight() );
$s->drawlineto( 0, $img->getheight() );
$s->drawlineto( 0, 0 );
$m = new swfmovie();
$m->setdimension( $img->getwidth() * 2, $img->getheight() * 2 );
$is = $m->add( $s );
$is->moveto( $img->getwidth() / 2, $img->getheight() / 2 );
for( $i = 0; $i < 10; $i++ )
{
$is->skewx( 0.02 );
$is->skewy( -0.03 );
$m->nextframe();
}
$m->save( 'image.swf' );
代码如下 | 复制代码 |
session_start();
|
/* 用户登陆操作*/
代码如下 | 复制代码 |
if($username&&$pw){ if($username==user&&$pw==pw){ /* 用户登陆成功,*/ // 更新数据表;表登陆次数和时间,都置零; $mod_content="`login_times`=0,`login_date`=0"; $condition="`id`=1"; $db->update('limit_login',$mod_content,$condition); echo '<script language="网页特效" type="text/网页特效">' . 'window.location="success.php"</script>'; }else{ //在第一次出错时,设置密码出错次数为1,把登陆时是session 保存的时间放入数据库; if($row['login_times']==0&&$row['login_date']==0){ $mod_content="`login_times`=1,`login_date`='".$_session['time']."'"; $condition="`id`=1"; $db->update('limit_login',$mod_content,$condition); }else{ $mod_content="`login_times`=`login_times`+1"; $condition="`id`=1"; $db->update('limit_login',$mod_content,$condition); } /* 提示用户还有几次机会*/ if($row['login_times']<3){ $row['login_times']++;// 这里登陆次数加1,和上面的说的原因一样,是因不能同步连接 数据库所致; echo'密码错误!错误次数为:'.$row['login_times'].'次<br>'; $remain_times=3-$row['login_times']; echo '你还有'.$remain_times.'登陆机会'; } } }else{ echo '用户名和密码不能为空!'; } } |
?>
<form action="" method="post" >
username:<input type="text" name="username" value="" maxlength="40"/><br>
password:<input type="password" name="pw" /><br>
<input type="submit" name="submit" value="login"/>
</form>
现在用php采集远程图片是很简单的事情,但是我们要把采集过来的数据进行过滤,这恐怕得用到正则表达式了,下面的程序是采集远程图片图片并且替换图片地址代码。
$dir_date=date('y/m/d');//日期文件夹
$dir_name="images/$dir_date";//文件夹路径
function mkdirm($path) //取文件夹名
{
if (!file_exists($path)) //判断是否存在
{
mkdirm(dirname($path)); //返回路径中的目录部分
mkdir($path, 0777); //创建文件夹和权限
}
}
mkdirm($dir_name);//创建文件夹
//$files = file_get_contents('http://www.ywsp.com');
$files ='<img" width=100% src="http://img.111cn.net/img/bid_v2/bid_v2_content/p_bid.gif" alt="普通任务" /><img width="272px" height="60px" style="padding-top: 10px;"" width=100% src="http://img.111cn.net/img/index_v3/20100611001.gif">';
// 图片地址转换一下 $p=preg_replace('//image//', 'http://qq.ip138.com/image/', $pg[1]);
$reg = "/<img[^>]*src="(http://(.+)/(.+).(jpg|gif|bmp|bnp))"/isu";
$img=preg_match_all($reg,$files,$imgs);
for ($i=0;$i<count($imgs[0]);$i++)
{
//echo "".$imgs[1][$i]." <br> ";
//保存图片
$opts = array(
'http'=>array(
'header'=>"referer: http://www.111cn.net/ "
)
);
$context = stream_context_create($opts);
header( 'content-type: image/jpeg' );
$fileresource = @file_get_contents( $imgs[1][$i],false,$context) ;
$image_old.=""".$imgs[1][$i].""".","; //先把所有网址变为一个数如1,2,3,4
$image_new.=""".$dir_name."/".mktime().$i.".jpg".""".","; //先把所有新的图片地址变为一个数如1,2,3,4
file_put_contents($dir_name."/".mktime().$i.".jpg", $fileresource);
//保存图片
}
$image_old=substr($image_old,0,(strlen($image_old)-1));//把网址最后个逗号去掉
$image_new=substr($image_new,0,(strlen($image_new)-1));//把新网址最后个逗号去掉
//print_r($p);
$image_old=explode(",",$image_old);//分割多个
$image_new=explode(",",$image_new);//分割多个
$files=str_replace($image_old,$image_new,$files); //把网址跟新的图片网址调用进去替换
echo $files;