Undesired forward slash

[php]$home_url = ‘http://’ . $_SERVER[‘HTTP_HOST’] . dirname($_SERVER[‘PHP_SELF’]) . ‘/index.php’;
header('Location: ’ . $home_url);[/php]

The above code is from the login script and redirects to the index page. Upon utilizing the button however,
the url contains a backslash following the host name, like so: hostname/index.php

The error page says something like “cannot find server .”

When you backspace over the backslash, the index page loads fine.

I was wondering if urlencode or htmlentities comes into play here.

You could try wrapping the dirname function in the rtrim function:

[php]rtrim(dirname($_SERVER[‘PHP_SELF’]),’/’)[/php]

I’ll definitely give that a shot and report back. Thanks!

Well the rtrim function didn’t do the trick, though it didn’t do any damage. Still getting host/index.php when I hit my login or logout link (to login.php and logout php respectively) to access the $home_url Location.

Phil P.

Can you just replace the string with what you want ?
Does this have to do with the way apache is setup ?

[php]
$home_url = ‘http://’ . $_SERVER[‘HTTP_HOST’] . dirname($_SERVER[‘PHP_SELF’]) . ‘/index.php’;
$home_url = str_replace($home_url, ‘\/’, ‘\’);
header(‘Location:’.$home_url);
[/php]

I see, use str_replace function to eliminate that forward slash. I will try that tonight.

I am not sure about how apache setup affects this. As I say, I using vhosts on the local machine, and it works well for my learning, except for this minor blip. I am using the actual code that they have in the book.

I have not tested up on an actual server, which I do have access to.

Thank you for your suggestion. Will update within 12 hours.

Maybe a mistake in .htaccess file ?

Check the vhost in config on apache

Well, it appears that as your code exists, it is actually doing what it is supposed to do.
It changes the ending value to a “” on Windows systems. There are several ways to fix this problem.
Most include removing the ending “” and adding your own “/” in place of it.

Here is the link to the PHP manual that explains it’s functions. If you read down a few responses, you will find many ways to fix it. Hope this helps… Good luck!

http://php.net/manual/en/function.dirname.php

Sponsor our Newsletter | Privacy Policy | Terms of Service