Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-19-2012, 05:33 PM   PM User | #1
mycarhelpline
New to the CF scene

 
Join Date: Sep 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
mycarhelpline is an unknown quantity at this point
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>
mycarhelpline is offline   Reply With Quote
Old 09-19-2012, 07:01 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,748
Thanks: 4
Thanked 2,466 Times in 2,435 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 09-20-2012, 03:30 AM   PM User | #3
mycarhelpline
New to the CF scene

 
Join Date: Sep 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
mycarhelpline is an unknown quantity at this point
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
mycarhelpline is offline   Reply With Quote
Old 09-20-2012, 02:53 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,748
Thanks: 4
Thanked 2,466 Times in 2,435 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
facebook, php, share code

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:18 PM.


Advertisement
Log in to turn off these ads.