I have a multi -part process
step 1:on page.php I evoke a facebook pop-up authentication window with the URI going to page2.php
https://facebook.com/dialog/oauth?client_id=ID&redirect_uri=http://domain.com/page2.php?-Your+Special+Token+1170-&type=user_agent&fbconnect=1&scope=publish_stream
on page2.php I want to process this token by reading it from the url and storing it as a cookie
<?php
session_start();
if ( empty($tkn) ) { ?>
<script>
(function () {
try {
var q = location.href.split('#');
var a = q[1];
var q2 = a.split('=');
var a2 = q2[1];
var q3 = a2.split('&');
var a3 = q3[0];
setTimeout(function () {
top.location.replace('http://domain.com/cookie.php?tkn=' + a3);
}, 200);
} catch (e) {
top.location.replace('http://domain.com/cookie.php?retry=1&tk=broken_' + encodeURI(e.message));
}
})()
</script><? } else {
print $_GET['tkn'];
}
$_SESSION['tkn'] = $tkn;
$tkn = $_POST["tkn"];
if(isset($tkn)) {
setcookie("tkn", $tkn);
echo "success";
}
?>
page.php detects the cookie and echoes out the token $tkn and reloads the page
<?php
session_start();
?>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
$.post('page2.php',{tkn: tkn}, function(data){
if(data=='success'){
location.reload(true)
}
});
</script>
<?php echo $tkn; ?>
the problem is I cant get any of this to work. The popup goes into an infinite error loop and nothing is refreshed or echoed.
Related
Hello i have this code which works for redirect back
Redirect Users leaving your site - Javascript back button hack
<?php
$javascript = <<<DOC
<script>
var ref = document.referrer;
var siteurl = "YOUR URL HERE";//if you have www, then use www. http://www.yoursite.com
if (ref.indexOf(siteurl)!= -1){
}
else{
(function(window, location) {
history.replaceState(null, document.title, location.pathname+"#!/auth");
history.pushState(null, document.title, location.pathname);
window.addEventListener("popstate", function() {
if(location.hash === "#!/auth") {
history.replaceState(null, document.title, location.pathname);
setTimeout(function(){
location.replace("http://www.blackhatworld.com/");
},0);
}
}, false);
}(window, location));
}
</script>
DOC;
echo $javascript;
?>
I want to add it a counter that will only redirect after 3 clicks on back.
How to do it?
try this javascript code :
<button id="button">Click Back 3 Times </button>
<script>
var counter = 0;
$("#button").click(function () {
counter++;
if (counter == 3) {
window.history.back();
}
});
</script>
This code also works but i need to add the counter
this code which works for redirect back Redirect Users leaving your site - Javascript back button hack:
<script>
// managage back button click (and backspace)
var count = 0; // needed for safari
window.onload = function () {
if (typeof history.pushState === "function") {
history.pushState("back", null, null);
window.onpopstate = function () {
history.pushState('back', null, null);
if(count == 1){window.location = 'http://google.co.il';}
};
}
}
setTimeout(function(){count = 1;},200);
</script>
Looking for a code to make redirect to page after clicking browser back button on the 3rd time... first 2 clicks should remain at the page
I have function validate my form and after form submitted
else
{
$('.submit-button').val('Wait please...');
$('.submit-button').attr('disabled', 'disabled');
return true;
}
PHP redirect to main page
function wpcallback_get_target() {
global $wpcallback_plugin_option;
if($value = $callback_plugin_option['target'])
return get_permalink($value);
return get_site_url();
}
PHP get site url then how I can make thanks modal window opened?
I tried with .modal but can't find right place for it.
$('#myModal').modal('show');
place $('#myModal').modal('show'); in the bottom of you view file or you can add following code in head tag
$(document).ready(function(){
$('#myModal').modal('show');
});
to prevent model every time on page load, update your PHP file:
function wpcallback_get_target() {
global $wpcallback_plugin_option;
if($value = $callback_plugin_option['target'])
return get_permalink($value);
$url = get_site_url();
return $url."?response=true";
}
in view file:
<?php if(isset($_GET['response']) && $_GET['response'] == 'true'){ ?>
$(document).ready(function(){
$('#myModal').modal('show');
});
<?php } ?>
use Javascript code:
$(document).ready(function(){
var myURL = window.location;
var res = myURL.search("response=true");
if(res > 0){
$('#myModal').modal('show');
}
});
Try this on your php.
echo "<script>
$(window).load(function(){
$('#yourthanksmodel').modal('show');
});
</script>";
In the header ( header.phtml ) I start the session :
<?php
if (session_status() == PHP_SESSION_NONE)
session_start();
?>
<!DOCTYPE html>
<html>
<head>
...
Now in other page I want to set a session value :
<script type="text/javascript">
$(document).ready(function() {
$("#add_reservS").on("click", function(e) {
<?php
$_SESSION['nb_ajout_client'] = 0;
?>
});
...
Then I increment this session value in other page :
public function ajouterExecAction($src = '', $pk_src = ''){
$client = new Client();
$client->ajouter($_POST);
if ($src == '')
$this->response->redirect('ReferentielClient');
else {
$_SESSION['nb_ajout_client']++;
...
}
...
}
Now inside another page I want to get this session value :
<script type="text/javascript">
$(document).ready(function() {
$("#btn_retour").on("click", function() {
var back = "<?php echo $previous; ?>";
if (back == "list_reserv")
window.history.back();
else {
var nb_back = "<?php echo $_SESSION['nb_ajout_client']; ?>";
alert("session nb ajout client = "+nb_back); // nb_back is blank !
}
});
});
</script>
The alert show a blank value ! So what is wrong in my approach ?
You must start each document with session_start();. While it is no longer required to be the very first line, it does need to be present before you do anything with a session in the file.
It is common to start the session from a common include file which is then included in every page which needs the session. Thus you only need to write it once.
I have a dynamic login header. 2 links, login / register and profile / logout.
I have a php class function that was being used to check if logged in and displaying relevant links, it worked fine.
I then moved to an ajax login as I didn't want a page refresh and the login box drops down and rolls back up. Again, it works fine.
I've noticed a slight issue, by slight I mean very irritating :)
Once logged in, Every single page refresh on new page shows a flicker where 'profile' becomes 'login' and then flickers back again. It only happens when the page is loading and doesn't last long but it's not very nice.
Could someone help me solve it please? I'm pretty new to Ajax/jQuery and spent ages wiht the help of some guys in here getting the ajax/jquery part functional in the first place.
this is script that toggles the login divs
<script>
window.onload = function(){
$(function() {
var loggedIn = <?php echo json_encode($general->loggedIn()); ?>;
$("#loggedIn").toggle(loggedIn);
$("#loggedOut").toggle(!loggedIn);
});
}
</script>
Thanks
EDIT: Ajax
function validLogin(){
$('#error').hide();
var username = $('#username').val();
var password = $('#password').val();
if(username == ""){
$('input#username').focus();
return false;
}
if(password == ""){
$('input#password').focus();
return false;
}
var params = {username: username, password: password};
var url = "../loginProcessAjax.php";
$("#statusLogin").show();
$.ajax({
type: 'POST',
url: url,
data: params,
dataType: 'json',
beforeSend: function() {
document.getElementById("statusLogin").innerHTML= '<img src="../images/loginLoading.gif" /> checking...' ;
},
success: function(data) {
$("#statusLogin").hide();
if(data.success == true){
$('#loggedIn').show();
$('#loginContent').slideToggle();
$('#loggedOut').hide();
}else{
// alert("data.message... " + data.message);//undefined
$("#error").show().html(data.message);
}
},
error: function( error ) {
console.log(error);
}
});
}
Use PHP to hide the unwanted element by doing the following
<?php
$loggedIn = $general->loggedIn();
?>
... Some HTML
<div>
<div id="loggedIn" <?php echo ( $loggedIn ? '' : 'style="display: none;"' ); ?>>
.... Logged in stuff
</div>
<div id="loggedOut" <?php echo ( !$loggedIn ? '' : 'style="display: none;"' ); ?>>
.... Logged Out Stuff
</div>
</div>
<script>
var loggedIn = <?php echo json_encode($loggedIn); ?>;
$('#loginForm').submit(function() {
... Handle form submit
... When ajax returns true or false we can set loggedIn and then toggle the containers
});
</script>
// CSS-Stylesheet
#loggedIn,
#loggedOut {display: none}
<script>
$(document).ready(function() {
var loggedIn = <?php echo json_encode($general->loggedIn()); ?>;
if (loggedIn == true) { // i can just guess here...
$("#loggedIn").show();
}
else {
$("#loggedOut").show();
}
});
</script>
Three possible solutions:
If the script element is placed inside the body, move
it to head element.
Use the following script instead:
$(document).ready(function () {
'use strict';
var loggedIn = <?php echo json_encode($general->loggedIn()); ?>;
$('#loggedIn').toggle(loggedIn);
$('#loggedOut').toggle(!loggedIn);
});
Hide both links in the "logged in" div using $('#loggedIn
a).hide(); and then, show them on the window.onload event using
$('#loggedIn a).show();. A bit dirty, bit it may work.
I have an index.php that updates every second user sessions:
[Index.php (before )]
<script type="text/javascript">
$(function($) {
var refresh = setInterval(function() {
$.post('myfolder/reload_info.post.php', {
id: <?php echo $_SESSION['id']; ?>
}, function(data){
clearInterval(this);
});
}, 1000);
});
</script>
[reload_info.post.php]
(sql query... // $row is the result)
$_SESSION['name'] = $row->name;
$_SESSION['mail'] = $row->mail;
$_SESSION['status'] = $row->stat;
$_SESSION['cf'] = $row->cf;
All functions of the site using any session are usually charged if there is any change in the database (MySQL). What I would like is to update the body of index.php () without reloading the page.
That is, if I open the index.php file and have nothing between the and editing the file I put any text after this a second, carrying the text without having to press F5 or take a location.reload ().
Is it possible? Thank you. :)
Perhaps you are after something like joconut: https://github.com/vdemedes/joconut
you want something like this?
<script type="text/javascript">
$(function($) {
var id="<?php echo $_SESSION['id']; ?>";
var refresh = setInterval(function() {
$.post('myfolder/reload_info.post.php', {
id: id;
}, function(data){
clearInterval(this);
$('body .container').html(data);
});
}, 1000);
});
</script>
in reload_info.post.php you should return something...
echo echo $_SESSION['id'];