user695575
user695575

Reputation: 127

Get url of the page in php

I am working on "Email this page" Popup page. I want to send url of base page as an email, but it should be a popup window.

I have used HTTP_REFERER, it is working fine on Firefox, but not working on Internet Explorer.

I am getting the url of current page but I want that url in new popup window page.

Is there any alternative than HTTP_REFERER.

Upvotes: 0

Views: 624

Answers (3)

outis
outis

Reputation: 77450

On the page you wish to grab the URL of, you can use $_SERVER['REQUEST_URI'] to get the requested URI (except the scheme & hostname; in other words, you get the path and query string). Pass this to your other page either using a query string or sessions. The former is preferable, as the latter isn't RESTful. There may be times when it's OK to break REST's rule against server side state, but this probably isn't it.

Upvotes: 2

Pedro M. Silva
Pedro M. Silva

Reputation: 1298

That happens because the HTTP_REFERER is sent by the client browser, which means that it's value can be totally manipulated or can even be null. This means that this variable isn't very reliable. But if the site is yours, there are other solutions.

You can send the url or any other identification like an ID by QueryStrings. So you'll have the link URL like this the_send_page_name.php?ref=index.php

Be aware that this method only works if you're opening the Pop-up in a site that's yours.

Upvotes: 0

Matt
Matt

Reputation: 7160

There is no way unless you store it or send it yourself. This page has one example of how to do it, but only really if you set it beforehand. If the site is your own then you should be ok. If not then you will struggle.

Upvotes: 0

Related Questions