469,358 Members | 1,611 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

Why is localhost added to all my links ?

Not sure if this is a php, mysql, or apache issue. I use win2k and I
have AMP on my system as a localhost. I use this to test PHP/MYSQL
scripts I write on my local PC.

I render a URL w/PHP by reading the URL string from a mysql field, eg.
on the php web page it shows as eg. www.yahoo.com link

But when I click the link I see that "localhost" is added to the URL
and it goes nowhere. ie. it get localhost added to the front -
localhost/www.yahoo.com

Is there a setting somewhere so that the link is exactly what the link
is and localhost is not added.

Thanks
Jul 17 '05 #1
4 7033
.oO(Hal Halloway)
I render a URL w/PHP by reading the URL string from a mysql field, eg.
on the php web page it shows as eg. www.yahoo.com link

But when I click the link I see that "localhost" is added to the URL
and it goes nowhere. ie. it get localhost added to the front -
localhost/www.yahoo.com

Is there a setting somewhere so that the link is exactly what the link
is and localhost is not added.


Relative URLs are expanded with the current hostname. If you want to
link to external servers the URL has to start with http(s)://.

Micha
Jul 17 '05 #2
Hal Halloway wrote:
I render a URL w/PHP by reading the URL string from a mysql field, eg.
on the php web page it shows as eg. www.yahoo.com link

But when I click the link I see that "localhost" is added to the URL
and it goes nowhere. ie. it get localhost added to the front -
localhost/www.yahoo.com

Is there a setting somewhere so that the link is exactly what the link
is and localhost is not added.


When you construct the anchors without the "http://" prefix, all the targets
are expected to be on the same server.
JW

Jul 17 '05 #3
Hal Halloway wrote:

But when I click the link I see that "localhost" is added to the URL
and it goes nowhere. ie. it get localhost added to the front -
localhost/www.yahoo.com
looks like PHP has a couple of rules:

1. if you prefix a URL with http:// or just a /, then it leaves it alone.

i.e "http://www.happyhappybunnies.com"
"/showerror.php?err=342"
2. if you do neither of these, it prefixes them with a host name and /.

Is there a setting somewhere so that the link is exactly what the link
is and localhost is not added.
best choice would be to prefix full URLs with http:// and relative URLs
with /.

PHP does have a mechanism via which you can control what markup elements
it modifies on output, which somehow ties into the url_rewriter.tags entry
in the php.ini file. i haven't studied this too much, so i'm not 100%
certain how it works.

good ruck!

mark.

Thanks


--
I am not an ANGRY man. Remove the rage from my email to reply.
Jul 17 '05 #4
.oO(Mark)
Hal Halloway wrote:
But when I click the link I see that "localhost" is added to the URL
and it goes nowhere. ie. it get localhost added to the front -
localhost/www.yahoo.com
looks like PHP has a couple of rules:


It's not a PHP issue.
1. if you prefix a URL with http:// or just a /, then it leaves it alone.

i.e "http://www.happyhappybunnies.com"
"/showerror.php?err=342"

2. if you do neither of these, it prefixes them with a host name and /.
The user agent (browser) expands URLs if necessary, not the server. Have
a look at the generated HTML to see what PHP did send to the browser.
PHP does have a mechanism via which you can control what markup elements
it modifies on output, which somehow ties into the url_rewriter.tags entry
in the php.ini file. i haven't studied this too much, so i'm not 100%
certain how it works.


This only applies to session handling.

Micha
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Michael Rybak | last post: by
23 posts views Thread by darrel | last post: by
5 posts views Thread by Howard | last post: by
12 posts views Thread by John Kotuby | last post: by
7 posts views Thread by pek | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.