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.
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.
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.
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.
Related
so I can easily edit some links, I was thinking about having my website act as the middle part, where I store the links in the database and use PHP to redirect (kind of like a shortener but probably with more basic code)
I did a test with two URL shorteners, and to me it seemed like the middle one wasn't revealed at all, however, I don't know what would happen if one went slow (like the browser could possibly say receiving data from x or actually put the URL in the bar). Also, even if it wasn't anything obvious, would you still be able to see headers received from the site or something?
Your browser will know. The first one just returns a response with a redirect header containing the new url. The browser will use this url to make a new request to the second redirect url.
You can probably see this happening when you inspect the Network tab in the developer tools (F12) in your browser.
Lets say I have a URL, www.mysite.com/go that I want to redirect to www.anothersite.com/site.php?id=999
The trick is, I do not want anothersite.com to be able to see that the request came from mysite.com. It should look like the address www.anothersite.com/site.php?id=999 was typed into the addressbar manually by the user.
It is important to note, that this has nothing to do with Google Analytics, and there will never exist an anchor link to www.mysite.com/go anywhere. Instead, the user will manually input www.mysite.com/go in the address bar (which is easier to remembar than the long URL).
How is this achieved? The technology in question is PHP. I imagine that it can be achieved with the header() function, but google searches reveal that this only works with https, not http. Can I via PHP control what the client provides of referrel information when the redirect is performed? I guess that if I want it to look like the address was typed into the address bar, I would have to blank out the referrer information. Is it possible?
It's not possible by means of a HTTP Redirect. You don't have any control over the outgoing referrer header as the browser handles it entirely client-side.
Your only real option that you can directly control is to use HTTPS. Referrers with a value of a HTTPS page are not carried forward by browsers.
Example flow:
http://www.mysite.com/go (so any existing links don't have to change)
https://www.mysite.com/go
http://www.anothersite.com/site.php?id=999
IS there, a cross browser, way to identify each browser window uniquely?
I need to store some values which are unique for a window.
Even if the user opens two windows on the same browser to the same site.
There is no Ajax involved, every click on a link will load a new page.
And how would I access that name from the server? (for this, assume I use php, but example in any other language, is also good)
You could identify the windows by putting and maintaining unique arguments into the query strings of all the urls. For example, if the current url is /foo.php?windowid=abhn7y76g7hygy7yhnui98u8mc then each url in that pages html would have an id distnct from the url and the others in the document. uniqid() is perfect for this as it uses time, and so they're lexicographically increasing id's.
The one edge case you need to handle is when someone opens the exact same link twice(maybe via clicking, or maybe via copy pasting the url and manually opening a new window). I think the only real solution is to have the server keep track of which id's have been used, and if it notices a second request for the same id, it redirects the request to the same url, but a new id. This would maintain unique id's across all browser windows.
on second thought, dont even bother attaching the ids to urls in the html. Just make the server do the logic if no id, redirect to same url with a new id. if id, and the id has been used before, redirect to same url with new id.
make sure to send no cache headers for the html pages because you need the browsers to recheck with your server if the back button is used.
window.name can be set via JavaScript. Strangely, it can also hold a few megabaytes worth of string data and is sometimes used as client-side storage.
You'd have to pass the name back to the server with each request in order to know which window in the caller.
I'm developing a website, but stuck at some point, where i needed to detect outgoing links on my website, and either forbid the links, or accept that, i don't know how facebook is doing this, but they can do it through facebook.com/l.php that if the link is marked spam, users will get notified about it.
I don't know if that's a php or htaccess, it worked in php using the DOMDOCUMENT, but it's not a real solution for this.
This is not something that you solve on the Apache or .htaccess level. Basically, whenever you're outputting a link, check if it's external, and if it is, change the destination to your redirector.
The redirector can then just check the URL passed, and if it's marked as malicious, it can show a message, and if it's not, then it can either automatically redirect or display some kind of notice that you're leaving the website.
I'm not 100% sure how Facebook is implementing it, but what I would recommend is to use JQuery (or another javascript library) to rewrite all external links to a validating PHP script (e.g. Facebook's l.php script), w/ the intended url getting passed as a GET parameter.
Using JQuery, it might look like:
$('a[href]').each(function(){
var safe_href = 'http://yourdomain.com/yourscript.php?url='+$(this).attr('href');
$(this).attr('href', safe_href);
});
You can can then do a database lookup in yourscript.php based on the variable $_GET['url'], and redirect to that url if it's safe or display a message if it isn't.
l.php is a script that reads links via $_GET['u']. With the url in the your hand you decide where you want the client to be redirected.
So as it looks, you want the users to teach your application what is spam and what not. For that you will need a button "report spam" beside the url.
I'm having difficulty trying to figure this out. I'm not even sure if it's possible.. I will appreciate any sort of help!!
On site A, I have a link (an affiliate type link) that redirects to site B. When clicking the link on site A, I use this script to redirect..
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $url);
exit;
the $url var is just site's "A" URL. What I can't figure out is how to pass a variable from the redirection script onto site B without using a query string in the URL itself (for example, http://www.siteB.com/?var_to_pass=something)
Also, both sites are on a different server so I'm not sure if sessions will work. But between sites I have a script which I hope I can use someone to achieve what I need.
There's only one way to pass data between sites via a redirection, just as you're doing, in the URL via query vars. You can't make a browser redirect via POST, so GET's your only option.
You can do it with a POST and javascript but it's not as pretty (or as reliable). Simply have a form that's submitted by the body onLoad event.
You just want to hide the variable from people? You can do this:
www.sitea.com -> (redirect) -> www.siteb.com/incoming?var=blah
# then
www.siteb.com/incoming?var=blah -> (redirect) -> www.siteb.com/
It will happen so quickly that the user won't even see and the end result is that siteb gets the variable from sitea and the user ends up on a clean looking url.
Alternatively you can use curl (but note, it won't redirect, if you want to redirect you have to use solutions descrbed above), to send and receive variables from one server to another, just when receive make sure to save your variables somewhere(database)..