Re: this line throws up an undefined index.
| From: | Jochem Maas | Date: | Mon, 30 Jan 2006 09:38:57 +0000 |
| Subject: | Re: this line throws up an undefined index. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-229449@lists.php.net to get a copy of this message | ||
Ross wrote:
<? $filename = basename($_SERVER['SCRIPT_FILENAME']); $link= "../text_only/$filename"; ?> any ideas how to prevent this error?$_SERVER is an array. and also a variable. we can be sure it exists if we are running a webserver php module, so we don't need to test if it's set or not BUT the index of the array pointed to by 'SCRIPT_FILENAME' does not necessarily exist so (the contents of the $_SERVER is different from server to server)... $filename = basename(@$_SERVER['SCRIPT_FILENAME']); if (!$filename) { die('yuck!'); } or something like: if (!isset($_SERVER['SCRIPT_FILENAME'])) { die('yuck!'); } else { $filename = basename($_SERVER['SCRIPT_FILENAME']); } to see what's in $_SERVER do something like: ecoh '<pre>'; // this line assumes you are viewing the output via a webbrowser! print_r($_SERVER);