I have a tracking link (poly.wtf) .
I'm trying to make a php page that check the referred if and to make this condition if the visitor came from my tracking link (poly.wtf) it will redirect him to page X
if the visitor didn't come from my tracking link (anywhere else) or just type the url through the browser it will redirect him to page Y
I'm tried to use this script PHP :
<?php
$domain = 'poly.wtf';
$referrer = $_SERVER['HTTP_REFERER'];
if (preg_match($domain ,$referrer)) {
header('Location: https://www.google.com/');
} else {
header('Location: https://www.yahoo.com/');
};
?>
but it doesn't work because for some reason it doesn't capture for me the refer here is example of redirect from poly.wtf link to the PHP page :
http://poly.wtf/5d9e31ce-bd7d-4500-bc4e-b7e7f7ddcacc
^^ in this case it should redirect me to google but it doesn't , what do you think is the problem?
You shoul enclose your pattern in some delimiter like:
$domain = '/poly.wtf/';
Related
I need a code to display referrer URL (full URL if possible, like example.com/1234). if full URL is not possible, then at least the domain is fine. Also, I want to see if the referrer is NOT coming from somewhere for example: if referer is NOT example2.com then //do action
I have a code but it's not working properly. If you can help, that would be great. Thanks
<?php
// Check if Referral URL exists
if (isset($_SERVER['HTTP_REFERER'])) {
// Store Referral URL in a variable
$refURL = $_SERVER['HTTP_REFERER'];
// Display the Referral URL on web page
echo $refURL;
} else {
if (( $refURL == !'https://example2.com' ) ) {
// sorry, you didnt come from example2.com, you NEED to come from example2.com}
?>
This doesnt seem to work. Also, http refer only displays domain of referrer without path like example.com/1234/321. If its possible to get the full URL please share, otherwise i can do without it.
Let say I have redirect rule on url example.com which redirect to newurl.net.
How can I get original url on newurl.net in order to be used and handled with some details or just to be printed on new destination.
Thank anyone for help.
If it's not external You can use
$_SERVER['HTTP_REFERER']
And it will give you the referer which is what you want.
See Acquiring referral after a PHP redirect for more informations.
But if you are trying to get to another website, the browser will overwrite the headers so you need to do it some other way.
You can store it in session.
//Save it in your first website
$_SESSION['REFERER'] = $_SERVER['HTTP_REFERER'];
And then in the other website :
//Use it in the other
$referer = '';
if (isset($_SESSION['REFERER'])) {
$referer = $_SESSION['REFERER'];
unset($_SESSION['REFERER']);
}
You could also pass the referer as a parameter:
header('Location: http://newurl.net?original_referer=' .$_SERVER['HTTP_REFERER']);
I want to make my web site so that it can only be accessed from visitors that accessed via a short link, and block them when they access my web by entering the address.
how can i do it on .htaccess?
In php you can check for the previous URL by using $_SERVER['HTTP_REFERER'].
So you can compare the previous url with $_SERVER['HTTP_REFERER'] to verify the visit.
if ($_SERVER['HTTP_REFERER'] == 'your-short-url') {
//redirect to home page
} else {
//display page not found;
}
Store shortlink addresses in the DB and then validate them on server site. The second approach is to check if the domain is comming from your shortlink provider, f.i. bit.ly
$_SERVER[HTTP_HOST] == 'bit.ly';
To check current address in php:
$actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
current browser URL using JavaScript:
window.location.href
This will return you the string with URL you currently see in your browser.
If you choose DB use approach compare each element in database with your current url and display website only if they are matching, coming from the same domain or any condition you want.
Let say we've the following
Objective : User will post certain exact URL $refere to lock viewing text content and only be allowed for view if the viwer is coming from the same exact URL $refere.
$refere = "http://www.site_site.com"; // User will post it
$r = $_SERVER['HTTP_REFERER']; // To get real referral
and i want to do the following
<?PHP
if(stripos($r, $refere) == false){
echo "Wrong";
} else { ?>
echo "Go";
}
?>
It always gives me $r = $_SERVER['HTTP_REFERER']; blank ! so does it deprecated on any PHP version 4 or 5 whatever !
Also
what is the user posted $refere like https:// or missed www. or only posted site_site.com while the $r = $_SERVER['HTTP_REFERER']; showing www.site_site.com
so can anyone help me to adjust this code to be working fine no matter the user posted the $refere link fully or only site_site.com.
The $_SERVER['REFERER'] variable will only be set when you click a link to your page from another page and if the browser (or an eventual proxy or firewall you're on) isn't removing the referer header.
To your second question: do some string comparisons. The functions strpos() and substr() will be of great help.
I have created one application for my portfolio.
Let's say the URL is http://fb.domain.com/about/ and my FB app is http://apps.facebook.com/myap/about/.
A user can access http://fb.domain.com/about/ directly from my site.
If the user types http://fb.domain.com/about/ or clicks http://fb.domain.com/about/, how do I redirect them to http://apps.facebook.com/myapp/about/
Here's an example from http://www.oodle.com.
If you go to this link, you will be redirected to here.
How is that done? Let me know. I currently use php for my site.
You can use ModRewrite in your .htaccess to redirect based on the rules set, which is probably the cleanest solution without involving hardcoding redirects in your code.
Something like this should work.
// Define current URL
$host = $_SERVER['HTTP_HOST'];
$self = $_SERVER['PHP_SELF'];
$query = !empty($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null;
$url = !empty($query) ? "http://$host$self?$query" : "http://$host$self";
// If current URL is not Facebook's, redirect to Facebook
if($url == 'http://fb.domain.com/about/'){
header("Location: http://apps.facebook.com/myapp/about/");
exit();
}
Assuming all you need is the simple redirect, no page loading, then this should do it...
header("Location: http://apps.facebook.com/myapp/about/");
exit();