Why is localhost added to all my links ?

This is a discussion on Why is localhost added to all my links ? within the PHP Language forums, part of the PHP Programming Forums category; Not sure if this is a php, mysql, or apache issue. I use win2k and I have AMP on my ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-22-2005
Hal Halloway
 
Posts: n/a
Default 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
Reply With Quote
  #2 (permalink)  
Old 01-22-2005
Michael Fesser
 
Posts: n/a
Default Re: Why is localhost added to all my links ?

.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
Reply With Quote
  #3 (permalink)  
Old 01-22-2005
Janwillem Borleffs
 
Posts: n/a
Default Re: Why is localhost added to all my links ?

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



Reply With Quote
  #4 (permalink)  
Old 01-23-2005
Mark
 
Posts: n/a
Default Re: Why is localhost added to all my links ?

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.
Reply With Quote
  #5 (permalink)  
Old 01-24-2005
Michael Fesser
 
Posts: n/a
Default Re: Why is localhost added to all my links ?

.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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:18 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0