Hello guys, I'm new to PHP programming and I would like your help in performing a little task on my site. I have a Wordpress blog and I make posts which consist of some content and some links to external sites. I would like those links to pass through an internal page before letting the users access the external site. For example: I have some links to on my post to external sites. The visitor clicks a link and it gets him to an internal page of my blog where there is a button like "Access the content" and when he clicks it it redirects him to the external site. If you would like to see exactly what I mean, here's a link to site that has exactly this functionality I'm looking for: http://watch-series.com/episode/90210_s2_e14-53025.html (I'm not yet allowed to put a link). So, if you click on one of those links will get you to an internal page where you can push a button to direct you on an external site. Hope I explained it well. Please, if you have any guidance that may help me achieve this, I'll really appreciate. Thank you in advance, Chris
I would recommend to create a redirect.php. Which you can call as: h-ttp://www.yoursite.com/redirect.php?url=1 In here you do the following: <? if ($_GET['id'] == 1 { $url = "h-ttp://www.externalsite.com"; } ?> <a href="<?php echo $url; ?>">Access the content</a> Of course you can extend your ifloop with more ID's and add more HTML to the page. I hope this helps!
Hi Coranti, Thanks for replying. I tried to use your code, but can't get it to work. Right now, my redirect.php page looks like this: And I tried to access the page by this: h-ttp://www.mysite.net/redirect.php?url=1 and it just gives "Error 404". Am I missing something?
I hope you changed externalsite and mysite to the appropiate URL's? Also did you remove the - in the URL's? (they are there because I'm not allowed to make a link)
Just use JavaScript. Don't bother filtering URLs with PHP or needing XSS scripts or whatnot. Just visit /whatever-file-you-want-to-name-this.html?url=http://www.example.com Don't need to make new if/else statements. No security issues. <!doctype html> <html lang="en"> <head> <title>You are now leaving example.com.</title> <style type="text/css">div{margin:0 auto}</style> </head> <body> <div id="container"> <p>You are now leaving example.com.</p> <p>Your destination is: <span id="u"></span>.<br>Different terms of use and privacy policies may apply.</p> <p><button onclick="_redirect();">Click here to continue to external site</button></p> </div> <script type="text/javascript"> function _onload() { var r = 'http://www.example.com/'; if (location.href.match(/url=([^&]+)/)) {var r = RegExp.$1;} else if(location.href.match(/urlesc=([^&]+)/)) {var r = unescape(RegExp.$1);} try{document.getElementById('u').innerHTML=r;}catch(e){} } function _redirect(){ if (location.href.match(/url=([^&]+)/)) {var r = RegExp.$1;} else if(location.href.match(/urlesc=([^&]+)/)) {var r = unescape(RegExp.$1);} location.href = r; } window.onload = _onload(); </script> </body> HTML:
Yes, I did all that and it didn't work. I'm gonna try also with JavaScript, as krsix suggested. Thank you both for trying to help. LE: krsix, I've tried your code, however I don't know if I did it correctly, because I can't get it to work. What I did, I created a page redirect.html where I've put the code and in place of example.com I've put my site's address. I tried to verify the functionality by accessing mysite.com/redirect.html?url='external_site.com' and I still get a 404. Using Wordpress blogging platform, is it possible that I may have to add other coding in other pages? If you have any ideas on how to get this to work... will be much appreciated. I feel bad I'm such a noob at this