facebook like button (current page)

Discussion in 'PHP' started by MyVodaFone, Jun 7, 2010.

  1. #1
    I'm looking for a php or other language script that can get the current page link (address bar)which could be inserted into the facebook LIKE code :

    <iframe src="http://www.facebook.com/plugins/like.php?href=[B][COLOR="Red"]http://example.com[/COLOR][/B]%2Fpage%2Fto%2Flike&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe> 
    Code (markup):
    Because its an iframe, I'm lost on how to do this ?

    EDIT:

    I found it:
    <iframe src="http://www.facebook.com/widgets/like.php?href=<?= "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; ?>" scrolling="no" frameborder="0" style="border:none; width: 450px; height: 80px;"></iframe>
    
    PHP:
    Well the above does get the full url, however facebook will only store the domain_name and the ?first=variable
     
    Last edited: Jun 7, 2010
    MyVodaFone, Jun 7, 2010 IP
  2. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    urlencode() the request uri.
     
    krsix, Jun 8, 2010 IP
  3. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #3
    I understand what your saying, but the js code on facebook rewrites the url so it doesn't matter what way you send it in, ie: view the iframe source code here on dp's facebook like button

    My solution was to write a .htaccess redirect
     
    MyVodaFone, Jun 8, 2010 IP
  4. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if your url has an & in it, it will be processed as another variable instead of part of the URL iirc, that's why I said urlencode
     
    krsix, Jun 8, 2010 IP
  5. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #5
    The snippet to get the URL is
    
    <?php
    $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    echo $url;
    ?>
    
    PHP:
     
    roopajyothi, Jun 8, 2010 IP
  6. andalusy

    andalusy Member

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    i doesn't work with me
     
    andalusy, Jul 2, 2010 IP
  7. K1llswitch

    K1llswitch Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #7
    <iframe src="http://www.facebook.com/widgets/like.php?href=<?=urlencode("http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']); ?>" scrolling="no" frameborder="0" style="border:none; width: 450px; height: 80px;"></iframe>
    PHP:
     
    K1llswitch, Jul 2, 2010 IP
  8. sudip03

    sudip03 Peon

    Messages:
    155
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    this is the exactly what you are looking about. i have tested this and it worked well. Thanks @K1llswitch
     
    sudip03, Jul 2, 2010 IP
  9. K1llswitch

    K1llswitch Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #9
    No problamo.
     
    K1llswitch, Jul 3, 2010 IP
  10. afzaal.alkurn

    afzaal.alkurn Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hi K1llswitch,
    I need a standard size button not the ( width: 450px; height: 80px; ). It will be a standard size with like count 1, 2, 3, 4.... Kindly suggest..
    Thanks
     
    afzaal.alkurn, May 3, 2012 IP
  11. infotripro

    infotripro Member

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    43
    #11
    like button uses the id of the facebook page. For G+ you can +1'd any page, on facebook you can like only the facebook page
     
    infotripro, May 3, 2012 IP
  12. BloodyShinji

    BloodyShinji Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    This is not working for me, I can see that the page extended so the code is red, but no button appear.
     
    BloodyShinji, Sep 24, 2012 IP