Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to trim current filename of page from URL?
    primarykey
    data
    text
    <p>I have a method, it looks like this:</p> <pre><code>private function setURL() { $pageURL = 'http'; if(isset($_SERVER["HTTPS"]) &amp;&amp; $_SERVER['HTTPS'] == "on") { $pageURL .= "s"; } $pageURL .= "://"; if($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } if(substr($pageURL, -4) == ".php") { // damn. this is harder to recover from. $len = strlen(basename(__FILE__, '.php')); $len = strlen($pageURL) - $len; $pageURL = substr($pageURL, 0, $len); } if(substr($pageURL, -1) != "/") { $pageURL .= "/"; } $this-&gt;url = $pageURL; } </code></pre> <p>If a user doesn't enter a filename, the URL returned is as expected, <code>http://localhost/zenbb2</code>. If the user does, however, the URL returned is wrong in some way, no matter what permutation I try to perform. For instance, this code returns <code>http://localhost</code> when visiting <code>http://localhost/zenbb2/index.php</code>, but <code>http://localhost/zenbb2</code> when visiting that URL.</p> <p><strong>Edit</strong> The contents of my .htaccess file are:</p> <pre><code>Options -indexes RewriteEngine on </code></pre> <p>Also, I mean the current URL as in, if I were visiting <code>http://localhost/zenbb2/index.php</code>, it would trim the <code>index.php</code> from the URL so I can use it in various places in my code. Ideally, in the end, I could use it like this:</p> <pre><code>$url = 'http://localhost/zenbb2'; echo "&lt;link rel=\"{$url}/sample.css\" /&gt;"; // http://localhost/zenbb2/sample.css </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload