Activate external href onclick from link - php

Let's say you have a link on your site and when you click that link it brings you to a different site. A site that you do not own and I would like it to have a "onclick" already activated maybe from a script that redirects to that link. Is this possible?

Simple answer NO. If possible it would be called 'mousejacking' :)

Setting window.location.href to a target link URL in javascript will, for most browsers, redirect the browser to the specified URL.
If you're specifically trying to make a link on your site redirect the user to a Google Search, read here.
There is almost no good reason to wrap an external site that you do not own in a frame. That kind of stuff is usually considered shady/malicious.

Related

Efficent url redirection in php

I am using a url redirection technique similar to google
Example
if you type wikipedia in google you get a wikpedia page result but if you click the link it will first go to this kind of redirecting link
http://www.google.com/url?some_paramaeters_for_wikipedia_page_redirection
and then it will go to
http://www.wikipedia.org/
i have made similar algorithm in my website and its working properly;But as in google when you want to copy the link location
it doesnt copy the main web link
http://www.wikipedia.org/
Instead it copies
http://www.google.com/url?some_paramaeters_for_wikipedia_page_redirection
I want to know if it is possible for users to copy the orginal link instead of url redirecting link without changing redirecting method.
Thanks for your info
Yes, what you should do is keep the real link in the href attribute (so the "Copy link location" works),
and with a bit of Javascript, on the click event of your link, replace this real URL with your redirecting one's.

How do I find out that a link was seen

I'm trying to make a page with some links and when somebody clicks on a link, the score count will go up.
How can I find out the visitor who has really seen the page related to link? But not just click the link and close the page for score...
really seen means: page loads completed.
and my links opens in new window.
any solution?
You cant really see pages that aren't in the same domain. Chrome even puts them in a separate thread.
Back in the day you could have used a CSS exploit talked about here: https://developer.mozilla.org/en-US/docs/Web/CSS/Privacy_and_the_:visited_selector
If you really want to make a page with this kind of functionality you will have to make a browser plugin/extension.
You can include a nonce token in the link, and post that token to the server, render the page embedding that same token in some javascript and have the javascript post back the token when the page is done rendering. Seems kinda overkill though.
The only thing I could thing of is maybe make the link to like a redirect page on your site and then you could control to see if the page was loaded and then like after the page was loaded redirect to the actual webpage to link is intended. This way you know for sure that the user waited to view the webpage.
Other than that I don't think there is any other way for you to go about this.

PHP: check from which page the link is directed

lets say i have a page hit.php in my website and the link is to this page is available on every\many pages in the website..
lets say i click <a href"hit.php">HIT</a> from any page.....
is there a way when hit.php is loaded i could know that the page from which this page was..
meaning if i click the link to hit.php from 'index.php' i could check loading hit.php that the user is navigating here from 'index.php' or any other page...
i know this i could establish in site by passing variables in URL like 'hit.php?pagename=index' but is there another way
p.s i know its crazy but still :)
$_SERVER['HTTP_REFERER'], although it can easily be spoofed or disabled.
You can use the referer. In PHP, it's:
$_SERVER['HTTP_REFERER']
However, users can configure their browsers not to send this, or spoof it. You should ensure that your code doesn't break if it's absent, or faked.

I'm not sure if I should use a redirect

I have an affiliate link on my webpage. When you click on the link it follows the href value which is as follows:
www.site_name.com/?refer=my_affiliate_id
This would be fine, except that the site offers no tracking for the ads, so I can't tell how many clicks I am getting. I could easily implement my own tracking by changing the original link href value to a php script which increments some click stats in a database and then redirects the user to the original page. Like so:
<?php // Do database updating stuff here
Header("Location: http://www.site_name.com/?refer=my_affiliate_id");
?>
But I have read some articles that say that using redirects may be seen by google as a sign of 'blackhat' techniques and they might rank me lower, unindex my site or even hurt the site that I'm redirecting too.
Does anybody know if this is true, or have any idea of the best way I could go about this?
Many thanks in advance
Joe
You could always do what Google does with search results. They have the link href normal, until the mousedown event. something to the effect of:
adlink.onmousedown = function(e) {
var callingLink = /* stuff to actually get the element here */;
callingLink.href = 'http://mysite.com/adtrack_redirect_page.ext?link=' + escape(callingLink.href);
}
Or something like that :P
So, Google will see a normal link, but almost all users will be redirected to your counter page.
Using a 301 redirect simple tells Google that the website is permamently moved. It should have, according to most random people on the internet and according to Google itself, no effect on your page-rank.
Actually I've read (can't remember where exactly) that this kind of redirect DOES HURT your rating. No, it won't "kill" your website nor the referenced, as far as I know (and please do check further), but it will hurt your site's rating as I said.
Anyway I'd recommend using some javascript to refer anything out of you domain - something like "window.open(....)" should do the trick, as Google will not follow this code.
There, refer to your tracking script which will redirect further.
You could use a javascript onClick event to send an ajax signal to your server whenever the link is clicked. That way the outgoing link is still fully functional, and your server-side script can increment your counter to track the clickthrough.

Is it possible to dynamically change the URL of a webpage?

I just wanted to know, is there any possible way to change the URL that appears in the address bar of a webpage dynamically? Like, maybe there are two buttons on the webpage, and when the user clicks one it will (or won't it does not matter) refresh the page and the url will be mysite.com/page1, or if the user clickes the second button, the url that appears in the address bar will be mysite.com/page2?
I do not need it to chaneg the domain, just the part after.
Just wanted to say, that I DO NOT want to go to another page. This must be done on one page. It does not matter if it is done with JS, PHP, or via the .htaccess file, but it must do this with only one page.
Outside of changing the .location you only really have control over the window.location.hash.
window.location.hash = "boo"; http://mysite.com -> http://mysite.com/#boo
This is the only way to not go to a new page while changing the URL. All other methods will refresh the page or redirect the page:
window.location redirects user when changed
window.location.pathname redirects user when changed
window.location.search redirects user when changed
window.location.hash does not redirect user when changed
You can also just change the non domain path by using a relative url:
window.location = "page1"; // include forward-slash if necessary
// goes to http://somesite.com/page1
You can definitely (and easily) serve the same page off both /page1 and /page2 and have the buttons navigate respectively to one and the other -- "refreshing the page", as you say (i.e. loading it up again from the server, or browser cache), and of course change accordingly what appears in the address bar, too. However, I don't see what's the point of doing that.
I don't quite understand what you want.
Is it that in both cases, you want the same page to be shown but with different urls ?
In that case, you could write a .htaccess file to redirect to the same page for both /link1 and /link2 and point the button to either of the links.
Just to update this question in case others come along.
This can now be handled via javascript using pushState(). There's a couple of libraries (such as History.js) that aim to ease implementation across different browsers currently without proper support. However, if you'd like see a simple usage example without the use of such libraries, feel free to check out the following article on Hawkee
Dynamically change URLs using Push and Popstate

Categories