Search code examples
phppaypalpathfilesystemsdirectory-structure

PHP - Relative Paths! Easy for experienced developers, I should think


I have a website where I sell digital downloads, and have been trying to set up PayPal express checkout for some time. I am finally getting it integrated, but there is one thing that I can't figure out.

My code says get_script_uri( 'buy.php' ) ); This means that when the payment is processed, the user will be redirected to "buy.php".

PayPal_Digital_Goods_Configuration::return_url( get_script_uri( 'buy.php' ) );

However, my page that includes this code (paypalbuy.php) is in a directory called "dl/". When the payment is processed, and the user is redirected to 'buy.php', the user is redirected to 'dl/buy.php' because of the path.

How can I fix this? How can I set 'get_script_uri( 'http://google.com' ) );' and have the user redirected to a URL, instead of the file within the path.

EDIT: HERE IS my get_script_uri function:

    function get_script_uri( $script = 'index.php' ){
// IIS Fix
if( empty( $_SERVER['REQUEST_URI'] ) )
    $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];

// Strip off query string
$url = preg_replace( '/\?.*$/', '', $_SERVER['REQUEST_URI'] );
//$url = 'http://'.$_SERVER['HTTP_HOST'].'/'.ltrim(dirname($url), '/').'/';
$url = 'http://'.$_SERVER['HTTP_HOST'].implode( '/', ( explode( '/', $_SERVER['REQUEST_URI'], -1 ) ) ) . '/';

return $url . $script;
}

Solution

  • Without looking at get_script_uri() source code I can't be sure, but from the directory structure you described, I infer that by changing get_script_uri( 'buy.php' ) to get_script_uri( '../buy.php' ) should give you the correct URL you're looking for: ../ means parent directory.