Jquery over facebook , twitter , google plus iframe? - php

I want to run/execute jquery code on facebook, twitter, google plus iframe.
I have tried to do it in many ways but it is not working.
Code is always showing error none/object not found.
Actually I want to know whether currently logged-in user has already done like/follow/+ .
If the current logged-in user has already done like/follow then I need to hide like/follow links,

If you are using the PHP Facebook SDK you can query it as follows:
$likes = $facebook->api('me/likes');
$fanpageliked = false;
$appliked = false;
foreach ($likes['data'] as $ilike) {
if ($ilike['id'] == $fanpageid) {$fanpageliked = true;}
if ($ilike['id'] == $appid) {$appliked = true; }
}
If your fanpage id is stored in $fanpageid, or app id in $appid, then $fanpageliked will be true (and/or appid).
So if you are only looking for a fanpage id, remove the appid if and add a break:
if ($ilike['id'] == $fanpageid) {
$fanpageliked = true;
break;
}
After that, you can have the following:
if (!$fanpageliked) {
echo "Like us NOW!";
// .... display like button etc
}
else {
echo "You are ours now. Bwa ha ha!";
}

You can't do that with jquery but you can use their own APIs to accomplish what you need. Facebook for example already has all that in their API.

Related

Insert php snippet after checking correct password

I have a Wordpress page where a user can book language classes. There are different booking options, so I built the page in a way that the booking form charges dinamically from URL. The DOM charges 16 different shortcodes but in front-end it's only displayed the one that user enters in the URL by setting some parameters. The only problem about this is that the page takes a lot of time to charge and display the form.
I'm trying to figure out a way to charge only one shortcode and only set dinamically the value that differs between all shortcodes. After some researching (as my PHP knowledge is limited), I tried this code, and it worked:
function php_insert() {
if( is_page( 645 ) ) {
$awQueryString = $_SERVER['QUERY_STRING'];
parse_str($awQueryString, $awQueryStringParams);
$language = $awQueryStringParams['lang'];
$pack = $awQueryStringParams['pack'];
if (empty($awQueryString)) {
echo 'The URL entered is invalid. Please refresh the page with the correct URL or contact the web admin.';
}
else if ($language == 'english') {
if ($pack == '5') {
echo do_shortcode('[ameliacatalog package=13]');
}
if ($pack == '10') {
echo do_shortcode('[ameliacatalog package=14]');
}
if ($pack == '25') {
echo do_shortcode('[ameliacatalog package=15]');
}
}
}
}
add_action('wp_enqueue_scripts', 'php_insert');
The problem now is that this page is protected by password, and this snippet charges the code at the top of the page and it doesn't wait to check that the password is correct.
I don't know if this is the best way to do this workaround. Also don't know how can I do to solve the password check and location problem.
I hope I have explained everything well.
Thanks

Prevent user from entering page again after logout

I've created this code so that the user will not redirect onto the next page again. I set the maximum value on votenow button to 1 and once the user click the button again the value on the votenow button will not be added anymore since its maximum is 1. Everything works fine except that the user can still access the nextpage though the maximum value on the button was reached. Here's the code.
<?php
$errors = array();
$db = mysqli_connect("localhost","root","","registration");
if(isset($_POST['votenow']))
{
$votenow ="0";
$votenow1="1";
if($votenow != $votenow1){
$votenow = "update users set votenow = votenow + 1 WHERE votenow=0 LIMIT 1 ";
$run_vote = mysqli_query($db,$votenow);
echo '<script type="text/javascript">alert("hello!");</script>';
header ("Refresh:2; url=renewsys3.php");
}
else{
echo '<script type="text/javascript">alert("oh not again!");</script>';
header ("Refresh:2; url=renewsys2re.php");
}
}
?>
Can you guys help me or is there any other way so that the user will not enter the next page again? Btw, this is a voting system
The best way to use session:
$_SESSION['votenow'] = 0;
if (isset($_SESSION['votenow'])) {
if (!$_SESSION['votenow']) {
//do something
} else { // means $_SESSION['votenow'] == 1
// do something else
}
}
Redirect the URL to a different page (maybe homepage or any page) If the maximum vote is reached.
Let that code run before any other code so that the page won't load of the condition is true. It'll redirect immediately.

Change Text in id/class based on the page they redirected from in php

i wan to change the text in a DIV based on the page they redirected from..
is there any if condition for this... or any code which helps me to do this... searched all the internet.. but didn't find it :(
if users reducers from google.com i want to show hello googler! if he came from my friends site, hello xxx reader. (Xxx = my friends blog name). if he is a direct visitor, hello visitor. like this....
hope you guys can help me! Thanks!!
UPDATE
in other question in stackoverflow, i found this ode (ASP.NET) i need a similar one in php.
in this ASP code he writes ENDS WITH(" ") but i want to write the FULL url there.
protected void Page_Load(object sender, EventArgs e)
{
string requestUrl = "";
. . .
if (requestUrl.ToString().EndsWith("Page1.aspx"))
label.Text = "foo";
else
label.Text = "bar";
}
Thank you!
$_SERVER['HTTP_REFERER'] will do exactly what you need.
if (strstr($_SERVER['HTTP_REFERER'], 'facebook.com') !== false) {
// Facebook brought me to this page.
}
else if (strstr($_SERVER['HTTP_REFERER'], 'google.com') !== false ) {
// Google brought me to this page.
}
EDIT
else if (strstr($_SERVER['HTTP_REFERER'], 'xxx.blogspot.com') !== false ) {
// Your friend brought me to this page.
}

Issue with Facebook API / Timeline

Ever since Timeline was added to Facebook the photos have been showing up on my website. This isn't ideal because there are a lot of duplicates and also the latest gallery doesn't show up because the timeline takes first position.
Here is my code. I am hoping there is some type of "if" command I can give to keep the gallery timeline from showing up.
$show=1;
if($show)
{
if(!$_GET[hash])
$la = getLastFacebookAlbum();
else $la = getFacebookAlbum($_GET[hash]);
if(!$_GET[image]) { $image=getFacebookAlbumFirst($la[aid]); $iid=getFacebookAlbumFirstId($la[aid]); $current=1; } else {$image=getFacebookSkippedImage($la[aid],$_GET[image]); $iid=getFacebookSkippedImageId($la[aid],$_GET[image]); $current=$_GET[image]+1;}
$total = getFacebookAlbumCount($la[aid]);
$ownlink=urlencode($server."photos.php?hash=".$la[aid]);
$info=#getimagesize($image);
if(!$info[0]) $info[0]=2;
if($info[0]>$info[1]) $isze='width="471" height="331"'; else {
$koef=ceil($info[1]/$info[0]);
$expected_width=ceil(331/$koef);
$margin=(471/2)-(ceil($expected_width/2))-10;
$isze='height="331" style="margin-left:'.$margin.'px;"';
}
}

click link and echo statement on next page?

Hi i'm trying to think of a way that if a user clicks a certain link it takes them to a new page where only if the user has come from that parent link it will echo a statement on the newly opened page?
Is this possible and if so does anyone know how i could do it? Thanks
I don't know if I understood your question correctly but give this a try...
HTTP_REFERER could help you do this but it isn't really reliable.
<?php
$referer = $_SERVER['HTTP_REFERER'];
$referer_parse = parse_url($referer);
if($referer_parse['host'] == "yoursite.com" || $referer_parse['host'] == "www.yoursite.com")
{
//from expected page
//echo here
} else {
//not from expected page
//do something else
}
?>
NOTE
This is a sample code showing the logic, you'll still need to modify this to fit your needs.
INFO
I would suggest trying to find a way/logic to implement it with the use of secret/session keys.
Good luck,
Madz
If I understood the question correctly
Link 1
Link 2
Link 3
Then in abc.php
$link = $_GET['link']; // Don't forget to sanitize the data
if($link == 1)
{
// user clicked Link 1
}
else if($link == 2)
{
// user clicked Link 2
}
else if($link == 3)
{
// user clicked Link 3
}
else
{
// came from somewhere else; i.e. did not click the links
}

Categories