I am using XAMPP in Windows 10 to create a PHP site.
I created a "test" folder directly under the "htdocs" folder, and I created "firstPage.php" and "secondPage.php" in it.
I am currently running it with XAMPP in the local environment, but I wanted to upload it to the server someday (please leave the security story behind), so I tried to specify the path to which I was linked as the absolute path.
However, although firstPage was displayed correctly, it cannot be moved to secondPage using the absolute path.
You can move by using the relative path.
The source code for firstPage is as follows:
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
</head>
<body>
// This can't be moved.
<?phpecho'<a href='.__DIR__.'/secondPage.php>secondPage</a>br/>'?>
// This can be moved.
<?phpecho'<a href=secondPage.php>secondPage</a><br/>'?>
</body>
</html>
When you view the source in your browser, the link is
<a href=C:\xampp\htdocs\test/secondPage.php>secondPage</a>br/>
<a href=secondPage.php>secondPage</a><br/>
It says , but I honestly don't know how this difference affects me.
I don't think Apache is working well...
Additional information
Both links are equally blue on the browser, but if you use __DIR__, you can click on them and they are unresponsive.
<?phpecho'<a href='.__DIR__.'/secondPage.php>secondPage</a><br/>'?>
There was no change in ./secondPage.php 」 in to .\secondPage.php 」.
Also, include and require_once can be loaded using _DIR__.
For now, it seems to be a problem with links.
Relative and absolute paths are used to describe the path of a file, but you should be aware of the difference between local environment and Internet address (=URL) starting with http
or https
.
__DIR__
is just a variable that represents the path in the local environment, so if you want to specify an absolute path as an Internet address through Apache, try $_SERVER['SERVER_NAME']
.
<a href="<?phpecho'http://'.$_SERVER {"SERVER_NAME"}.'/secondPage.php';?>">secondPage<a>
If you are testing locally and the hostname is "localhost", then $_SERVER{"SERVER_NAME"}
should also contain that hostname.
Note:
PHP:$_SERVER-Manual
PHP ($_SERVER) Server Variable List and Example
PHP is not aware of Apache's Document Root.The __DIR__ is not a directory represented by Apache's Document Root path, but a directory represented by an absolute path represented by the root directory of your computer.
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
911 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.