php main (),main.php

/**

* Site Main Page

*

* @author   Avenger 

* @version  $Id 2003-04-11 18:06:20 $

*/  require_once "header.inc.php";

tpl_load("index.html","","keep");  // Get u language

$G_lang = explode(",",$_SERVER["HTTP_ACCEPT_LANGUAGE"]);

switch ($G_lang[0]) {

case "zh-hk":

case "zh-tw":

case "zh-mo":

case "zh-cn":

include("lang.zh.inc.php");

$indexfile = "main_zh.htm";

break;

default:

include("lang.en.inc.php");

$indexfile = "main_en.htm";

}  $filedate = (int)date(time()-@filemtime($indexfile));  // If lastupdate less than five hours then update

if ($filedate<18000 && filesize($indexfile)<>0 && empty($_GET["update"])) {

require($indexfile);

exit();  } else {      // Rand title

require_once "titles.inc.php";      $currdate = date("md");      if ($title_h[$currdate]) {

$title_more = $title_h[$currdate];

} else {

$title_more = $title_o[array_rand($title_o)];

}      // Import template

$tpl->setVar("FILEHEAD",file_head());      /*

$tpl->setVar("FILEPIC",file_pic("phptshirt.gif","国内首款 PHP T-shirt 火热预定中……","http://www.phpe.net/t-shirt"));

$tpl->setVar("FILEPIC",file_pic("phpandmore.gif","《PHP&More》创刊号发布","http://www.phpe.net/news/34.shtml"));

$tpl->setVar("FILEPIC",file_pic("3.jpg","超越PHP欢迎您",""));

$tpl->setVar("FILEPIC",file_pic("show.gif","Show出你的热情活动 -- 点击查看详情","http://www.phpe.net/club/index.php?act=ST&f=2&t=1416"));

$tpl->setVar("FILEPIC",file_pic("1year.gif","超越PHP一岁了","http://www.phpe.net/club/index.php?s=&act=ST&f=7&t=2419"));

*/      $tpl->setVar("CREATE",date("Y-m-d H:i:s"));

$tpl->setVar("DESC",$lang["sitedesc"]);

$tpl->setVar("KEYWORDS",$lang["sitekeywork"]);

$tpl->setVar("TITLE",$lang["sitetitle"].$title_more);      /*

DBInit();

extract($dbinfo,EXTR_OVERWRITE);

$rs = $dbconn->Execute("SHOW TABLES");

while ($result = $rs->FetchRow()) $tables .= $result["Tables_in_$dbname"].",";

$SQL = "OPTIMIZE TABLE ".substr($tables,0,-1);

$dbconn->Execute($SQL);

*/      $indexlogin = "";

    $tpl->setVar("INDEXLOGIN",$indexlogin);      $space = "

";      ob_start(); 

//echo item_title($lang["stat"],"98%");

include("index_stat.inc.php");

$tpl->setVar("INDEXCOUNT",ob_get_contents());

ob_end_clean();      ob_start();

//echo item_title($lang["vote"],"98%");

include("index_vote.inc.php");

$tpl->setVar("INDEXVOTE",ob_get_contents());

ob_end_clean();      ob_start();

//echo item_title($lang["links"],"98%");

include("index_links.inc.php");

$tpl->setVar("INDEXLINK",ob_get_contents());

ob_end_clean();      ob_start();

//echo item_title($lang["intro"],"98%");

include("index_intro.inc.php");

$tpl->setVar("INDEXINTRO",ob_get_contents());

ob_end_clean();      ob_start();

//echo item_title($lang["news"]." ".make_link("/?n=RSS&t=news", "(rss)", "_blank", "class="en2""),"98%");

include("index_news.inc.php");

$tpl->setVar("INDEXNEW",ob_get_contents());

ob_end_clean();      ob_start();

//echo item_title($lang["articles"]." ".make_link("/?n=RSS&t=articles", "(rss)", "_blank", "class="en2""),"98%");

include("index_article.inc.php");

$tpl->setVar("INDEXARTICLE",ob_get_contents());

ob_end_clean();      ob_start();

//echo item_title($lang["recommendtopic"],"98%");

echo "

更多推荐话题 ...  

";

$tpl->setVar("RECOMMENDTOPIC", ob_get_contents());

ob_end_clean();      ob_start();

echo "

更多招聘信息 ...  

";

$tpl->setVar("HRTOPIC", ob_get_contents());

ob_end_clean();      ob_start();

//echo item_title($lang["faqs"]." ".make_link("/?n=RSS&t=faqs", "(rss)", "_blank", "class="en2""),"98%");

include("index_faq.inc.php");

$tpl->setVar("INDEXFAQ",ob_get_contents());

ob_end_clean();      ob_start();

//echo item_title($lang["nav"],"98%");

include("index_sitenav.inc.php");

$tpl->setVar("INDEXNAV",ob_get_contents());

ob_end_clean();      ob_start();

//echo item_title($lang["tips"],"98%");

include("index_tips.inc.php");

$tpl->setVar("INDEXTIPS",ob_get_contents());

ob_end_clean();      /*

ob_start();

echo item_title($lang["events"],"98%");

$tpl->setVar("INDEXEVENTS",ob_get_contents());

ob_end_clean();

*/      ob_start();

//echo item_title($lang["resouce"],"98%");

include("index_resource.inc.php");

$tpl->setVar("INDEXRESOURCE",ob_get_contents());

ob_end_clean();      ob_start();

//echo item_title($lang["souwang"],"98%");

echo "

互联网上的 php 资源

";

$tpl->setVar("INDEXSOUWANG",ob_get_contents());

ob_end_clean();      //$tpl->setVar("INDEXPARTNERS",item_title($lang["partners"],"98%"));      ob_start();

//echo item_title($lang["calendar"],"98%");

include_once "calendar.inc.php";

$c = new Calendar;

echo $c->getCurrentmonthView();

$tpl->setVar("INDEXCALENDAR",ob_get_contents());

ob_end_clean();      ob_start();

//echo item_title($lang["newtopic"],"98%");

echo "

";

$tpl->setVar("INDEXFORUM", ob_get_contents());

ob_end_clean();      ob_start();

//echo item_title($lang["maillist"],"98%");

echo "

Join the mail list:

";

$tpl->setVar("INDEXMAIL",ob_get_contents());

ob_end_clean();      // My name :)

$s_name="index.php";      $tpl->setVar("SPACE",$space);

$tpl->setVar("FILEFOOT",file_foot());      $tpl->parse("output","main");

$output = $tpl->get("output");      // Rwrite to file

wfile($indexfile,$output);

require($indexfile);

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我会解答这个问题。首先,你需要在数据库中创建一个用户表,包括用户名和密码,例如: ```SQL CREATE TABLE users ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, username VARCHAR(30) NOT NULL, password VARCHAR(30) NOT NULL ) ``` 然后,你需要创建一个验证码生成器 `image.php`,该脚本将生成一个随机的验证码,并将其呈现为图像。可以使用 PHP 的 GD 库来创建图像。以下是一个简单的 `image.php` 的示例代码: ```PHP <?php session_start(); $length = 4; $width = 100; $height = 30; $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $code = ''; for ($i = 0; $i < $length; $i++) { $code .= $characters[mt_rand(0, strlen($characters) - 1)]; } $_SESSION['captcha'] = $code; $image = imagecreatetruecolor($width, $height); $background_color = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $background_color); $text_color = imagecolorallocate($image, 0, 0, 0); imagettftext($image, 18, 0, 10, 25, $text_color, 'arial.ttf', $code); header('Content-type: image/png'); imagepng($image); imagedestroy($image); ?> ``` 接下来,你需要创建一个登录页面 `login.php`,该页面将显示一个表单,允许用户输入用户名、密码和验证码。你可以在登录页面中使用表单来收集用户输入,然后使用 PHP 脚本验证用户凭据。以下是一个简单的 `login.php` 示例代码: ```PHP <?php session_start(); if (isset($_POST['submit'])) { $username = $_POST['username']; $password = $_POST['password']; $captcha = $_POST['captcha']; if (strtolower($captcha) != strtolower($_SESSION['captcha'])) { echo "<script>alert('验证码输入错误');</script>"; } else { $conn = mysqli_connect('localhost', 'username', 'password', 'database'); $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'"; $result = mysqli_query($conn, $query); if (mysqli_num_rows($result) == 1) { echo "<script>alert('欢迎" . $username . "用户登录');</script>"; header('Location: main.php'); } else { echo "<script>alert('登录失败');</script>"; } mysqli_close($conn); } } ?> <!DOCTYPE html> <html> <head> <title>Login</title> </head> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label>Username:</label> <input type="text" name="username" required><br><br> <label>Password:</label> <input type="password" name="password" required><br><br> <label>Verification Code:</label> <input type="text" name="captcha" required> <img src="image.php" alt="Verification Code"><br><br> <input type="submit" name="submit" value="Login"> <input type="reset" value="Reset"> </form> </body> </html> ``` 在上述代码中,如果用户提交表单,则 PHP 脚本将从表单中获取用户名、密码和验证码。如果验证码输入不正确,则显示一个警告框。否则,它将连接到数据库并执行查询以验证用户名和密码。如果用户名和密码正确,则显示一个欢迎框,并将用户重定向到 `main.php` 页面。如果用户名或密码不正确,则显示一个错误框。 希望这个示例代码可以帮助你实现你的需求!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值