Jump to content

substr_replace, have just a couple questions about it.


wtfsmd

Recommended Posts

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.