Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP variable not getting parsed in share code

    Hi - am looking for a facebook share plugin where user is on,

    have put in following code - bit its leading to opening window - facebook.com/sharer/sharer.php/?u='$sharerpath';

    The php variable is not getting parsed, not able to debug my error
    can someone help pls


    Code


    Code:
    <?php
       $server_name = 'mycarhelpline.com';
       $current_path = $_SERVER['REQUEST_URI'];
       $sharerpath = 'http://www.facebook.com/sharer/sharer.php/?u='.$server_name  .'/'.$current_path;
        ?>
    
       <a onclick="window.open('http://www.facebook.com/sharer/sharer.php/?u='.$sharerpath', 'newWindow', 'width=600, height=400'); return false;" 
       href="http://www.facebook.com/sharer/sharer.php/?u='.$sharerpath''" target="_blank" 
       rel="nofollow"><img src="/templates/mycar_home/images/facebook.png" alt="Share on Facebook" /></a>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Nor will it parse. The link you have here isn't printed by PHP, its directly output as HTML, so php will not parse it. You need to change it to use: /?u=<?= $sharerpath;?>.
    Now, I suggest that you actually use full print: <?php echo $sharerpath;?> instead of short (for now). As of PHP 5.4.0, the short_open_tags directive no longer impacts the short evaluation block. More and more I find that the short_open_tags is disabled due to issues with <?xml, but in the nearish future the <?= will be valid no matter what.

  • #3
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi - Thnx, but still not able to resolve it completely

    i have put in below revised code

    Code:
    <?php
       $server_name = 'mycarhelpline.com';
       $current_path = $_SERVER['REQUEST_URI'];
       $sharerpath = 'http://www.facebook.com/sharer/sharer.php/?u='.$server_name.''.$current_path;
        ?>
    
       <a onclick="window.open(<?php echo $sharerpath;?>, 'newWindow', 'width=600, height=400'); return false;" 
       href="<?php echo $sharerpath;?>" target="_blank" 
       rel="nofollow"><img src="/templates/mycar_home/images/facebook.png" alt="Share on Facebook" /></a>
    Now the page url in address bar been coming in new window is correct
    Code:
    http://www.facebook.com/sharer/sharer.php/?u=mycarhelpline.com/index.php?option=com_forms&view=pages&layout=carloanemicalculator&Itemid=68
    But the facebook window sharing is not displaying it correctly
    Code:
    http://mycarhelpline.com//index.php?option=com_forms
    Its only displaying above url with no description and nothing in the share box
    not yet able to solve this ... thnx - if can help in again to identify the gap

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    This is an invalid path: http://www.facebook.com/sharer/sharer.php/?u=mycarhelpline.com/index.php?option=com_forms&view=pages&layout=carloanemicalculator&Itemid=68
    This has two domain entries and two querystrings. You need to run the $_SERVER['REQUEST_URI'] through a urlencode() before using it. I'd recommend the $server_name part too, so group them first, then urlencode them.
    Javascript is not my thing. Although I would expect that it wants to have that provided url in a string, so wrap that in single quotes.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •