On Jan 19, 2009, at 3:28 PM, Daniel Brown wrote:
On Mon, Jan 19, 2009 at 14:32, Richard Heyes <richard@xxxxxxx> wrote:
Notice: Undefined index: 2 in /home/raosetc/public_html/purl/p.php
on line
19
and here is Line 19:
$data = explode("/", $_SERVER['REQUEST_URI']);
When I view that file, on line 19, I see:
echo <<<HTML
Only when you log into certain accounts and view the file after I had
made changes :P
Are you sure it's an array? Use print_r() or var_dump() on
$_SERVER['REQUEST_URI'] on the preceding line. Just for testing, you
could do this too:
$_SERVER['REQUEST_URI'] = 'It/Works';
...on the preceding line.
Well, that wouldn't address the issue of the code he gave on the
line reported, but I know what you mean, Richy. He's turning
$_SERVER['REQUEST_URI'] into an array with explode() if it contains a
forward-slash ("/").
What would be better in that case would be:
<?php
$data = isset($_SERVER['REQUEST_URI']) &&
strlen($_SERVER['REQUEST_URI']) > 0 ?
explode('/',$_SERVER['REQUEST_URI']) : $_SERVER['REQUEST_URI'];
if(is_array($data)) {
// Handle as appropriate.
}
?>
However, that's not the best option as:
1.) REQUEST_URI may not (though it should) have *any* forward
slashes in the URI passed to PHP by the HTTP server.
2.) It leaves too much other stuff to be done.
Instead, check out:
<?php
$data = basename($_SERVER['REQUEST_URI']);
echo $data; // In case you're not yet aware of what you'll receive
from the use of basename()
?>
I'm not positive that does exactly what I want... What I'm really
going for is given this URL:
purl.mysupersite.com/test/mail
"test" refers to a record in the database.
"mail" refers to a file on the server which is included when "mail" is
present. Otherwise the main page is used.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php