how to send facebook button current href - php

<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo 'http://domainame.com/'.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];?>&layout=button_count&show_faces=false&width=120&action=recommend&font=verdana&colorscheme=light&height=21"
scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:120px; height:21px;" allowTransparency="true"></iframe>
But if i'm on http://domainame.com/?bla it prints http://domainame.com//index.php?bla
if i could just send this.href but i don't know how to insert js in-line here,
help?
With your help we got working:
<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo str_replace("index.php","",'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']); ?>&layout=button_count&show_faces=true&width=150&action=recommend&font&colorscheme=light&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:120px; height:21px;" allowTransparency="true"></iframe>
can get better?

Try using the following as a value for href:
<?php echo rawurlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>

Try this: <?php echo rawurlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>
(BTW, you should never use $_SERVER['PHP_SELF'] for anything of this sort, due to injection vulnerabilities. Read this for details.)

I image that the page is named index.php and your server sets index.php as the default page, which would mean http://domainame.com//index.php?bla is interchangeable as a page reference to http://domainame.com/?bla.

Related

PHP Coding making different Iframe codes appear

Hello so I have this code here <iframe frameborder="0" height="550" marginheight="0" marginwidth="0" scrolling="auto" src="http://example.com/signup.php" width="1000"></iframe> now I was wondering is there any way to make a php script that can choose a random iframe code and display the php script on the page for example
<iframe frameborder="0" height="550" marginheight="0" marginwidth="0" scrolling="auto" src="website1.com/signup.php" width="1000"></iframe>
<iframe frameborder="0" height="550" marginheight="0" marginwidth="0" scrolling="auto" src="website2.com/signup.php" width="1000"></iframe>
like in website 1 and 2 but have it so each time a person loads that page it switches from site 1 to site 2 and embeds the php or is that n
You could simplify this easily. Try adding the sites to an array like this:
$sites = array(
'site1.com',
'site2.com',
'site3.com',
'site4.com',
'site5.com',
'site6.com',
'site7.com'
);
Now you can use features like array_rand() to pick a random entry from the site to show in your <iframe>:
<?php
$site_to_use = array_rand($sites);
?>
<iframe frameborder="0" height="550" marginheight="0" marginwidth="0" scrolling="auto" src="<?php echo $sites[$site_to_use]; ?>/signup.php" width="1000"></iframe>
Or you could even use rand() like this:
<iframe frameborder="0" height="550" marginheight="0" marginwidth="0" scrolling="auto" src="<?php echo $sites[rand(0, (count($sites - 1)))]; ?>/signup.php" width="1000"></iframe>
That avoids the hassles of large if else or switch casestatements.
Example

Embedd HTML code from PHP variable

After more than 3 hours searching in google, I found that ppl do the other way around of what I am doing but anyway, here is what I want to do:
I have a variable $location which contains an HTML code (embedded google map code) i.e.
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0"
marginwidth="0" src="https://www.google.com/maps/ms?........in a larger
map></iframe>
now in a php code, how can i get the map to be displayed?
the following outputs the HTML code as text
<?php echo $loation; ?>
Thanks!
You spelled your variable name wrong $loation; - should be $location;. Assuming you set your variable correctly like
$location = '...';
OR using heredoc syntax:
$location = <<<STR
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0"
marginwidth="0" src="https://www.google.com/maps/ms?........in a larger
map></iframe>
STR;
you should be fine.

iframe navigation using parameter

I have a page called 'mas.php' where i retrieve values from database. An IFrame is present in mas.php page. It is defined as follows:
<iframe width="523" height="234" scrolling="No"
width="500" height="145" src="mail-to.php" frameborder="0"
name="myframe" ></iframe>
Now from mail-to.php page I have to navigate to mail.php for mailing.
The sequence is:
(mas.php-->mail-to.php[iframe]--->mail.php)......
here while using the iframe in 'mas.php' page can i navigate to 'mail-to.php' by defining id in iframe?
<iframe width="523" height="234" scrolling="No"
width="500" height="145" src="mail-to.php?id=<?php echo $row['id'];?>"
frameborder="0" name="myframe" ></iframe>

PHP: Twitter button doesn't show text + link

This is generated Twitter button, I added text inside.
> <iframe allowtransparency="true" frameborder="0" scrolling="no"
> src="http://platform.twitter.com/widgets/tweet_button.1357735024.html#_=1357817606773&count=horizontal&id=twitter-widget-0&lang=en&original_referer=&size=m&text=<?php
> echo $art["title"].'
> http://web.com/article.php?art_id='.$art["id"];?>&url=<?php
> echo
> 'http://web.com/article.php?art_id='.$art[id];?>&via=MyWeb"
> class="twitter-share-button twitter-count-horizontal" style="width:
> 107px; height: 20px;" title="Twitter Tweet Button"
> data-twttr-rendered="true"></iframe>
The problem is, that I cannot add a link into the tweet. When I add it there, there is not displayed even the simple text.
Has anyone similar issue or any help, how to fix it?
Thank you
I would reorganize your code a bit just to make the building of the iframe src easier to follow (there may be a mistake there). You should also make sure that the $art['title'] is urlencoded.
<?php
$iframe_src = 'http://platform.twitter.com/widgets/tweet_button.1357735024.html#_=1357817606773&count=horizontal&id=twitter-widget-0&lang=en&original_referer=&size=m&text=';
$iframe_src .= urlencode($art['title']);
$iframe_src .= 'http://web.com/article.php?art_id='.$art['id'];
$iframe_src .= '&url=http://web.com/article.php?art_id='.$art['id'].'&via=MyWeb';
?>
<iframe allowtransparency="true" frameborder="0" scrolling="no" src="<?php echo $iframe_src; ?>"
class="twitter-share-button twitter-count-horizontal"
style="width:107px; height: 20px;" title="Twitter Tweet Button"
data-twttr-rendered="true"></iframe>

Php facebook like button

I'm creating a dynamic site with php/mysql. There are few article. So i want to show a facebook like button for every article. How do i do this.
article show with php:
echo "<h2><a href='readmore.php?post_id= ". $id ."'>$sub</a></h2>";
Anyone can help me.
Add following code for each your article, and like button will show on each article:
<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo "http://www.yousite.com/$yourArticleUrlHere"; ?>&layout=standard&show_faces=false&width=450&action=like&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px;"></iframe>
Hope it helps
echo '<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>';
Don't forget to include Facebook JavaScript SDK in the beginning, after opening body tag: http://developers.facebook.com/docs/reference/plugins/like/
I hope this code will help:
<?php
// Facebook Like button HTML 5 syntax
echo '<div class="fb-like" data-href="http://www.yourwebsite.com/readmore.php?post_id='.$id.'" data-send="true" data-width="450" data-show-faces="true"></div>';
// Facebook Like button XFBML syntax
echo '<fb:like href="http://www.yourwebsite.com/readmore.php?post_id='.$id.'" send="true" width="450" show_faces="true"></fb:like>';
?>

Categories