wtfsmd Posted November 21, 2008 Share Posted November 21, 2008 I am writing an install script and a bump i have run into is when i am using the substr_replace to trim up a url that i get from people that are using the install script. I know that the page name is index.php and what i would like to do is delete the page/file extension (install.php) from the url i get back. The problem that i am having is when people navigate to the page and lets say they enter in the address bar: http://example.com This script will still see that they have navigated to index.php but thats not that url that they have typed in so it will then delete 9 chars (index.php) from the right leaving: http://ex If they navigate using: http://example.com/index.php it works perfectly. Here is my code: <?php function curPageURL() { $isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on"); $port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443"))); $port = ($port) ? ':'.$_SERVER["SERVER_PORT"] : ''; $url = ($isHTTPS ? 'https://' : 'http://').$_SERVER["SERVER_NAME"].$port.$_SERVER["REQUEST_URI"]; return $url; } function curPageName() { return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); } $str = curPageName(); $originalUrl = curPageURL(); $cleanedUrl = substr_replace($originalUrl, "", 0, 0); $cleanedUrl2 = substr_replace($cleanedUrl, "", -strlen($str), strlen($str)); $web_url = $cleanedUrl2; ?> If anybody could help me figure out how to get this to work i would greatly appreciate it. Also if there is a way to check to see what the user has typed into the address bar i could figure out a work around. Link to comment https://forums.phpfreaks.com/topic/133624-substr_replace-have-just-a-couple-questions-about-it/ Share on other sites More sharing options...
JasonLewis Posted November 21, 2008 Share Posted November 21, 2008 Well, you could do something like: if(strpos($_SERVER['REQUEST_URI'], "index.php") !== false){ //index.php was found in the url, perform your substr_replace() }else{ //index.php was not found } Link to comment https://forums.phpfreaks.com/topic/133624-substr_replace-have-just-a-couple-questions-about-it/#findComment-695189 Share on other sites More sharing options...
Adam Posted November 21, 2008 Share Posted November 21, 2008 Try playing with... $file = basename(htmlentities($SERVER['PHP_SELF']), ".php"); Link to comment https://forums.phpfreaks.com/topic/133624-substr_replace-have-just-a-couple-questions-about-it/#findComment-695192 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.