I´m having this affiliate link (as seen below). Why does this version of the code redirects to my desired target:
header("Location: https://www.awin1.com/cread.php?s=2079804&v=10954&q=326996&r=456987");
but that version doesn´t lead to my target. Instead it leads to "onepixel.gif"
header("Location: ".$_GET["link"]);
executed as:
linktofile.com/?link=https://www.awin1.com/cread.php?s=2079804&v=10954&q=326996&r=456987
How is the awin server able to distinguish the difference?
If you use the URL as given (linktofile.com/?link=https://www.awin1.com/cread.php?s=2079804&v=10954&q=326996&r=456987), PHP stops to parse the first parameter $_GET['link'] at the latest at the next best ampersand, so it contains at most https://www.awin1.com/cread.php. Follow the advice of RamRaider and encode the URL parameters before rendering the link pointing to your page. It should work if the link is given as linktofile.com/?link=https%3A%2F%2Fwww.awin1.com%2Fcread.php%3Fs%3D2079804%26v%3D10954%26q%3D326996%26r%3D456987
Related
I have a simple PHP website. Let's call it youtubex.com. I want to redirect youtubex URLs (in the format shown on STEP2) to my website in the format shown on STEP3. Here, I am using YouTube, just for illustration.
STEP1: https://www.youtube.com/watch?v=lj62iuaKAhU
STEP2: https://www.youtubex.com/watch?v=lj62iuaKAhU
STEP3: https://www.youtubex.com/#url=https://www.youtube.com/watch?v=lj62iuaKAhU
STEP1 shows any desired URL. STEP2 shows the same URL from STEP1 with youtubex as domain. STEP3 shows the final required URL. I am trying to redirect STEP2 to STEP3.
I tried finding some solutions to this on the internet and SO, but, none help. Here is one.
This should do the work:
RedirectMatch 301 /watch$ https://www.youtubex.com/#url=https://www.youtube.com/watch
An inefficient but full php solution can be using the location header in php :
$vid = $_GET['v']
if($vid){ header("location:https://www.youtubex.com/#url=https://www.youtube.com/watch?v=$vid");
}
by the way you can't get the text after the hash mark in php because it is not sent to the server.
javascript can do it in a more neat way without the second reload by checking window.location.href to see if the hash does not exist already and then get the v parameter in url then change url without refreshing the page by using window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
using php str_replace and header :
$step2_url = "https://www.youtubex.com/watch?v=lj62iuaKAhU";
$part2_url = str_replace("youtubex","youtube",$step2_url);//the output is : https://www.youtube.com/watch?v=lj62iuaKAhU
$step3_url = "https://www.youtubex.com/#url=".$part2_url; //the output is : https://www.youtubex.com/#url=https://www.youtube.com/watch?v=lj62iuaKAhU
now you have the final url , simply redirect
header($step3_url);
I'm new to PHP, and I'm developing a PHP plugin for CraftCMS.
On my local dev machine, this code was working; however, on the server, the pagination links are not directing properly.
This is a plugin which imports an XML feed and paginates the results.
For example, when using 'PHP_SELF' in the code, the link redirects to the index page, and when using 'REQUEST_URI,' the link works correctly the first time, yet is appended with each successive URI.
I was wondering if there would be a work around or better method for correcting this problem?
This version takes you back to the home page:
code:
echo '<< < ';
while this version appends the querystring each time:
e.g. http://mypage/test?page=1&page=2
code:
echo '<< < ';
Here is what is happening
The first time you use $_SERVER['REQUEST_URI'] the URL on the address bar (which is the value returned by $_SERVER['REQUEST_URI']) is http://mypage
Now say you click on the "First" button, you get redirected to $_SERVER['REQUEST_URI'].'?page=1#rss' so now your URL on the address bar reads http://mypage?page=1#rss
So now what happens when you click on "First" again? The text ?page=1#rss is appended to the already existing request Uri i.e http://mypage?page=1#rss. So the result is? You guessed it
http://mypage/test?page=1#rss&page=1#rss
To avoid this, you need to strip the querystring (the part following the ?) from the request Uri and there exists a wonderful SO answer to help you do just that
So your code should look like
$url=strtok($_SERVER["REQUEST_URI"],'?');
echo '<< < ';
I am trying to share the following link:
https://www.facebook.com/sharer/sharer.php?u=http://www.example.com/test.php/?user=abc&serial=43215
The sharing is ok.But when I am opening the link from facebook, It is not showing the correct link.
Showing like the following link:
http://www.example.com/test.php/?user=abc
and removed these part from the shared link : &serial=43215 .
How can I get the original link like http://www.example.com/test.php/?user=abc&serial=43215?
You can use Facebook Debugger to check your URL and be sure of what is wrong. You should ensure you are setting the correct og tags which are included in your page's header tag. Verify these then you'll be good to go.
Since you are putting one URL as a parameter value into another URL, you must of course properly URL-encode that first URL.
The way you are doing it right now, you are passing two parameters to sharer.php – parameter u with value http://www.example.com/test.php/?user=abc and parameter serial with value 43215.
Since your question includes the tag php, you can simply use urlencode for this:
$shareUrl = 'https://www.facebook.com/sharer/sharer.php?u=' .
urlencode('http://www.example.com/test.php/?user=abc&serial=43215');
I m in a situation where i am redirecting user to another page with following jQuery code
window.location = "/#/customer/email?isEmail=true&eid=1&template=2";
i have some url re-writing , and so complete url becomes is
https://demo.qa.com/#/customer/email?isEmail=true&eid=1&template=2
but in PHP when i try to get full page url using this
echo $_SERVER['REQUEST_URI'];
it just gives me this
/
i just want to get variable IsEmail
$_GET['IsEmail']
value in PHP page,
I think the
#
in between the URL is creating the problem, is there any way to get it, please advise..
The fragment is never sent to the server, so if you want access to the query parameters you need to bring them forward:
https://demo.qa.com/?isEmail=true&eid=1&template=2#/customer/email
^ ^
query fragment
The anchor fragment portion of the URL (anything after #) isn't sent to the server at all. It only lives client-side. The server has no knowledge of it, and therefore PHP has no knowledge of it.
If you want to do anything with the anchor fragment, you must do it client-side.
I want to link links on my website via go.php?urlhere, I have been told and I have tried using go.php?url=urlhere however the URL's to which I redirect, redirect to another URL with-in it for example go.php?http://.com/click?p=0&a=0&url=http://.com, many of the redirect I have tried to use simply copy the URL in the go.php file and use a meta refresh or a window.location reload; however they redirect to the second URL and not the first one. Sometimes when I do actually get it to redirect the first part of the redirected URL gets all the dots changed to "_" which stops it redirecting.
I want to have something like this website using on its "Buy It Now" buttons
http://www.searchchief.co.uk/Search/Sony-PSP-Go
So I think this is what you are asking: How do I redirect to a page using a url as a query string parameter?
eg.
http://www.myurl.com/go.php?url=http%3A%2F%2Fwww.myotherurl.com
You must do two things to achieve this on the url:
have a query string parameter. eg.
go.php?url=mysite.com or
go.php?redirect=mysite.com not
just go.php?mysite.com.
you must URL ENCODE this query
string parameter value. eg. go.php?url=http%3A%2F%2Fwww.myotherurl.com
NOT go.php?url=http://www.myotherurl.com. In php you can use the urlencode() function or http://meyerweb.com/eric/tools/dencoder/ can do it for you if you have a small number of urls to convert.
On the PHP side of things you will use the following
<?php
header('Location: '.urldecode($_GET['url']));
exit();
?>
You can do other basic checks on the php side of things eg. check for a valid url format etc
I think you want to use the header command.
So, in your case you would do this:
For a url in this syntax: go.php?url=thisurl
This would be the code
<?php
header('Location: ' . $_GET['url']);
?>