PHP手机号码生成图片实例程序

 更新时间:2016年11月25日 15:44  点击:1457
以前做过一个招聘网站这样我们需要让别有采集不到我们客户的手机号码与邮箱地址了,所以我们会利用php实现从数据库读出来的手机号码与邮箱地址直接生成一张图片了,这样采集过去只能是图片并且无法识别了,下面我来给大家介绍两个实例。


PHP字符串处理-将手机号码生存图片

 

 代码如下 复制代码

   <?php
    ////电话号码转变成图片
    //$str 要显示的字串,$rand是否启用扰码
    function str_to_image($str,$w=130,$h=25,$rand=true)
    {
       //生成11位的数字图片
       Header("Content-type:image/png"); //告诉浏览器,下面的数据是图片,而不要按文字显示
       //定义图片宽高
       $nwidth=$w;
       $nheight=$h;
       //srand((double)microtime()*1000000); //取得目前时间的百万分之一秒值,以执行时的百万分之一秒当乱数种子
       $randval=$str; //11位数
       $im=@imagecreate($nwidth,$nheight) or die("Can't initialize new GD image stream"); //建立图象
       //图片色彩设置
       $background_color=imagecolorallocate($im,255,255,255); //匹配颜色
       $text_color=imagecolorallocate($im,23,14,91);
       //绘制图片边框
       imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background); //矩形区域着色
       imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color); //绘制矩形
       imagestring($im,8,10,4,$randval,$text_color); //绘制横式字串
       if($rand){
           //加入干扰因素
           for($i=0;$i<260;$i++)
           {
               $randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
               imagesetpixel($im,rand()%($nwidth-5),rand()%($nheight+5),$randcolor); //点
           }
       }
       //imagestring($im,3,5,5,"A Simple Text String",$text_color);
       //imageinterlace($im,1);
       imagepng($im); //建立png图型
       imagedestroy($im); //结束图型
    }

    $str =  '13087263453';
    echo str_to_image($str,$w=130,$h=25,$rand=true)

例2

 代码如下 复制代码


<?php //前面不要有空行
$id=$_GET[id];
include("admin/config.php");
$sql="select * from user where id=$id";
$data=mysql_fetch_array(mysql_query($sql));
$p=SBC_DBC($data[Phone],1);
function get_str($str,$strlen=16) {
$str=stripslashes($str);
for($i=0;$i<$strlen;$i++)
if(ord(substr($str,$i,1))>0xa0) $j++;
if($j%2!=0) $strlen++;
$tmp_str=substr($str,0,$strlen);
return $tmp_str;
}
if($p<>''){
//生成5位的数字图片
Header("Content-type:image/png"); //告诉浏览器,下面的数据是图片,而不要按文字显示

//定义图片宽高
$nwidth=120;
$nheight=25;
$im=@imagecreate($nwidth,$nheight) or die("Can't initialize new GD image stream"); //建立图象

//图片色彩设置
$background_color=imagecolorallocate($im,255,255,255); //匹配颜色
$text_color=imagecolorallocate($im,23,14,91);

//绘制图片边框
imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background); //矩形区域着色
imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color); //绘制矩形

//srand((double)microtime()*1000000); //取得目前时间的百万分之一秒值,以执行时的百万分之一秒当乱数种子
//$randval=rand();
$randval=$p; //5位数
imagestring($im,8,10,2,$randval,$text_color); //绘制横式字串


//加入干扰因素
//for($i=0;$i<478;$i++)
//{
//$randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
//imagesetpixel($im,rand()%100,rand()%30,$randcolor); //点
//}
//imagestring($im,3,5,5,"A Simple Text String",$text_color);
//imageinterlace($im,1);
imagepng($im); //建立png图型
imagedestroy($im); //结束图型

}else{
echo "<font size=2>商家未输入电话号码</font>";
}

?>

这里给大家介绍一个移动设备检查类了,从google找到的mobile-detect类,这个类可以ct判断android、ios、Tablet平板,浏览器,等比较完美完善的判断ipad,iPhone,win8等

使用方法

 代码如下 复制代码

<?php
    include 'Mobile_Detect.php';
    $detect = new Mobile_Detect();


    if ($detect->isMobile()) {
       // Any mobile device.
    }

    if($detect->isTablet()){
       // Any tablet device.
    }
    Check for a specific platform:

    if($detect->isiOS()){
       // Code to run for the Apple's iOS platform.
    }

    if($detect->isAndroidOS()){
       // Code to run for the Google's Android platform.
    }

官方实例

 代码如下 复制代码

<?php


require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
$scriptVersion = $detect->getScriptVersion();

?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <title>Mobile Detect Local Demo</title>
    <style type="text/css">
        html { font-size: 100%; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
        body { margin: 0; padding: 0 1em; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 1em; color: #333333; background-color: #ffffff; max-width:320px; }
        body, td { font-size: 1em; }
        table th { text-align:left; }
        a { color: #0088cc; text-decoration: underline; }
        a:hover { color: #005580; text-decoration: underline; }
        header h1 small { font-size:small; }
        section { margin-bottom:2em; }
        section h1 { font-size:100%; }
        .infoText { font-size:85%; }
        .response { color:red; }
        .computer { background-color:blue; color:white; }
        .tablet { background-color:yellow; color:black; }
        .phone, .true { background-color:green; color:white; }
        .sendDataButton { border-radius: 1em; -moz-border-radius: 1em; -webkit-border-radius: 1em; padding:0.5em 1em; cursor: pointer; }
        .sendDataButton_yes {
                color:white;
                border: 1px solid #56A00E;
                background: #74B042;
                font-weight: bold;
                color: #ffffff;
                text-shadow: 0 1px 0 #335413;
                background-image: -webkit-gradient(linear, left top, left bottom, from( #74B042 ), to( #56A00E )); /* Saf4+, Chrome */
                background-image: -webkit-linear-gradient( #74B042 , #56A00E ); /* Chrome 10+, Saf5.1+ */
                background-image:    -moz-linear-gradient( #74B042 , #56A00E ); /* FF3.6 */
                background-image:     -ms-linear-gradient( #74B042 , #56A00E ); /* IE10 */
                background-image:      -o-linear-gradient( #74B042 , #56A00E ); /* Opera 11.10+ */
                background-image:         linear-gradient( #74B042 , #56A00E );
        }
        .sendDataButton_no {
                color:white;
                border: 1px solid #cd2c24;
                background: red;
                font-weight: bold;
                color: #ffffff;
                text-shadow: 0 1px 0 #444444;
                background-image: -webkit-gradient(linear, left top, left bottom, from( #e13027 ), to( #b82720 )); /* Saf4+, Chrome */
                background-image: -webkit-linear-gradient( #e13027 , #b82720 ); /* Chrome 10+, Saf5.1+ */
                background-image:    -moz-linear-gradient( #e13027 , #b82720 ); /* FF3.6 */
                background-image:     -ms-linear-gradient( #e13027 , #b82720 ); /* IE10 */
                background-image:      -o-linear-gradient( #e13027 , #b82720 ); /* Opera 11.10+ */
                background-image:         linear-gradient( #e13027 , #b82720 );
        }
        #feedbackForm fieldset { border:1px dotted #333; }
        #feedbackForm label { font-weight:bold; font-size:85%; }
        #feedbackForm textarea { width: 260px; }
    </style>
  


</head>
<body>


<section>

    <p>This is a <b><?php echo $deviceType; ?></b>. Your UA is <b class="<?php echo $deviceType; ?>"><?php echo htmlentities($_SERVER['HTTP_USER_AGENT']); ?></b></p>

   


</section>


<!-- copy to GitHub demo.php -->
<section>
    <h1>Supported methods</h1>
    <table cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
            <th colspan="2">Basic detection methods</th>
        </tr>
        <tr>
            <td>isMobile()</td><td <?php $check = $detect->isMobile(); if($check): ?>class="true"<?php endif; ?>><?php var_dump($check); ?></td>
        </tr>
        <tr>
            <td>isTablet()</td><td <?php $check = $detect->isTablet(); if($check): ?>class="true"<?php endif; ?>><?php var_dump($check); ?></td>
        </tr>
        </tbody>
        <tbody>
        <tr>
            <th colspan="2">Custom detection methods</th>
        </tr>
        <?php foreach($detect->getRules() as $name => $regex):
                        $check = $detect->{'is'.$name}();
        ?>
            <tr>
                    <td>is<?php echo $name; ?>()</td>
                    <td <?php if($check): ?>class="true"<?php endif; ?>><?php var_dump($check); ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
        <tbody>
            <tr>
                <th colspan="2">Experimental version() method</th>
            </tr>
            <?php
            foreach($detect->getProperties() as $name => $match):
                $check = $detect->version($name);
                if($check!==false):
            ?>
            <tr>
                <td>version(<?php echo $name; ?>)</td>
                <td><?php var_dump($check); ?></td>
            </tr>
            <?php endif; ?>
            <?php endforeach; ?>
        </tbody>
        <tbody>
            <tr>
                <th colspan="2">Other tests</th>
            </tr>
            <tr>
                <td>isiphone()</td>
                <td><?php echo var_dump($detect->isiphone()); ?></td>
            </tr>
            <tr>
                <td>isIphone()</td>
                <td><?php echo var_dump($detect->isIphone()); ?></td>
            </tr>
            <tr>
                <td>istablet()</td>
                <td><?php echo var_dump($detect->istablet()); ?></td>
            </tr>
            <tr>
                <td>isIOS()</td>
                <td><?php echo var_dump($detect->isIOS()); ?></td>
            </tr>
            <tr>
                <td>isWhateverYouWant()</td>
                <td class="randomcrap"><?php echo var_dump($detect->isWhateverYouWant()); ?></td>
            </tr>
        </tbody>
    </table>

</section>

</body>
</html>


php-mobile-detect文件下载地焉: http://file.111cn.net/upload/2013/10/M.rar

如果我们是一维数据去重复项就不要说了有直接的函数了,但二维数据php未提供函数了,下面小编来给大家推荐两个不错的二维数组去重复项自定义函数吧。

例1

 代码如下 复制代码


<?php
function unique_array_2d($array2D,$stkeep=false,$ndformat=true)
{
       // 判断是否保留一级数组键 (一级数组键可以为非数字)
       if($stkeep) $stArr = array_keys($array2D);

       // 判断是否保留二级数组键 (所有二级数组键必须相同)
       if($ndformat) $ndArr = array_keys(end($array2D));

       //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
       foreach ($array2D as $v){
               $v = join(",",$v);
               $temp[] = $v;
       }

       //去掉重复的字符串,也就是重复的一维数组
       $temp = array_unique($temp);

       //再将拆开的数组重新组装
       foreach ($temp as $k => $v)
       {
               if($stkeep) $k = $stArr[$k];
               if($ndformat)
               {
                       $tempArr = explode(",",$v);
                       foreach($tempArr as $ndkey => $ndval) $output[$k][$ndArr[$ndkey]] = $ndval;
               }
               else $output[$k] = explode(",",$v);
       }

       return $output;
}

$array2D = array(
       'first'=>array('title'=>'1111','date'=>'2222'),
       'second'=>array('title'=>'1111','date'=>'2222'),
       'third'=>array('title'=>'2222','date'=>'3333')
);

echo "<pre>";
print_r(unique_array_2d($array2D,true));

/**
* 将二维数组通过指定的 key 去重
*
* @param array $arr 要去重的数组
* @param array $by  指定key去重,该参数不指定将返回 array()
* @return array
*/
function array_multunique($arr,$by = array()) {
       $temp = array();
       foreach($arr as $key => $val) {
               foreach($by as $v) {
                       $temp[$key] .= isset($val[$v]) ? $val[$v] : '';
               }
       }
       return array_intersect_key($arr,array_unique($temp));
}
/*$aa = array ( 
   array ('id' => 123, 'name' => '张三' ),  
   array ('id' => 123, 'name' => '李四' ),  
   array ('id' => 124, 'name' => '王五' ),  
   array ('id' => 125, 'name' => '赵六' ),  
   array ('id' => 126, 'name' => '赵六' )  
); 
$key = 'id'; 
array_multunique ($aa, array('id')); */

function array_remove_key($array,$keys){
       if (!is_array($array) || !is_array($keys)){
               return false;
       }
       foreach($array as $t){
               foreach($keys as $k){
                       unset($t[$k]);
               }
               $doc[]=$t;
       }
       return $doc;

}
/*$array = array(
       '0' => array('a' => 'aaaaa', 'b' => 'bbbbb', 'c' => array('d' => 'ddddd', 'e' => 'eeeee')),
       '1' => array('a' => 'aaaaa', 'b' => 'bbbbb', 'c' => array('d' => 'ddddd', 'e' => 'eeeee'))
);
print_r( array_remove_key($array,array('c')));*/

function array_remove_key_val(&$a,$b,$c){
       foreach ($a as $key=>$value){
               if ( isset($value[$b]) && ($value[$b]==$c) ){
                       unset($a[$key]);
               }
       }
}
/*$a=array(
       array('id'=>1,'num'=>10,'type'=>'news'),
       array('id'=>2,'num'=>100,'type'=>'pic')
);
print_r( array_remove_key_val($a,"id","1") );*/


例2

 

 代码如下 复制代码

/二维数组去掉重复值
function array_unique_fb($array2D){
     foreach ($array2D as $v){
         $v = join(",",$v);  //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
         $temp[] = $v;
     }
     $temp = array_unique($temp);    //去掉重复的字符串,也就是重复的一维数组
    foreach ($temp as $k => $v){
        $temp[$k] = explode(",",$v);   //再将拆开的数组重新组装
    }
    return $temp;
}


//二维数组去掉重复值  并保留键值
function array_unique_fb($array2D){
    foreach ($array2D as $k=>$v){
        $v = join(",",$v);  //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
  $temp[$k] = $v;
    }
 $temp = array_unique($temp);    //去掉重复的字符串,也就是重复的一维数组
    foreach ($temp as $k => $v){
        $array=explode(",",$v);  //再将拆开的数组重新组装
  $temp2[$k]["id"] =$array[0];  
  $temp2[$k]["litpic"] =$array[1];
  $temp2[$k]["title"] =$array[2];
  $temp2[$k]["address"] =$array[3];
  $temp2[$k]["starttime"] =$array[4];
  $temp2[$k]["endtime"] =$array[5];
  $temp2[$k]["classid"] =$array[6];
  $temp2[$k]["ename"] =$array[7];
 }
    return $temp2;
}

利用php调用discuz登录框方法有很多种,最常用的就是直接使用iframe方式调用了,还有就是直接在php页面中调用了,下面小编来给大家总结一些常用的方法。

方法一,直接使用iframe调用一个加了discuz登录功能的页面

 代码如下 复制代码

 <iframe src="/login.html" style="width:100%; height:32px" scrolling="no" frameborder="0" ></iframe>


login.html代码

 代码如下 复制代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title> c-gd.com-登录</title>
<style type="text/css">
<!--
* {
 margin:0;
 padding:0;
}
body {
 font: normal 12px Arial, Helvetica, Sans-Serif, "宋体";
 line-height: 160%;
 text-align:left;
 color: #3a3a3a;
 margin:0;
 padding:0;
}
img {
 border:0;
}
ul, li {
 padding:0;
 margin:0;
 list-style:none;
}
a {
 text-decoration: none;
 color:#3a3a3a;
}
a:hover {
 color: #C00;
}
.banner {
 margin-bottom:1px;
 height:59px;
}
.denglu {
 height:31px;
 border-bottom:1px solid #FFF;
 background:#e7e3e4;
 color:#7b797a;
}
.denglu a {
 color:#7b797a;
 text-decoration:none;
}
.denglu a:hover {
 color:#C00;
 text-decoration:underline;
}
.denglu .box01 {
 margin-left:30px;
 float:left;
 width:224px;
 line-height:30px;
 height:31px;
}
.denglu .box02 {
 width:433px;
 float:left;
 color:#000;
 text-align:right;
}
.denglu .box02 input {
 border:1px #c5c3c3 solid;
 height:20px;
 width:88px;
 background:#FFF;
 line-height:20px;
 margin-top:5px;
}
.denglu .box02 .button {
 background:url(/static/image/common/img01.gif) no-repeat;
 width:50px;
 height:21px;
 border:0;
 color:#4b4b4b;
 margin:0 5px;
 font-size:12px;
 line-height:20px;
}
.denglu .box03 {
 float:right;
 line-height:30px;
 height:31px;
 margin-right:15px;
}
.denglu .box03 .font1 {
 margin-left:20px;
}
.denglu .box03 .font2 {
 margin-left:10px;
 background:url(/static/image/common/icon03.jpg) left center no-repeat;
 padding-left:8px;
 margin-left:40px;
}
-->
</style>
<script type="text/javascript">
function checkform(){
 if(document.getElementById('username').value==''){
  alert('请输入用户名');
  return false;
 }
 if(document.getElementById('password').value==''){
  alert('请输入密码');
  return false;
 } 
 return true;
}
 
function showDate()
{
var d = new Date(); 
document.write("<div class='date_div'>"+d.getYear()+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日");
switch(d.getDay())
{
 case 0:
  document.write("  星期日");
  break;
 case 1:
  document.write("  星期一");
  break;
 case 2:
  document.write("  星期二");
  break;
 case 3:
  document.write("  星期三");
  break;
 case 4:
  document.write("  星期四");
  break;
 case 5:
  document.write("  星期五");
  break;
 case 6:
  document.write("  星期六");
  break;
}
 document.write("</div>");
}
</script>

</head>
<body>
<div id="header">
  <!--登录-->
  <div class="denglu">
    <div class="box01">
 <script language="JavaScript" type="text/JavaScript">
showDate();
</script>    </div>
         <form method="post" action="/bbs/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes" onsubmit="return checkform();">
     <div class="box02">
     用户名:<input type="text" name="username" id="username" />
         密码:<input type="password" name="password" id="password"  />
             <input type="hidden" name="quickforward" value="yes" />
               <input type="hidden" name="handlekey" value="ls" />
               <input type="hidden" name="iflogin" value="plus.php?mod=iframelogin" />
      <span>
      <input name="input" type="submit"  class="button" value="登录" style="cursor:pointer" />
      </span>
      <span>
      <input name="input" type="button"  class="button" value="注册" style="cursor:pointer" onclick="window.open('/bbs/member.php?mod=register')"/>
      </span>
      </div>
      </form>
   
    <div class="box03">
    <span class="font2"><a onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.111cn.net');" href="javascript:;">设为首页</a></span>
    <span class="font1"><a href="/" target="_parent">中文</a> | <a href="#"  target="_parent">English</a></span>
   
    </div>
 
   
  </div>
</div>
</body>
</html>

方法二,利用php方式调用了

在自定义的PHP页面里加入discuz登陆框。PHP如何调用discuz登陆框。

 代码如下 复制代码
<?php
 error_reporting(0);
 require 'source/class/class_core.php';
 $discuz = & discuz_core::instance();
 $discuz->init();
if (empty($_G['uid'])) {
?>
 
<form target="_blank" action="member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes" method="post" name="form2" onSubmit="return check()">
 <span>用户名:<input name="username" type="text" id="textfield2" size="13" tabindex="1" value="请输入用户名" onFocus="this.value='';" onBlur="if(this.value==''){this.value='请输入用户名';}">
 密码:<input name="password" type="password" id="password" size="12">
 <input type="submit" name="button2" id="button2" value="登录" onClick="setTimeout('window.location.reload()', 2000)">
 <a href="member.php?mod=register" target="_blank">注册</a>
 <a href="member.php?mod=logging&action=login&viewlostpw" target="_blank">找回密码</a>
 <input type="hidden" name="referer" value="/" /></span>
</form>
 
<?php } else { ?>
 
<div>
尊敬的<a href="home.php?mod=space&uid=<?php echo $_G['uid']; ?>&do=profile" target="_blank"><? echo $_G['username']; ?></a>,欢迎您光临!&nbsp&nbsp|&nbsp<a href="home.php?mod=space&do=thread&view=me" target="_blank">我的帖子</a>&nbsp|&nbsp <a href="home.php" target="_blank">个人中心</a>&nbsp|&nbsp <a href="member.php?mod=logging&action=logout&formhash=<? echo FORMHASH;?>" target="_blank" onClick="setTimeout('window.location.reload()', 2000)">退出登陆</a>
</div>
 
<?php }?>


方法三:discuz登陆框是ajax调用的,一开始在firebug下看到了调用了接口:

 代码如下 复制代码
/member.php  ?mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login

 
这返回的是一个xml的内容,其中就一个结点root,里面会根据本地的cookies判断是否登录了论坛,如果没有登陆

里面的内容就是一段form登陆表单。如果登陆了里面就是一段登陆后的信息。然后将ajax请求中的css保存到本

地。能够实现登陆框调用。登陆框中有一个hidden的input name=‘reffer’ 这里面的value值是来路链接.不过要是

论坛程序里的。比如将这个连接换成h/home.php?mod=spacecp&ac=blog这样登陆完后会

自动跳转到发博客的页面。可以实现一键发帖功能。

代码如下:

 代码如下 复制代码

<?php 
$login = file_get_contents("/member.php? 
mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login"); 
require_once('SofeeXmlParser.php');//xml解析类 博客里搜索xml有相关介绍 
$xml = new SofeeXmlParser(); 
$xml->parseString($login); 
$tree = $xml->getTree(); 
$login = str_replace("member.php","h/member.php",$tree["root"]["value"]); 
$login = str_replace("h/./","h/home.php? 
mod=spacecp&ac=blog",$login);//跳转到发帖页面 
$login = preg_replace('/<h3 class="flb">(.*)</h3>/i','',$login); 
var_dump($login); 
exit(); 
$login = iconv('utf-8','gbk',$login); 
   
echo $login; 
?>

在php中要实现跳转有很多方法,最常规的跳转方法就是使用header函数来操作了,当然也可以在php中输入js跳转形式,下面我来给大家介绍一下。

PHP 跳转

 代码如下 复制代码

<?php
header("location: http://www.111cn.net");
?>

header函数使用

PHP页面跳转一、header()函数

header()函数是PHP中进行页面跳转的一种十分简单的方法。header()函数的主要功能是将HTTP协议标头(header)输出到浏览器。
header()函数的定义如下:

void header (string string [,bool replace [,int http_response_code]])可选参数replace指明是替换前一条类似标头还是添加一条相同类型的标头,默认为替换。
第二个可选参数http_response_code强制将HTTP相应代码设为指定值。 header函数中Location类型的标头是一种特殊的header调用,常用来实现页面跳转。注意:1.location和“:”号间不能有空格,否则不会跳转。
2.在用header前不能有任何的输出。
3.header后的PHP代码还会被执行。例如,将浏览器重定向到冠威博客

 代码如下 复制代码

< ?php
//重定向浏览器
header("Location: http://www.111cn.net");
//确保重定向后,后续代码不会被执行
exit;
?>

PHP页面跳转二、Meta标签

Meta标签是HTML中负责提供文档元信息的标签,在PHP程序中使用该标签,也可以实现页面跳转。 若定义http-equiv为refresh,则打开该页面时将根据content规定的值在一定时间内跳转到相应页面。
若设置content=”秒数;url=网址”,则定义了经过多长时间后页面跳转到指定的网址。例如,使用meta标签实现疫苗后页面自动跳转到冠威博客。

 代码如下 复制代码

< meta http-equiv="refresh" content="1;url=http://www.111cn.net">

例如,以下程序meta.php实现在该页面中停留一秒后页面自动跳转到www.111cn.net。

 代码如下 复制代码

<?php
$url = "http://www.111cn.net"; ?>
< html>
< head>
< meta http-equiv="refresh" content="1; url=< ?php echo $url; ?>">
< /head>
< body>
页面只停留一秒……
< /body>
< /html>

PHP页面跳转三、JavaScript(常用、推荐)

例如,此代码可以放在程序中的任何合法位置。

 代码如下 复制代码

<?php
$url = "http://www.111cn.net";
echo "<script language='javascript' type='text/javascript'>";
echo "window.location.href='$url'";
echo "</script>";
?>

附一些js跳转方法

JavaScript 跳转

方法一:

 代码如下 复制代码
<script language="javascript">
window.location= "http://www.111cn.net";
</script>

方法二:

 代码如下 复制代码

<script language="javascript">
document.location = "http://www.111cn.net";
</script>

ASP 跳转

 代码如下 复制代码

<%
response.redirect "http://www.111cn.net"
%>

[!--infotagslink--]

相关文章

  • 怎么查询自己的联通手机号码是否已经实名认证(实名制)?

    怎么查询自己的联通手机号码是否已经实名认证?现在手机一批一批的开始实名制了,自己的手机号买的时候没有实名认证,怎么才能知道自己的手机是否被知名认证了呢?认证以后就不能充话费打电话了,下面我们们一起来看看两种查看方法...2016-07-04
  • 微信小程序开发之获取用户手机号码(php接口解密)

    这篇文章主要介绍了微信小程序开发之获取用户手机号码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-05-18
  • javascript 手机号码正则表达式验证函数 <font color=red>原创</font>

    随着手机号码段的不断增加,以前网上的手机号码验证函数都不能那么完美的支持了,这里脚本之家编辑特为大家准备的一个简单的正则与手机验证的函数分析。...2021-05-07
  • PHP批量生成图片缩略图(1/5)

    这款批量生成缩略图代码可以生成指定大小的小图哦,并且支持文件批量上传。 这款教程会用到php文件 view.php config.php funs.php index.php 功能: -------...2016-11-25
  • 浅谈C#手机号换成111XXXX1111 这种显示的解决思路

    下面小编就为大家带来一篇浅谈C#手机号换成111XXXX1111 这种显示的解决思路。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • .net生成缩略图及水印图片时出现GDI+中发生一般性错误解决方法

    这篇文章主要介绍了.net生成缩略图及水印图片时出现GDI+中发生一般性错误解决方法 ,需要的朋友可以参考下...2021-09-22
  • PHP实例:EmailAddress生成图片程序

    把下面的文件保存为index.php <? /* MailX Managment System 0.8 Beta */ header("Content-type:image/png"); $mailaddress=$_GET['mailname']; $mailaddres...2016-11-25
  • php中固定电话号码和手机号码正则表达式验证

    现在我们来总结一下关于php中固定电话号码和手机号码正则表达式验证,本实现可以验证目前所有中国座机与移动电话号码,有需要的朋友可参考一下。 086-区号-号码-分...2016-11-25
  • PHP手机号码归属地查询代码(API接口/mysql)

    文章来介绍一下关于手机号码归属地实现方法,我们可以利用api接口与mysql+php来实例有需要的同学看看。 首先我们介绍使用自己的数据库查询多个手机号码,那还是建...2016-11-25
  • js手机号批量滚动抽奖实现代码

    这篇文章主要为大家详细介绍了js手机号批量滚动抽奖实现代码,s适用于年会等活动,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2017-01-16
  • php生成图片文字混合图片的例子

    生成图片文字混合图片通常用于验证码了,下面来看一个关于php生成图片文字混合图片的例子,希望对大家会有所帮助. 例子一 图片合成文字 <?php $im = imagecreatet...2016-11-25
  • 最新手机号码、电话号码正则表达式

    相信大家对正则表达式一定都有所了解和研究,这篇文章主要为大家分享了最新验证手机号码和电话号码的正则表达式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-05-07
  • js验证电话号码手机号码的正则表达式

    本篇文章主要是对js验证电话号码手机号码的正则表达式进行了介绍。需要的朋友可以过来参考下,希望对大家有所帮助...2020-06-25
  • phpStudy2013中php无法生成图片解决办法

    在php中生成图片是需要用到一个GD库的,默认情况下phpStudy都是打开了,但到了phpStudy2013之后GD库就像php默认安装一个不再开启这个功能了,要用户需配置一下。 phpSt...2016-11-25
  • php中手机号码正则表达式代码

    我们的手机号现在分类中国移动与中国联通了,下面我来给大家先分析他们的特性,然后进行有效的编码。 手机(中国移动手机号码): 代码如下 复制代码 ...2016-11-25
  • 手机号码归属地查询代码

    本款手机号码归属地查询代码是一款php开源手机归属查询系统,本系统不依靠mysql之类的大型数据库,而是依靠文本,因为,一般一个手机号码,在查询系统中起决定作用的就是前7位...2016-11-25
  • php中网址、email、手机号码正则表达代码

    本文章来详细的介绍一在我们php开发中常用的几种正则表达式,如有网址、email、手机号码正则表达代码 1. 判断Email: 域名由各国文字的特定字符集、英文字母、数字...2016-11-25
  • android手机开发之获取客户端手机号码程序

    本文章分享一篇关于android手机开发之获取客户端手机号码程序有需要了朋友可以看看。 代码如下 复制代码 /创建电话管理 Telep...2016-09-20
  • php 验证手机号码

    本文章收藏了三款php 验证手机号码程序,这全部都是利用正则表达式来验证用户输入的手机号码是不是正确的,如果是不ok通过,否提供用户输入合法的移动手机号码。 //php...2016-11-25
  • php 生成图片缩略图-大图生成小图片

    /* 函数:生成缩略图 MakeBuild("images/a.jpg","news/b.jpg","100"); 参数: echo $BuildFile; 原图 带路径 echo $newFile; 生成的缩略图...2016-11-25