homepage Welcome to WebmasterWorld Guest from 54.161.192.130
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
link adds extra forward slash automatically
if the page name is absent in the query a forward slash is added
phparion

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3605113 posted 10:21 am on Mar 19, 2008 (gmt 0)

Hi

I call a php function from the main page body. this function reads database and generate a link code like

<a href='http://www.example.com/index.php?affid=009090&SID=b3b0172e52dcc6cf61182891904440a3' target=_blank title='strip'>slash</a>

the above code works fine in the main page but as soon as a link code is generated without page name , index.php, it shows extra slash i.e

<a href='http://example.com?affid=009090&SID=b3b0172e52dcc6cf61182891904440a3' target=_blank title='strip'>slash trippers</a>

when i mouse over the link it shows

<a href='http://example.com/?affid=009090&SID=b3b0172e52dcc6cf61182891904440a3' target=_blank title='strip'>slash</a>

however the slash is doesnt exist after .com in the actual code.

Similarly, a code like

<a href='http://example.com&affid=009090&SID=b3b0172e52dcc6cf61182891904440a3' target=_blank title='strip'>slash</a>

is displayed like

<a href='http://example.com&affid=009090&SID=b3b0172e52dcc6cf61182891904440a3/' target=_blank title='strip'>slash</a>

i.e now the slash is added at the end of the HREF value.

I checked this in both FF and IE it is the same.

can anybody help me please to avoid this extra slash and display the actual code generated from the function call?

thanks

 

MarkFilipak

5+ Year Member



 
Msg#: 3605113 posted 10:46 am on Mar 19, 2008 (gmt 0)

I believe the href in the actual link needs to be
'http://example.com/?affid=009090&SID=b3b0172e52dcc6cf61182891904440a3'
right?

> I checked this in both FF and IE it is the same.
The problem is in your PHP, not in the client code. You need to parse the url coming from the database and add the slash if there is no filename.

penders

WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



 
Msg#: 3605113 posted 11:08 am on Mar 19, 2008 (gmt 0)

Are you doing some URL rewriting server side?

<a href='http://example.com/?affid=009090&SID=b3b0172e52dcc6cf61182891904440a3' target=_blank title='strip'>slash</a>

IMHO I would have said that this (with the extra slash) was more correct, since the server is afterall going to have to resolve this to "...com/index.php" (or whatever your default page is)?

<a href='http://example.com&affid=009090&SID=b3b0172e52dcc6cf61182891904440a3' target=_blank title='strip'>slash</a>

I would have said this was invalid. There is no query string marker (?) indicating the end of the URL and the start of the query string. It is just one big URL. And I guess, the server will resolve this as 'http://example.com&affid=009090&SID=b3b0172e52dcc6cf61182891904440a3/index.php'? So a slash at the end is correct.

can anybody help me please to avoid this extra slash and display the actual code generated from the function call?

To change browser behaviour? Hhhmmm, is this possible? If for instance you specify a relative path in your code, the browser will resolve this to an absolute path as you 'hover' over it.

Is the browser breaking your URLs?

---
EDIT: I didn't see that MarkF had already replied :)

phparion

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3605113 posted 4:57 am on Mar 20, 2008 (gmt 0)

The problem is in your PHP, not in the client code.

if it is PHP then it should not add slash because for PHP I am calling a function, querying database, creating a concatenated string and returning that as a variable. How does PHP know the returning string is a URL and she should add slashes to it with her own intelligence?

I think it is a browser thing.

Achernar

5+ Year Member



 
Msg#: 3605113 posted 11:53 am on Mar 20, 2008 (gmt 0)

From rfc 2616:
http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]
...
An empty abs_path is equivalent to an abs_path of "/".

An absolute path is at minimum equal to '/'.

The browser will automatically convert url into the valid form (just like it encodes " " as "%20"). And the webserver will most probably redirect the incomplete url to a valid one (if the entity is a directory and the url doesn't end with a "/", it will automatically redirect and append one).

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved