Proper link is not shared using facebook link sharer - php

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');

Related

How to extract m3u8 from dynamik link?

This is the main link :
When we enter the above link in the browser it will change to :
But this link is dynamic and some parts of above link will change everytime with refresh. I want to extract the m3u8 link after any refresh. The result of extract to be similar this :
Your original link (the static one) is doing a redirect. In order to follow this redirect you have to specify the right option to your crawler.
So if you're using curl for example you should set CURLOPT_FOLLOWLOCATION to true.
Regards
Also note that the format is really simple:
If your original link is formatted:
http://api.hqiptv.net/?{A}/live/0.{B}.m3u8
the redirect will look like:
http://s1.hqiptv.net:8080/live/{timestamp}:{A}/{B}.m3u8?{random string}

URL being re-encoded?

I have a few links that look like this:
https://www.example.com/find?category=food%20%26%20drink
Clicking on the link should take me to a page where I can GET the variable, and it SHOULD read "food & drink".
However, when I click the link, it takes me to this url instead:
https://www.example.com/find?category=food%2520%2526%2520drink
the variable reads: food%20%26%20drink.
If I paste the first url into the search-bar directly, it works fine. But if I click on it as a link, then it gets re-encoded somehow.
Any idea how to get it to read "food & drink" even though it comes from a different page?
many thanks in advance!
Realized the links were written as http instead of https.
Consequently, they were being re-written by the htaccess file to https when clicked, and also being re-encoded at the same time.
The link you have is double encoded. The possible solution to this would be
Find line of code where the link getting encoded again and make suer not encode if encoded already. Couple of examples are given here Click Here
If there is no way you can change the code form where the URL is getting generated, then you have to use urldecode twice to parse the url params
<?php
$query = "https://www.example.com/find?category=food%2520%2526%2520drink";
$param = explode("=", $query);
print_r(urldecode(urldecode($param[1])));
?>
Hope this helps!

external link sends me internally

I am have a form that requests a user to submit a website and then on a different page I send a mysql query to retrieve that website an and turn it into a link by doing this in PHP (V=5.6)
$link = '' . $school_website . '';
the problem is that when i try to click this link, instead of sending me to www.google.com for example, it directs me to www.mydomain.com/www.google.com.
I fixed it originally by using substr to see if the first part was "www" and if it was adding "http://" to it and it worked but now i realize that not all websites will start out with that.
I have tried googling this problem but Im not quite sure how to word the problem so I am not getting anything.
My apologies if this is a duplicate. I did not see anything here that fits my problem, so any help would be greatly appreciated. Thanks.
Could always check if it has http/s:// with regex, if it hasn't then add http:// and the link will work as it should. Or make it ugly but simple.
Simplest way is to remove any protocol and prepend // - that would mark the link as absolute and adopt your current protocol. Even if it didn't have http/s:// it would work as it should.
$school_website = '//' . str_ireplace(['https://', 'http://'], '', $school_website);
Example:
https://google.com becomes //google.com
google.com becomes //google.com
www.google.com becomes //www.google.com
In any of the above cases it would become a absolute url.
A better but longer way would be to validate the url with regex.
Until you add http:// or https://in front of url. It will remain the relative
Like if you re on www.mydomain.com and your href attribute value is www.google.com, The attribute value remain the relative and will target to
you url.
You need http:// or https:// at the beginning of the URL of external links - in fact that should be part of your variable "$school_website", and if that one is for example retrieved from a database, that value has to be changed in the database.

Different redirect with GET parameter

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

Use link url upon click in PHP

I want to use the URL of the link that was clicked in a VB.net program. How can I take the url from my browser url bar and use it in my PHP program?
Example:
VB.net - click link then open using a web browser
url: www.something.com/id=^%$##&var2=13lfhd3f4gt
PHP - put the link in a variable or something so that I can use explode command to get the id and var2 from the URL itself
I need those variables to output a certain value from my database.
This question has the answer that you are looking for, for getting the url in PHP:
Get the full URL in PHP
Though for getting id and var2, it would be simpler to just use the $_GET variable in php. Then you don't have to explode the url and process it. Just change the '/' after 'com' to a ? like:
www.something.com?id=^%$##&var2=13lfhd3f4gt
You can do this using eg. $_SERVER global variable. Please refer to the manual

Categories