使用PHP创建企业网站的示例
在创建企业网站时,PHP是一种流行的服务器端脚本语言,它能够嵌入到HTML代码中,并且可以与数据库进行交互,这使得它成为开发动态网站的理想选择,下面是一个简化的PHP企业网站的示例,包括一些基本功能模块:首页、关于我们、服务、联系我们和管理员登录。
(图片来源网络,侵删)
目录结构
/var/www/html/mycompany |-index.php |-about.php |-services.php |-contact.php |-admin |-login.php |-dashboard.php |-includes |-header.php |-footer.php |-styles |-style.css
1. 首页 (index.php)
<?php include 'includes/header.php'; ?> <body> <div class="container"> <h1>Welcome to My Company</h1> <p>We provide the best solutions for your business needs.</p> <a href="about.php">About Us</a> | <a href="services.php">Our Services</a> | <a href="contact.php">Contact Us</a> </div> <?php include 'includes/footer.php'; ?> </body> </html>
2. 关于我们 (about.php)
<?php include 'includes/header.php'; ?> <body> <div class="container"> <h1>About Us</h1> <p>My Company is a leading provider of innovative solutions in the industry. We have over 10 years of experience in delivering top-notch services to our clients.</p> <a href="index.php">Home</a> | <a href="services.php">Our Services</a> | <a href="contact.php">Contact Us</a> </div> <?php include 'includes/footer.php'; ?> </body> </html>
3. 服务 (services.php)
<?php include 'includes/header.php'; ?> <body> <div class="container"> <h1>Our Services</h1> <p>We offer a wide range of services including web development, digital marketing, and consultancy. Our team of experts is dedicated to helping you achieve your business goals.</p> <a href="index.php">Home</a> | <a href="about.php">About Us</a> | <a href="contact.php">Contact Us</a> </div> <?php include 'includes/footer.php'; ?> </body> </html>
4. 联系我们 (contact.php)
(图片来源网络,侵删)
<?php include 'includes/header.php'; ?> <body> <div class="container"> <h1>Contact Us</h1> <p>If you have any questions or would like to get in touch with us, please use the contact form below:</p> <form action="sendmail.php" method="post"> <label for="name">Name:</label> <input type="text" id="name" name="name"><br><br> <label for="email">Email:</label> <input type="email" id="email" name="email"><br><br> <label for="message">Message:</label><br> <textarea id="message" name="message"></textarea><br><br> <input type="submit" value="Submit"> </form> <a href="index.php">Home</a> | <a href="about.php">About Us</a> | <a href="services.php">Our Services</a> </div> <?php include 'includes/footer.php'; ?> </body> </html>
5. 管理员登录 (admin/login.php)
<?php session_start(); if ($_SERVER["REQUEST_METHOD"] == "POST") { $username = $_POST['username']; $password = $_POST['password']; // Dummy credentials for demonstration purposes only if ($username == 'admin' && $password == 'password') { $_SESSION['authenticated'] = true; header('Location: dashboard.php'); } else { echo "Invalid credentials"; } } ?> <!DOCTYPE html> <html> <head> <title>Admin Login</title> </head> <body> <div class="container"> <h1>Admin Login</h1> <form action="login.php" method="post"> <label for="username">Username:</label> <input type="text" id="username" name="username"><br><br> <label for="password">Password:</label> <input type="password" id="password" name="password"><br><br> <input type="submit" value="Login"> </form> </div> </body> </html>
6. 管理员仪表盘 (admin/dashboard.php)
<?php session_start(); if (!isset($_SESSION['authenticated']) || $_SESSION['authenticated'] !== true) { header('Location: login.php'); exit; } ?> <!DOCTYPE html> <html> <head> <title>Admin Dashboard</title> </head> <body> <div class="container"> <h1>Admin Dashboard</h1> <p>Welcome to the admin dashboard. From here, you can manage various aspects of the website.</p> <!-Add more functionality here --> <a href="logout.php">Logout</a> </div> </body> </html>
includes/header.php
<!DOCTYPE html> <html> <head> <title>My Company</title> <link rel="stylesheet" type="text/css" href="styles/style.css"> </head> <body> <header> <nav> <ul> <li><a href="index.php">Home</a></li> <li><a href="about.php">About Us</a></li> <li><a href="services.php">Services</a></li> <li><a href="contact.php">Contact Us</a></li> <li><a href="admin/login.php">Admin</a></li> </ul> </nav> </header>
includes/footer.php
<footer> <p>© 2023 My Company. All rights reserved.</p> </footer> </body> </html>
styles/style.css
(图片来源网络,侵删)
body { font-family: Arial, sans-serif; margin: 0; padding: 0; } .container { width: 80%; margin: auto; padding: 20px; } header { background-color: #333; color: white; padding: 10px 0; } header nav ul { list-style-type: none; padding: 0; display: flex; justify-content: center; } header nav ul li { display: inline; margin: 0 10px; } header nav ul li a { color: white; text-decoration: none; } footer { background-color: #333; color: white; text-align: center; padding: 10px 0; position: fixed; bottom: 0; width: 100%; }
这个简单的PHP企业网站示例展示了如何使用PHP和基本的HTML、CSS来构建一个动态网站,你可以根据需要扩展功能,例如添加数据库连接以存储用户信息或产品数据,实现更复杂的业务逻辑等。
以上就是关于“php企业网站例子_PHP”的问题,朋友们可以点击主页了解更多内容,希望可以够帮助大家!
本文来源于互联网,如若侵权,请联系管理员删除,本文链接:https://www.9969.net/77555.html