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
Related
<?php
session_start();
if(isset($_SESSION['login_user'])) {
require_once('logged.html');
} else {
require_once('notlogged.html');
}
?>
This code works fine when I login directly from the login page, but when I start from the homepage, then a href to the login page, login, it still shows the notlogged.html.
But when I start from the login page, I can login and get to logged.html, go to the signout page and destroy my session, which lands me to the notlogged.html, then login again to the logged.html.
So basically, it works perfectly when I enter from login.php, but not when I enter from index.php. Any idea why this might be?
question isn't clear, 1st of all check whether session created while login from any page, its simple after creating session variable, make alert using JS
alert("$_SESSION['login_user']");
I've got a registration page and a landing page, when the register button is pressed it activates a JS function in an external JS file (reg.js) that then runs reg.php, like so:
reg.html->reg.js->reg.php
If the registration succeeds it is supposed to redirect to a landing page (landing.php) but instead it is just appending the landing page to the bottom of the current page(reg.html), like so:
Register
[register button]
Landing
[landing page text]
The redirection code is:
header('Location: landing.php');
From the sounds of it, you're posting via AJAX to a php script to process. PHP would then need to send some sort of success response back to the AJAX—something like:
if (registered) {
header(201); // http response code for "created"
}
The AJAX callback would see that success, and then you would redirect the user client-side:
$.post().success(function() { window.location = '/landing.php'; });
Are you using javascript ajax ? If yes then you need to use
window.location = 'http://webiste.com';
If your javascript submits the form then you need to use header in PHP code like this:
header( 'Location: http://website.com/landing.php' ) ;
Don't forget to add http:// in the redirect url as this may be causing an issue.
<?php
if(registered)
{
header( 'Location: /landing.php' ) ;
}
?>
or try to input the whole url.
Im trying to redirect an user of my page when I ban him from my chat box using this (php):
header("location: index.php");
exit;
The problem is the index.php page is opening inside the connected users section, in this case inside a div. How can i redirect the user's main page ?
Thanks for your time.
Try this in the javascript code:
window.top.location.href = "http://www.site.com";
This is the answer using javascript:
window.parent.location = "http://www.example.com/index.php";
so here i am with "maybe another stupid question"
so here i want to ask how to redirect to previous page if the case is somehow like this:
i have view:
a. home_view b. about_view c. contact_view
then i have login view that (now currently after i login it'll redirect me into the home_view)
I want if i access login_view from about_view then the redirect function will redirect me to about_view, or if i access login_view from contact_view then the redirect function will redirect me to contact_view and so on. How to make redirect function to the previous page(not a single page) ? Maybe some tricks using php? or codeigniter itself?
It's simple when you have login and you go to login_view just set default redirect to about_view or contact_view when had login.
But if you want to redirect to previous page you have to trick with session must set session ex : $SESSION['last_view'] = $yourlastview;. $yourlastview can be set when you in about_view or contact_view or another view and when you go to login_view just check that $SESSION['last_view'] and redirect to that view.
Regard's
Jefri
You can use query string to solve this problem.
Like when you call login script from about us page access url as login.php?page=1 where page=1 for aboutus page similarly you can page=2 for contact us page. At login page you can get the redirect page by the query string can redirect to the respective after successfully login using header function.
e.g. Header('Location:about.php');
just use redirect($_SERVER['HTTP_REFERER'],'refresh')
This works.
$this->load->library('user_agent');
redirect($this->agent->referrer());
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">