所以,我的公式是重定向到错误的网站!
看看我的例子:
ATM我有网址: http://localhost/myworkspace/mywebsite/index.php
它托管在localhost-xampp服务器上。它的主页是: http://localhost/xampp/
好的...现在我尝试了几件事情进入文件,其中脚本正在使用公式的数据:
<form action="index.php">
- &GT;我正被重定向到Xampp主页
<form action="index.php?mod=home">
- &GT;我正被重定向到Xampp主页
<form action="myworkspace/mywebsite/index.php">
- &GT;我正在重定向“http://localhost/myworkspace/mywebsite/myworkspace/mywebsite/index.php”
(箭头表示点击“发送”时会发生什么)
为什么会这样?如示例所示,浏览器不会移动到myworkspace / mywebsite-folders之外。但是,它仍然会加载index.php,它位于localhost / xampp(它的localhost / index.php)中。如果你看到我网站的原始链接,那么“myworkspace / mywebsite”中实际上有一个index.php文件。
以下是我的一些代码:
addguestbook.php,它包含在index.php中(见下文)
<?php
//******************************************************//
//********************Database stuff********************//
//******************************************************//
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="mywebsite"; // Database name
//********************Tables***************************//
$tbl_name="guestbook"; // Guestbook
echo $hostname.$path.$get;
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$comment = $_POST['comment'];
$datetime = date("l, jS M Y, g:i a"); //date time
// Connect to server and select database.
mysql_connect($host, $username, $password)or die("cannot connect server: ".mysql_error());
mysql_select_db($db_name)or die("cannot select DB: ".mysql_error());
$sql="INSERT INTO ".$tbl_name."(id, name, email, website, comment, datetime)VALUES('".$post_id."', '".$name."', '".$email."', '".$website."', '".$comment."', '".$datetime."')";
$result=mysql_query($sql);
mysql_close();
} else
?>
<form method="post" action="myworkspace/mywebsite/index.php">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="guestbookFormCell" colspan='2'><input
class="guestbookInputFieldText" name="name" type="text"
value="Name *" size="40" maxlength="30" /></td>
</tr>
<tr>
<td class="guestbookFormCell" colspan='2'><input
class="guestbookInputFieldText" name="email" type="text"
value="E-Mail (won't become displayed)" size="40" maxlength="40" />
</td>
</tr>
<tr>
<td class="guestbookFormCell" colspan='2'><input
class="guestbookInputFieldText" name="website" type="text"
value="Website" size="40" maxlength="50" /></td>
</tr>
<tr>
<td class="guestbookFormCell" colspan='2'><textarea
class="guestbookInputFieldText" name="comment" cols="37" rows="5">Comment *</textarea>
</td>
</tr>
<!--
<tr>
<td>CAPTCHA</td>
</tr>
-->
<tr>
<td><button class="guestbookFormCell guestbookButton" type="submit"
name="submit">
<span class='guestbookButtonText'>Send</span>
</button></td>
<td><button class="guestbookFormCell guestbookButton" style="float:right;"type="reset"
name="reset">
<span class='guestbookButtonText'>Reset</span>
</button></td>
</tr>
</table>
</form>
和index.php(它非常大。大多数只是一个设计结构,所以忽略了html的东西。它只是div和table。
<html>
<head>
<title>JustBasti's website</title>
<script type="text/javascript" src="lightbox/js/prototype.js"></script>
<script type="text/javascript"
src="lightbox/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="lightbox/js/lightbox.js"></script>
<link rel="stylesheet" href="lightbox/css/lightbox.css" type="text/css"
media="screen" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
session_start();
// Path-parameters for link-building
$hostname = $_SERVER['HTTP_HOST'];
$path = $_SERVER['PHP_SELF'];
$_SESSION['basepath'] = dirname($_SERVER['PHP_SELF']);
?>
<div id='top'>
<div id='header'>
<div id='headerText' class='lightText text bigText'>
<div>
Hello, My name is <font class='blueText'>Sebastian Fast</font>
</div>
<div>
I just finished my <font class='blueText'>education in IT</font>
</div>
<div>
and am now <font class='blueText'>aiming to</font>
</div>
<div>
experience the <font class='blueText'>most wonderful places</font>
</div>
<div>
around <font class='blueText'>the world</font>
</div>
<div>
Read more about myself <font class='blueText'>here</font>
</div>
</div>
<div id='headerLineBox'>
<div class='lineTopDiv'>
<div id='headerTopLine' class='lineTopEnd'></div>
</div>
<div class='verticalLine'>
<div id='headerLine' class='line'></div>
</div>
<div class='lineBottomDiv'>
<div class='lineBottomEnd'></div>
</div>
</div>
<div id='headerNavigation' class='lightText text bigText'>
<div>
<a href='index.php?mod=home' class='lightLink'>Home</a>
</div>
<div>
<a href='index.php?mod=news' class='lightLink'>News</a>
</div>
<div>
<a href='index.php?mod=countries' class='lightLink'>Countries</a>
</div>
<div>
<a href='index.php?mod=gallery' class='lightLink'>Gallery</a>
</div>
</div>
</div>
</div>
<div id='middle'>
<div id='content'>
<table>
<!-- CONTENT -->
<?
// Paths
echo " <a href='index.php?mod=home'>Home</a>
<a href='index.php?mod=news'>News</a>
<a href='index.php?mod=allnews'>All News</a>
<a href='index.php?mod=countries'>Countries</a>
<a href='index.php?mod=gallery'>Gallery</a>
<a href='index.php?mod=guestbook'>Guestbook</a>
<a href='index.php?mod=admin'>Administrator</a>";
if (!isset($_SESSION['angemeldet']) || !$_SESSION['angemeldet']) {
include('login/login.php');
}
// Check which link got clicked & import data
if (!$_GET){
include('data/home.php');
} elseif (isset($_GET['mod']) && !isset($_GET['post']) && !isset($_GET['album']) && !isset($_GET['country'])){
Switch($_GET['mod']){
case 'home':
include('data/home.php');
exit;
case 'news':
include('data/latestPosts.php');
exit;
case 'allnews':
include('data/allPosts.php');
exit;
case 'countries':
include('data/viewCountries.php');
exit;
case 'gallery':
include('data/gallery.php');
exit;
case 'admin':
include('admin/admin.php');
exit;
}
} elseif (isset($_GET['mod']) && isset($_GET['post'])){
$get = "?mod=".$_GET['mod']."&post=".$_GET['post'];
$post_id = $_GET['post'];
include('data/viewPost.php');
include('data/guestbook.php');
} elseif (isset($_GET['mod']) && isset($_GET['album'])){
$get = "?mod=".$_GET['mod']."&album=".$_GET['album'];
$post_id = $_GET['album'];
include('data/viewAlbum.php');
include('data/guestbook.php');
} elseif (isset($_GET['mod']) && isset($_GET['country'])){
$country = $_GET['country'];
include('data/viewCountry.php');
}
?>
</table>
</div>
</div>
<div id='graphicDIV'>
<div id='graphic'></div>
</div>
<div id='bottom'>
<div id='guestbook'>
<table border='0' cellspacing='0' cellpadding='0'>
<tr>
<td id='guestbookHeadline1'><font class='lightText bigText text'>Allgemeines Gästebuch</font>
</td>
<td id='guestbookTopLine' class='lineTopEnd'></td>
<td id='guestbookHeadline2'><font class='lightText bigText text'>Schreibe selbst</font>
</td>
</tr>
<tr id='guestbook2'>
<?
$post_id = 000000000000;
$get = "?mod=home";
?>
<td id='guestbookComment'>
<? include('data/viewguestbook.php'); ?>
</td>
<td id='guestbookLine'></td>
<td id='guestbookFormular'>
<? include('data/addguestbook.php'); ?>
</td>
</tr>
</table>
</div>
<div id='footerLeftLine' class='lineLeftEnd'>
<!-- LineLeftEnd -->
</div>
<div id='footerLine' class='horizontalLine'>
<!-- Line -->
</div>
<div id='footerRightLine' class='lineRightEnd'>
<!-- LineRightEnd -->
</div>
<div id='footer'>
<div class='footerLink'>
<!-- AdministratorLink -->
</div>
<div class='footerLink'>
<!-- ImpressumLink -->
</div>
<div class='footerLink'>
<!-- NewsArchiveLink -->
</div>
</div>
</div>
</body>
</head>
</html>
感谢您的帮助!
答案 0 :(得分:1)
<form action="myworkspace/mywebsite/index.php">
应该是
<form action="/myworkspace/mywebsite/index.php">
您目前拥有的是相对于当前页面的路径。我给出的路径是相对于您的文档根目录,即http://localhost
。
另见: