HTML Relative path not working PHP
I have HTML code that is calling php in IE6, problem is when i use relative path, it just opens php file but when i use absolute path, then php code is executed. Both html, and php are in same directory and apache is running.
Below one is working:
<form action="http://localhost/welcome.php" method="POST">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
</form>
Not working:
<for开发者_Python百科m action="welcome.php" method="POST">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
php code:
<html>
<body>
Welcome <?php echo $_POST["fname"]; ?>!<br />
</body></html>
I expect, in the 2nd case, you're actually running it from a file:/// protocol. This means that it isn't passing through your server at all.
You should never double-click on a file in your explorer, as that will just open it through the filesystem. None of your PHP will work that way.
With the full URL, you're actually making a request to a server. You'll navigate from whatever file/protocol you're at to a named location: http://localhost/welcome.php.
With a relative URL, you're starting from your base directory (file:///c:/xampp/htdocs/), and relatively navigating to welcome.php. This makes your final URL file:///c:/xampp/htdocs/welcome.php. Since the second one is not rendered by a server... you're not going to get anything useful.
Does this mean you shouldn't use relative URLs? No, not at all. This means you should start from your http server. Set a bookmark. : )
Let the file with the form be: C:\xampp\htdocs\form.html
If you're navigating in an explorer, and clicking on the file, than any link within that file will also default to the file protocol, and not http. Meaning, that the browser will go the location and open the file, and parse it itself without the server.
You must navigate to localhost/form.html and than it will work.
精彩评论