常用php代碼
⑴ 求一個php跳轉代碼很簡單
這里提供了一個簡單的PHP代碼示例,用於隨機跳轉到預設的網站。具體代碼如下:
$JumpURL = array("www..com", "www.google.com", "www.qq.com"); 這行代碼定義了一個數組,包含三個跳轉目標網站的URL。
$randNum = rand(0, 2); 這行代碼生成一個0到2之間的隨機數,用於選擇數組中的一個元素。
header("Location: http://$JumpURL[$randNum] "); 最後這行代碼執行跳轉,根據生成的隨機數選擇數組中的一個URL,並進行跳轉。
這個簡單的PHP代碼能夠實現隨機跳轉到預設的網站,我自己嘗試了一下,確實可以正常工作,每次運行都會隨機打開一個網站。
需要注意的是,在使用這個代碼時,確保目標URL是正確的,並且伺服器允許執行HTTP頭部重定向。此外,如果需要跳轉到HTTPS網站,記得將URL中的「http://」改為「https://」。當然,這個代碼也可以根據需要調整目標網站的數量和內容。
簡單來說,這段代碼通過生成隨機數來選擇數組中的一個URL,然後通過HTTP頭部重定向實現跳轉。這種方式可以應用於各種場景,例如廣告推廣、網站測試等。
如果你希望實現更復雜的功能,比如根據用戶偏好選擇跳轉目標,可以考慮在此基礎上進行擴展。
總之,這是一個非常實用且簡單的PHP跳轉代碼示例,希望能夠對你有所幫助。
⑵ 求寫個比較簡單的php登陸頁面代碼
主頁面:index.php <form name="form1" action="login.php" method="post" onsubmit="return check()"><!--這里注意onclick的用法-->
賬號:<input name="adminAccount" type="text" />
密碼:<input type="password" name="adminPass" />
輸入驗證碼:<input type="text" name="validate" />
< br />
<input type="submit" value="登陸" /><input type="reset" value="重置">
</form>判斷頁面:login.php<?php
//再連庫判斷賬號密碼
require_once("../inc/dbconfig.php");
$adminAccount=$_POST['adminAccount'];
$adminPass=md5($_POST['adminPass']);
$sql="select * from admin where adminAccount='$adminAccount' and adminPass='$adminPass'";
$result=mysql_query($sql) or die($sql);
$rows=mysql_num_rows($result);
if($rows==0){
?>
<script language="javascript">
alert("管理員賬號密碼錯誤!");
window.location="index.php";
</script>
<?
exit();
}
//將管理員賬號賦值給session
$_SESSION['adminAccount']=$adminAccount;
?>
<script language="javascript">
window.location="command.php";
</script>配置文件自己來就行了!
⑶ 求個簡單的php代碼
_tags($string, $replace_with_space = true)
{
if ($replace_with_space) {
return preg_replace('!<[^>]*?>!', ' ', $string);
} else {
return strip_tags($string);
}
}
截取字元函數(匹配各種編碼)
function truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false){
if ($length == 0)
return '';
if (is_callable('mb_strlen')) {
if (mb_detect_encoding($string, 'UTF-8, ISO-8859-1') === 'UTF-8') {
// $string has utf-8 encoding
if (mb_strlen($string) > $length) {
$length -= min($length, mb_strlen($etc));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($string, 0, $length + 1));
}
if (!$middle) {
return mb_substr($string, 0, $length) . $etc;
} else {
return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, - $length / 2);
}
} else {
return $string;
}
}
}
// $string has no utf-8 encoding
if (strlen($string) > $length) {
$length -= min($length, strlen($etc));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1));
}
if (!$middle) {
return substr($string, 0, $length) . $etc;
} else {
return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
}
} else {
return $string;
}
}
綜合就是
$arc=strip_tags($arc);
$arc=truncate($arc,200)