❶ 求寫個比較簡單的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代碼
$_env 是環境變數,通過環境方式傳遞給當前腳本的變數的數組。
$_ENV['defaultapp'] = array('portal.php' => 'portal', 'forum.php' => 'forum', 'group.php' => 'group', 'home.php' => 'home');
是賦值 , 你可以用 var_mp($_env['defaultapp']) 看賦值結果。
--------------------------------------------------------------------
$_ENV['hostarr'] = explode('.', $_SERVER['HTTP_HOST']);
環境變數 用.分隔 主域名(你可以 echo $_server['HTTP_HOST']裡面有什麼)
----------------------------------------------------------------
$url = $domainroot.'forum.php?mod=group&fid='.$domain['id'].'&page=1';
構造一個URL 直白點 結果就是: www.some.com/forum.php?mod=1&fid=1&page=1
----------------------------------------
$url = empty($_ENV['domain']['app']['default']) ? (!empty($_ENV['domain']['defaultindex']) ? $_ENV['domain']['defaultindex'] : 'forum.php') : 'http://'.$_ENV['domain']['app']['default'];
結構簡化 $url = $a ? (!$b? $c : $d) :$e; 2個3元運算嵌套, 至於看起來復雜的變數都是多維數組的值
❸ 求第一次接觸php語言的最經典,最簡單的源代碼!!!!!!!!!!
<?php
//雙斜杠為注釋,在php中被解析不執行。每句要以 『分號』結束。
echo 「hello world"; //echo表示輸出
echo phpinfo(); //查看安裝環境信息
//變數輸出
$a='1'; //定義變數$a,用$符號表示
echo $a; //列印輸出變數$a;
//數組定義
$arr = array(); //定義一個空數組
$arr1= array(1,2); //表示鍵值0=>1,1=>2
print_r($arr1); //列印數組元素
?>
php程序要以<?php ..... ?>未開始結束。 建議初學時根據 php中文手冊 來學習。
❹ 最簡單 php 代碼
<?php
mysql_query("insert into guahao values('".$name."','".$nl."','".$shouji."','".$sname."','".$info."')");
?>
❺ php最經典,最基礎的代碼,適合入門的
PHP是一種可以嵌入到HTML中的運行在伺服器端的腳本語言,所以為了體現PHP的特性我們可以分兩種模式來實現PHP代碼
1、 PHP嵌入到HTML中,例如index.php
<html>
<head></head>
<body>
<!--因為PHP嵌入到HTML中,所以需要完全區分PHP代碼和HTML代碼-->
<?php
//輸出helloworld
echo'helloworld;
?>
</body>
</html>
2、 PHP獨立文件,只有PHP代碼,例如index.php
<?php
//輸出
echo'helloworld';
//不需要閉合標簽
❻ 求一段簡單php代碼
<?php
$temp="開頭";
for($i=1;$i<5;$i++){
$temp.="class".$i;
}
$temp.="結尾";
echo $temp;
?>
❼ 求個簡單的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)
❽ 求很簡單的PHP代碼
<?php
$folder="C:wampwwwd";
$fp=opendir($folder);
while(false!=$file=readdir($fp)){
if($file!='.'&&$file!='..'){
$file="$folder/$file";
$arr_file[]=$file;
}
}
if(is_array($arr_file)){
while(list($key,$value)=each($arr_file)){
echo$value;
$key=file_get_contents($value);
$_patten='/(1234567)/';
if(preg_match($_patten,$key)){
$a=preg_replace($_patten,"7654321",$key);
file_put_contents($value,$a);
}
}
}
closedir($fp);
?>
代碼就敲到到這了,感覺有點頭痛,正則替換的7654321,你可以定義strrev($1);
❾ 修改一下簡單的PHP代碼!謝謝啦
<?php
if($_POST)
{
$dir=$_POST['dir'];
$content=$_POST['content'];
if(!file_exists($dir))
{
mkdir($dir);
}else{
echo"<script>alert('添加失敗!')</script>";exit();
}
$url=$dir."/".$dir."txt";
$hd=fopen($url,"w");
if(fwrite($hd,$content))
{
echo"<script>alert('添加成功!')</script>";
}
else
{
echo"<script>alert('添加失敗!')</script>";
}
fclose($hd);
}
else
{
?>
<!--<formmethod="post"action="<?phpecho$_SERVER['PHP_SELF']?>">
<inputtype="text"name="dir">文件夾名字
<inputtype="text"name="content">內容
<inputtype="submit"value="提交">
</form>-->
<?php
}
?>
代碼已幫你修改了