<html>
<head>
<script type="text/javascript" src="jquery-1.6.1.js"></script>
<script>
$('a').click(function(e) {
e.preventDefault();
document.location.href='http://www.redirectlink.com?ref='+this.href;
return false;
});
</script>
</head>
<?php
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://192.168.0.14:8081/home/');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_response = curl_exec($ch);
curl_close($ch);
echo $curl_response;
?>
Should this be working? It curls a page and then when you click on a link on the page it should redirect to http://www.redirectlink.com?ref=‘+this.href The curling part works but it doesn’t redirect. It still takes me to the original url. The jquery-1.6.1.js file is in the same directory as all the other files.
EDIT: Problem fixed. Needed to ready the javascript.
Redirect?
Four issues:
1). You’re calling the $(‘a’) selector before the document has loaded. You won’t get any A’s. You’ll need to wrap this in document.ready or something similar.
2). You need to encodeUriComponent on this.href.
3). You seem to be assuming it is a fully-qualified URL, never a relative URL.
4). If what you’re lookng for is a redirect, you’ll need to just use a redirect header (CURL isn’t necessary):
Note — this must go ABOVE any output… basically, move your php block to the very top of the file.
Clarification. Not a redirector at all:
The above block replaces all of your PHP code in 3 easy-to-understand lines.