Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^3: How to get current URL with Query String

by techdex (Initiate)
on Feb 04, 2014 at 06:26 UTC ( #1073310=note: print w/ replies, xml ) Need Help??

in reply to Re^2: How to get current URL with Query String
in thread How to get current URL with Query String

I wanted to quickly input here. I've been using this, especially where I have apps that run on both http:// and https:// In my case where I use OOP it's usually a subroutine in the main package, but this works just as well, calling the $page_url variable. Some smart concatenation, no additional modules, strictly native...

my $page_url = 'http'; if ($ENV{HTTPS} = "on") { $page_url .= "s"; } $page_url .= "://"; if ($ENV{SERVER_PORT} != "80") { $page_url .= $ENV{SERVER_NAME}.":".$ENVSERVER_PORT}.$ENV{REQUEST_U +RI}; } else { $page_url .= $ENV{SERVER_NAME}.$ENV{REQUEST_URI}; }
what do you think?

Comment on Re^3: How to get current URL with Query String
Download Code
Replies are listed 'Best First'.
Re^4: How to get current URL with Query String
by Your Mother (Chancellor) on Feb 04, 2014 at 15:30 UTC
    if ($ENV{HTTPS} = "on") {

    Already shows a problem with this sort of approach (copying and pasting the “same” snippet around). I don’t doubt you have it right somewhere but that above is a bug (you need eq and you should probably also normalize case with lc). It will always say the URL is https as is.

    String concatenation is, to me, code smell. The “no additional modules” shtick can be paraphrased to: no help from experts who have been solving and testing this exact problem against edge cases for 20 years and will continue to do so as the standards are updated.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1073310]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2016-02-15 00:21 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (471 votes), past polls