id like to get the url of an website, which an website is automatically referring to.
For example:
When i browse the link "www.example.de" it refers me automatically to "www.example.de/example123/example.php" (This one id like to get)
Unfortunetaly it is not possible to get the second link but using the first link.
Greeting,
Geigerkind
Try this out:
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
(Sorry haven't got a PHP up to test on)
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 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 want to check redirect to another link from our webpage if user clicking on back from browser I must be alert for user such as 'Backword Forbidden ...'
I'm using this code and that not working for me:
$referer = Request::header('referer');
or how to check witch URL user backword to our site?
If you want to get the Referer URL, you can use either Request::header('referer') or native $_SERVER["HTTP_REFERER"]. But there are (at least) 2 problems with that:
It can be spoofed, empty etc.
It will only work if the person got to your page through a link. It won't work when pressing the browser's back button or backspace.
The function you're looking for is Request::server() which functions just like the $_SERVER super global, so to get the page referer you'd do the following.
$referer = Request::server('HTTP_REFERER');
Using Request::header('refer') will only work for POST requests.
GET requests are the one your're looking for.
You can use Request::segment(1) or Request::segment(2), depends on the exact URL you're using.
Ok so when somebody types this into the URL mywebsite.com/?s1=affiliateid
I want to take the affiliateid part out of the URL. Every affiliate will put a different username into the address.
Then I want to create a link will point to differentwebsite.com/?id=affiliateid based on the username typed into the address bar.
Now so far, I know that I have to have something like this will get that affiliate id
$aff_id = $_GET['s1'];
Then I can use that variable to create a link or just redirect it to the next page
differentwebsite.com/?id=$aff_id
My question is, where do I place this code at? $aff_id = $_GET['s1'];
Do I have to make a page called ?s1.php or something?
Assuming s1 isn't used anywhere else but just to create a link:
<?php
$s1 = isset($_GET['s1']) && !empty($_GET['s1'])
? $_GET['s1'] // it's populated, use the passed value
: ''; // default value in case it's not present
//
// Maybe check $s1 is indeed valid
//
$newurl = sprintf('http://differentwebsite.com/?id=%s', urlencode($_GET['s1']));
?>
Then you can output that link somewhere on the page, like:
New Url Here
urlencode will make sure that if s1 has characters like &, =, ?, / (or others) it won't break the integrity of the url.
If you want the concise approach:
<a href="http://differentwebsite.com/?id=<?= urlencode($_GET['s1']); ?>">
New Url Here
</a>
You could place $aff_id = $_GET['s1'] anywhere before you want to use $aff_id. I tend to put stuff like that at the top of the page.
Or, simply put. "differentwebsite.com/?id=$_GET['id']"
I would suggess you do a check to see if the id parameter exists in the URL before you try to use it. Maybe even make sure it is the data type you expect, integer, string, etc. So as when you redirect users, you don't send them somewhere else in a broken way.
If you are not using this for SQL then no SQL Injection could occur #BlackHatShadow.
Append the $aff_id that you get from mywebsite.com to the url of the new web site. Presumably, $newurl = "differentwebsite.com/?id=".$aff_id.
Edit:
Do I have to make a page called ?s1.php or something?
You need to make a page that the user will land on when they hit the url: www.mywebsite.com/
I assume you are running a web server that can process PHP code. The code can go into a file called index.php in your server's document root directory. If you don't know what this is, I suggest googling a "how to" guide for your specific server.
Get the value of "s1" from the url and store it in $aff_id:
$aff_id = $_GET['s1'];
If you want to pass this variable into another web site which accepts an "id" parameter, then you can simply append $aff_id to the new web URL and redirect the user there.
Redirect the user to differentwebsite.com and also sends the $aff_id from mywebsite.com to the other URL:
header('Location: http://www.differentwebsite.com/?id='.$aff_id);
I'm building a bookmarklet and I need to get the current URL of the webpage the user is on when they activate the bookmarklet.
I tried using
$current_url = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
But that will just get me the URL of the server where the JS for the bookmarklet is hosted. Is there anyway of getting the URL straight from the address bar?
You can resolve the problem by defining your SITE URL (eg: define('SITE_URL', 'http://abc.com')) and concat the site url with $_SERVER['REQUEST_URI']
Eg: $cur_url = SITE_URL.$_SERVER['REQUEST_URI'];
Yes, simply pass location.href form the bookmarklet.
For example;
location.href="http://mywebsite.com/bookie.php?url="+encodeURIComponent(location.href);
Then on your server, you get the URL at $_GET['url']. Good luck.
Of course, that's just JS. You need to add javascript: scheme for it to work.
If by bookmarklet you mean http://en.wikipedia.org/wiki/Bookmarklet than I think this code will help:
javascript:alert(document.location.href);
To test it, select the code and drag it in your bookmark browser bar than click it.