I'm working on a jquery mobile web app and do a sessioncheck with php on pages I need the user to be logged-in. If not, the user will be redirected to the login.php?r=L29yZGVyLnBocD9kZWFsX2lkPTEwMDM2MjM= (base64_encode($_SERVER['REQUEST_URI']) to login. After the login he has to be redirected to the page he actually requested.
Unfortunately JQM doesn't update the URL, so i can't grab the GET parameter ?r=.... as it is not there. Just a page reload (F5) updates the url.
Here the sessioncheck code which does the redirect if user is not logged-in:
if(!isset($_SESSION["member"]) || (isset($_SESSION["member"]) && (int)$_SESSION["member"]["member_id"]==0)){
unset($_SESSION["member"]);
Header("Location: " . SITE_ROOT . "/login.php?r=".base64_encode($_SERVER['REQUEST_URI']));
exit;
}
What do you guys suggest to tell jQuery mobile that the target has changed.
Of course my redirect happens before the DOCTYPE tag
Cheers
Did you specify a data-url attribute into the page div?
<div data-role="page" data-url="/login" id="login-page">
Related
I'm building a plugin, but somehow when I post a form and redirect back to the page, the page is empty. Content returns after a page reload.
I use the following after the (successful) form submit.
wp_redirect(get_permalink());
exit();
I don't seem to get any errors (I do have WP_DEBUG on).
There can be cache in your browser or web server. You can try generate unique link for reload. For example add to url parameter.
$url = add_query_arg("unique", time(), get_permalink());
wp_redirect($url);
exit();
Iam just using an iframe for login and register.
and i need to reload the page when the message appears that he successfully registered/logged-in.
for example the iframe would be
when he click login in the iframe it reload other page called "login_success" this page send message"successfully logged in".
Now is the proplem i need the browser reload the page so that the session work in the page that loads the Iframe.
Thanks for responding.
You can use following script.
window.parent.location.reload();
Here it is
document.getElementById('ifarme_id').contentWindow.location.reload();
If it is in same domain you can try below
var myframe = document.getElementById('Ifrme_id');
myframe.src = myframe.src;
How can I make "location.reload()" on php file without get perimeter ?
Here is an example..
Let's say I have PHP, and at the right top, I have logout button.
When user press that button, PHP will automatically re-direct to "index.php?logout" and after that, i will logout (unset cookie and other) and return ( javascript location.reload() ) to main page (login page)
Problem that I have is, when php return to login page after logout, then url is still "index.php?logout", so when user login back with "index.php?logout" page, it will automatically logout (because of ?logout perimeter on url)..
So how can I tackle this problem ? Anybody got any idea ?
I hope you all understand what i'm trying to tell you all about..
Thanks for reading this..
use self.location.reload instead of location.reload. Because location.reload reloads the current page. You can simple use
self.location.reload = index.php
Or you can remove query paramter from your url like
var url = 'index.php?logout'
url=url.split("?")[0];
location.reload =url
location.reload() reloads the current page with the post data,you should use window.location.href in case of login/logout
When user press that button, PHP will automatically re-direct to "index.php?logout" and >after that, i will logout (unset cookie and other) and return ( javascript location.reload() >) to main page (login page)
all these can be implemented in server side.
// LOGOUT
if(isset($_GET['logout'])){
//logout code
}
header('location: www.yoursite.com/login') //or whatever the url is
exit;
you re-direct to login page and save page url that request for login that is index.php?logout for re-direct back you must check perimeter logout if exist remove it from return url for example
//replace parent::$Patch with your root url like "http://localhost/myapp/"
if(!parent::$Patch.'admin/login.php'=='http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']){//check if you are in login.php page didn't redirect to login.php
if(!#header('Location:'.parent::$Patch.'admin/login.php?url='.rawurlencode(str_replace("logout","",'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])))){
//if header error echo javaScript code for re-direct
?>
<!DOCTYPE HTML>
<html>
<head>
<script language="javascript">
var LoadP = <?php print "'".parent::$Patch.'admin/login.php?url='.rawurlencode(str_replace("logout","",'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']))."'"?>;
self.location = LoadP;
</script></head></html>
<?php
}
exit();
}
}
this code re-direct user to login page and keep return url of page. if logout exist inside of return url remove it
i hope it can help you
have created a Facebook App,As we know Facebook app have 2 URLs. Page Tab URL and Application URL.In my code if I redirect user to Page Tab URL it gives me FacebookGraphMethod Exception.May be I need to redirect with additional parameters.Anyone who can help with this\
For Example
The Page Tab URL is abc.com/main.php
From main.php I navigate to xyz.php
Now I want to go back to main.php what should I do,I even tried window.location.href
Thanks
you first need to add your App to a page. Then, you can access it on this page by clicking he app icon (or to an URL like this: http://facebook.com/{{page_username}}/app_{{app_id}}).
You can get the page username using this method on FB API:
$profile = $facebook->api('/' . $PageInfo['page']['id'], 'GET');
$page_username = $profile['username'];
To add the app to a page, you can use the add page tab dialog: https://developers.facebook.com/docs/reference/dialogs/add_to_page/
Use top.location.href to redirect to page tab.
<?php
echo "<script type='text/javascript'>top.location.href='".$fbpagetaburl."';</script>";
exit;
?>
i have simple coding problem. i have created a page with textbox and share button. the page also contains one Points up button.
i had a problem with that points up button that when the user click on that button and refresh the page ... a window ask for resend of information
for that i have used following code which works fine.
`header('Location: samepageurl.php');
exit;`
but the problem with above code is when user scroll down page and click the button. the page automatically scrolls up. and user have to manually scroll it down.
what i want is the page should refresh but it should be on the same location where it was.
if the problem is still unclear please refer the following images
You can set a fragment identifier.
eg:
<a name="points_up"></a> <!-- this needs to be near that button, the page will scroll exactly where the element is -->
and redirect him to:
header('Location: samepageurl.php#points_up');
die;
Mihai answer is correct, but as you said that fragment identifier is not working because each user has points up button, you can pass user id as a fragment identifier and make a hidden(display : none;) <a> tag and pass the user id in front of each user...
Like this:
You can set a prefix before a user id too (optional)
<a name="pu12345" style="display: none;"></a>
<?php
header('Location: whatever.php#pu12345');
exit;
?>
You can send the request via ajax instead relying on the normal form submission. That will not affect the scrolling of the current page.
Add this line at the bottom of your page before the the <\body> tag
<button id="PageRefresh">Refresh a Page in jQuery</button>
<script type="text/javascript">
$('#PageRefresh').click(function() {
location.reload();
});
</script>