Chris
Chris

Reputation: 21

$_SERVER['SCRIPT_FILENAME'] returns different value on local and remote server

I am working on setting up a local development environment using MAMP and Coda 2.
I intend to work locally and publish my changes to my remote server.
I am finding that my relative links between pages do not work and I suspect it is because $_SERVER['SCRIPT_FILENAME'] which I am echoing in:

<base href="<?php echo $_SERVER['SCRIPT_FILENAME']; ?> > 

is returning different values depending if my header.html file is on the local or remote server.
What I have noticed is the containing site folder is included in the returned value ex: folder/page_name.php

I am not sure how to remedy this. Ultimately I want a solution that will work both locally and remotely

Upvotes: 0

Views: 5976

Answers (2)

GolezTrol
GolezTrol

Reputation: 116100

$_SERVER['SCRIPT_FILENAME'] is the full (local) path of the script, so it's likely different on the server and it's not the best value to use when constructing urls.

Instead of using that value, I think you need $_SERVER['SCRIPT_NAME'] or even $_SERVER['REQUEST_URI'].

Upvotes: 3

windrunn3r.1990
windrunn3r.1990

Reputation: 414

Your question is a bit unclear, but I will give it a shot.

$_SERVER is an array containing server and execution environment information. Basically, the list of environment variables provided by the server and defined on the user environment the web server is using for execution.

So if the variable SCRIPT_FILENAME is playing up, you can check its value on the server.

For linux based systems: https://www.digitalocean.com/community/tutorials/how-to-read-and-set-environmental-and-shell-variables-on-a-linux-vps

Upvotes: 0

Related Questions