I have basic login code system that every values of the textboxes(user inputs) will store in a SESSIONS. After the user's login, my HOME.php showed. And in a HOME.php, The user clicked the back arrow of google chrome, and it seemed the page is going back to the INDEX.php where user logged-in. I was trying if the sessions in index.php are exist. if not go back to home.php?
How could I prevent if the user try to click the back arrow of chrome and still remain in home.php?,
You should check whether the session has set in the index.php and if it was set then you should redirect the user to home.php else to remain same in the index.php
So, In your index.php you should have this code
if(isset($_SESSION['user']))
{
header("Location: home.php");
}
else
{
#Ask for credentials using your form
}
Note : I am using $_SESSION['user'] you should the name that you are using.
I am not exactly sure what the problem is, but I think you want to check if the user session exists in your index.php page. If it does, redirect automatically to home.php and if it does not, show the page contents / login form.
Related
I need to create a button to go to the previous page if the last page visited was in the same domain and I have to check what page was. For example if the user come from google, the back button have to redirect to the homepage, if he come from www.domain.com/product the back button have to redirect to that page, if he come from www.domain.com/static the back button have to redirect to the homepage.
I tried with PHP and the $_SERVER HTTP REFERER and if the protocol is http woks fine, but it doesn't work with https, it redirects always to the homepage. It looks like that variable doesn't exists!
How can I solve that problem? JavaScript and history obj can help?
Thanks
Use a session variable to track the current page and check it at the next page, i.e.:
if (isset($_SESSION['page_url'])) {
// visitor has seen another page in this domain
$previous_page = $_SESSION['page_url'];
}
else {
// visitor comes from outside, use home page
$previous_page = 'http://domain.com';
}
// keep the URL of the current page
$_SESSION['current_url'] = $_SERVER['REQUEST_URI'];
I have two iframes named "header" and "content". When the index page is loaded, the "header" contains a link to the Home Page, and another link to the Login Page. While the "context" displays stuff about the page and all that.
Now the problem is, after I log in, I want both of the frames to reload. I can change "context" because this is the iframe where I will do the logging in so there's no problem.
What I am tyring to do now is to find out how I could also change the "header" iframe. After logging in, I want it to display a link for Home Page for his tasks, and a link that would display the username of the logged in user for his profile.
Is there any way I could do this? I am using PHP, by the way.
Thank you in advance. :)
it would be better if you share your codes with us, its hard to answer by this way, you can try using php sessions for check a user logged in or not. after the code which you checking login, if login is success create the session and define $_SESSION['userName'] or userID as you wish and you check if session userName set on your header or content.
<?php if($_SESSION['userName']): ?>
// your html codes goes here for logged in user
<?php else: ?>
// your html codes goes here for non-user
<?php endif; ?>
i have a issue with my SESSIONS, on the first page the user clicks on a anchor, then if the user is logged in will be redirected without problem, but if not, first he will pass through login page, but when the user reach thelogin page, the variables are missing. (The login page occurs after the redirect page). So i have saved the SESSIONS with $_GET parameters.
How i can keep the current SESSIONS to redirect the user after the login?
Thanks!
EDITED
Page: retailer.php (this page is where its fired the parameters)
<a href="/go2store.php?rid=<?php echo $row['slug_title']; ?>&c=<?php echo $row_coupons['coupon_id']; ?>" onclick="javascript:window.location.href='<?php echo $row_coupons['logout_url']; ?>';" target="_blank">
Page: go2store.php (this page is where i'm saving the SESSION)
$_SESSION["myCupon"] = "/go2store.php?rid=".$_GET['rid']."&c=".$_GET['c'];
Page: redirect.php (This page its checking if the user is logged in, if yes, redirect to the URL on the SESSION, if not will send to login.php)
Page: login.php (here i have this on top of the code)
session_start();
$_SESSION["myCupon"] = "/go2store.php?rid=".$_POST['rid']."&c=".$_POST['c'];
But it comes empty, its not returning any values after the redirect.php page.
As noted by a user in the comments, you need to include:
session_start();
At the top of each page to carry session variables across pages, otherwise it won't recognise the vars you set initially.
We don't know how you're organising your code, but this needs to be present both before and after potential login.
You can easily set/get $_SESSION variables prior to login or indeed set/get upon login from other vars you might use in pages that aren't yet authenticated.
On a password protected website (ajax-php-jquery login system), a fadeIn/fadeOut alert confirms that the user just logged out. The user is sent back to the login page and I do a document.referrer to check if he comes from a page of the site (if so it means that he just logged out so I can display the message). But of course if the user refreshes the page he will get the notice again.
I was thinking of changing the document.referrer but the property is read-only. Any idea how I could display the message only once if the user did log out?
You could do a conditional with PHP:
if(isset($_SESSION['justLoggedOut'])){
print '<script type="text/javascript"> ..notification code.. </script>';
unset($_SESSION['justLoggedOut']);
}
You just have to set the session from within the authenticated area (or the logout page which redirects to the index page [I'm assuming.])
Using a cookie would be easiest route. Simply add a cookie when they log out, and then delete it after the notification has been shown. This cookie could contain all of the information you want about the log out: e.g. the time the logged out and the URL from which they initiated the log out.
Of course, that is assuming your clients are allowing cookies on your site. A server side alternative would be to use session data. Your notification would then send an AJAX call back to the server to clear the indicator that the notification should be shown.
In my JSP page I am using post method while submitting the page.
So once I go from Page 1 to page 2. In Page 2, If I press F5 I am getting alert as
"To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier."
I knew this question is a bit sarcastic but please give me an Idea.
I can't change my method from POST to GET because I need to send large amount of data.
Thanks in advance...
Edited:
In my Page1.JSP I call onClick function in that function I call action as "/page2servlet.do".
Now, In Java side I use Spring Framework. With MVC Object I return to page2.jsp.
So where do the response.sendRedirect Fit.
Do a redirect to Page 2 after POST. You will not receive the prompt anymore.
After doing POST save all the info you will need to session and send an instant redirect to other page with GET. Then on that other page get all the info you need from session.
However, after the session expires user wont be able to press Refresh. Also, it will break multi-windowing. User won't be able to do 2 distinct submits in separate windows as they will share same session object.
<?php
session_start();
if(!isset($_SESSION['disablethispage'])){
$_SESSION['disablethispage'] = true;
// serving the page first time
}else{
// visited before or page was refreshed
}
?>
Here is a version that replaces the next page:
http://plungjan.name/testredirect.html ->
redirect.php ->
thanks.html
and here is redirect.php
<meta http-equiv="refresh" content="3; url=http://plungjan.name/test/thanks.html">
<script>
location.replace("http://plungjan.name/test/thanks.html");
</script>
redirecting..
.