从HTML中划分PHP代码的方式。我在加载css文件时遇到了问题。 所以我有php文件index.php,css文件 - main.css和html文件front.html和log_in.html
<?php
// Get email address
require_once 'config.php';
// Ensures no one loads page and does simple spam check
if(isset($_POST['name']) && empty($_POST['spam-check'])) {
// Declare our $errors variable we will be using later to store any errors
$error = '';
// Setup our basic variables
$input_name = strip_tags($_POST['name']);
$input_email = strip_tags($_POST['email']);
$input_subject = strip_tags($_POST['subject']);
$feedback = array(1 => "Volvo", 2 => "Saab", 3 => "Mercedes", 4 => "Audio");
$feedback = $feedback[(int) $_POST['feedback']];
$input_message = strip_tags($_POST['message']);
// We'll check and see if any of the required fields are empty
if(strlen($input_name) < 2) $error['name'] = 'Please enter your name.';
if(strlen($input_message) < 5) $error['message'] = 'Please leave a message.';
// Make sure the email is valid
if(!filter_var($input_email, FILTER_VALIDATE_EMAIL) ) $error['email'] = 'Please enter a valid email address.';
// Set a subject & check if custom subject exist
$subject = "Message from $input_name";
if($input_subject ) $subject .= ": $input_subject";
$message = "$input_message\n";
$message .= "\n---\nThis email was sent by contact form.";
$feedback = "$feedback";
// Now check to see if there are any errors
if(!$error) {
// No errors, send mail using conditional to ensure it was sent
if(mail($your_email_address, $subject, $message, "From: $input_email")) {
echo '<p class="success">Your email has been sent!</p>';
} else {
echo '<p class="error">There was a problem sending your email!</p>';
}
} else {
// Errors were found, output all errors to the user
$response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
$response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
$response .= (isset($error['message'])) ? $error['message'] . "<br /> \n" : null;
echo "<p class='warning'>$response</p>";
}
} else {
die('Direct access to this page is not allowed.');
}
这里我尝试将登录容器放在front.html页面中。我最好这样做,创建另一个类似的页面。
如果我去目录localhost / my-site /(如果我理解正确,它会自动接受index.php或index.html) 它完美地向我展示了这个网站。一切正常。 但是一旦我得到localhost / my-site / index.php就会得到一个带有空css文件的页面(参见附图)。 所以问题是:它为什么会发生?它与localhost / my-site /和localhost / my-site / index.php的地址不一样吗?
答案 0 :(得分:1)
如果输入localhost / site-final / index.php(没有/结尾)会发生什么?我认为当你有index.php /时,它会尝试加载localhost / site-final / index.php / css / main.css。您可以使用css文件的绝对路径(http://localhost/site-final/css/main.css)。