-3

I want to make php script that will redirect any url passed to it..
I am running affiliate website and i am importing offers from api and those api give direct link and i want to hide it. so, i thought to create script and add prefix to all links to hide them then add not to index /go to google..

example go/goto.php?http://exampleurl.com/

Now url wont be same it could be any url so i want the script to goto exampleurl.com. so that i can prexix all url with goto.php?

is it possible to do so.. or any other recommendation..

Bibhudatta Sahoo
  • 4,808
  • 2
  • 27
  • 51
Mangal
  • 41
  • 1
  • 8
  • 5
    Possible duplicate of [How to make a redirect in PHP?](https://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php) – Andreas Jul 29 '17 at 07:12
  • You edited one letter @Bibhudatta? Why? There is more to edit if you really care. Or is it just for a badge? – Andreas Jul 29 '17 at 07:24
  • 1
    @Andreas The question had an upvote removed just after he edited it (as well as deleted his downvoted answer) so it was probably to enable that as votes get locked in unless an edit happens. – user3942918 Jul 29 '17 at 07:29
  • @Paul I see. So because he gets downvoted the question is bad and needs to go from up to downvote. I thought votes should be given according to quality of posts not how your own answer is up/downvoted. – Andreas Jul 29 '17 at 07:33
  • @Andreas He didn't downvote this question, that vote was already there. A vote up was simple removed immediately after he edited the question (taking the total score from 0 to -1.) And yeah, that implies there was some undesired behavior. – user3942918 Jul 29 '17 at 07:35
  • @Paul ok. I misunderstood you there. But yes it does show his/her way of thinking. – Andreas Jul 29 '17 at 07:40

2 Answers2

1

your redirect.php:

<?php

$url = $_GET['url'];
header('Location: ' . $url);

when you navigate http://yourwebsite.com/redirect.php?url=http://www.google.com should redirect you to google.

bubjavier
  • 982
  • 8
  • 11
  • This is dangerous. an exploiter can spread URLS to your famous, known and trusty domain to redirect to his page. Sanitize the URL before you direct your users to it, don't redirect to **any** page – Accountant م Jul 29 '17 at 07:17
  • I didn't thought about that.... can i add limited domains that i can redirect.. all the links will be having same domain with change in ?id that redirect to other page. – Mangal Jul 29 '17 at 07:34
0

Try this code:

<?php
$link = $_SERVER['QUERY_STRING'];
header("Location: ".$link);
?><html>
<head>
<meta http-equiv="Refresh" content="0;URL=<?php echo $link; ?>">
<script type="text/javascript">
window.location='<?php echo $link; ?>';
</script>
</head>
<body bgcolor="white">
<p>Go to <a href="<?php echo $link; ?>">there</a> &rarr;</p>
</body>
</html>