Reputation: 584
Using the PHP GD image library I have successfully outputted an image with text from url parameters (a, b, c).
I need to be able to send these images to the Facebook sharing url so that they can be sent to social media.
https://www.facebook.com/sharer/sharer.php?u=http://example.com/script.php?a=1&b=2&c=3
However, the sharing link does not seem to accept my php parameters. When I test the url, it pulls the image but does not send any numbers resulting in no text carried through.
Is there a way to save the complete image with parameters and have it sent to the Facebook sharing url? I am doing this through a link embedded in email, so it cannot use anything more complicated than basic HTML.
Upvotes: 0
Views: 323
Reputation: 584
So I did eventually end up solving this. After giving up on pushing a php image to Facebook with url parameters included, I attempted to place the image into an email. This worked well in nearly every client EXCEPT Gmail. I had to convert the url parameters to get around the Gmail proxy which allowed the image to be displayed AND it also happened to now be usable in the Facebook sharer. Double hooray!
The original way I had it set up was to link the php image with url parameters and use $_GET
to place them on the image:
script-wrong.php
$var1 = $_GET['a'];
$var2 = $_GET['b'];
$var3 = $_GET['c'];
The correct way to do this is the following:
script.php
$uri = $_SERVER['REQUEST_URI'];
$path = substr($uri, strpos($uri, "a=")); // start your url parameters here
$delim = 'abc=&'; // enter all characters you use in parameters (a, b, c, =, &)
$tok = strtok($path, $delim);
$tokens = array();
while ($tok !== false) {
array_push($tokens, $tok);
$tok = strtok($delim);
}
$var1 = $tokens[0];
$var2 = $tokens[1];
$var3 = $tokens[2];
What this does is look at the url and pull specified characters ($delim) from it to place into an array. Then using what follows those characters, set their value to a token and place that token on the image.
Here is how I set up my php image to display in the email:
<img src="http://example.com/script.php/a=1&b=2&c=3">
And my share URL:
https://www.facebook.com/sharer/sharer.php?u=http://example.com/script.php/a=1%26b=2%26c=3
Upvotes: 0
Reputation: 1530
You'll likely need to encode your url such that the ?, = and & aren't read by facebooks php script.
See here for details of encoding.
? is %3F, = is %3D and & is %26
So your url would be :
https://www.facebook.com/sharer/sharer.php?u=http://example.com/script.php%3Fa%3D1%26b%3D2%26c%3D3
Note: I've not tested this as I don't want to post to facebook :)
Upvotes: 2