How do I get the link from a page and assign it to a variable in PHP?

1

I'm trying to use the Facebook plugins on comment, but I do not want to have to change the code on each page just because of the link. Can you do a function that takes the link automatically and assigns a variable to put this variable in data-href in the code below?

<div class="fb-comments" data-href="http://developers.facebook.com/docs/plugins/comments/" data-numposts="5" data-colorscheme="light"></div>
    
asked by anonymous 14.04.2015 / 19:23

2 answers

1

In summary ...

<div class="fb-comments" data-href="<?= "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ?>" data-numposts="5" data-colorscheme="light"></div>

This way you will be putting in the date-href the address of the current page, but be careful, this practice is not very safe since HTTP_HOST can be changed.

    
14.04.2015 / 20:39
-1

I think this will leave a bar missing, the right would not be:

<div class="fb-comments" data-href="<?= "http://$_SERVER[HTTP_HOST]"."/"."$_SERVER[REQUEST_URI]" ?>" data-numposts="5" data-colorscheme="light"></div>
    
14.04.2015 / 21:03