So I am making a website on my localhost, the folder name is "veco" therefore my URL link is http://localhost/veco/
Im currently using this code to get the home url "http://localhost/veco/":
<?php
function home_url() {
// output: /myproject/index.php
$currentPath = $_SERVER['PHP_SELF'];
// output: Array ( [dirname] => /myproject [basename] => index.php [extension] => php [filename] => index )
$pathInfo = pathinfo($currentPath);
// output: localhost
$hostName = $_SERVER['HTTP_HOST'];
// output: http://
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https://'?'https://':'http://';
// return: http://localhost/myproject/
return $protocol.$hostName.$pathInfo['dirname']."/";
}
?>
Now I'm on page "about", my URL now is http://localhost/veco/about Now on the about page, I made a form
<form action="data/cs_menu.php" method="POST">
<input type="text" name="f_menu">
<input type="submit" name="save_menu">
</form>
Now when I submit this form, it will redirect me to http://localhost/veco/about/data/cs_menu.php which is correct, but when I use the function home_url, it gives me "http://localhost/veco/data/", not "http://localhost/veco/"
Any ideas? I am not using Wordpress right now, but If you are familiar with WordPress, they have a function "home_url();" which returns the "http://localhost/FILENAME/" which is I am trying to copy.