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..
.
Related
basically I need some help and I have no idea how to progress or come up with a solution with this issue. This is a similar issue to when you logout of an Laravel app, and press the back button, it will display the information from the cache.
The problem I am getting is, if 2 users share a same computer. At one point the first user gets page 1 cached (after a form submit they get redirected to page 1). Now, I logout and login using the 2nd user. I go to page 1 then to view the form that was submitted but I then press the back button on the browser. This then leads to page 1 BUT with account 1 on page 1 instead of being account 2 on page 1.
I understand I can remove cache from all pages from my app but the app is currently quite large and relies on the cache in order to load page 1 otherwise I get a out of memory error. I also don't think I can make page 1 efficient enough to load without cache.
Is the only other solution is to have a back button inside the app on every page and disable browsers back button?
I also thought about using an intermediate page between the submit and page1 (therefore in theory would not cache page 1) but this would need to be done throughout the app on any form submit. Is this a possible solution?
Does anyone else have any other solution to this problem? I have the back button currently disabled but I realise it is an inconvenience for users.
Given that you have record of the session data inside a table in the database I think a solution could be, to have something like this inside a Controller
<?php
public function login(Request $request) {
//Process the $request data
$user = //Get user with a model function
if ( $user ) {
Auth::login($user);
}
}
public function logout() {
Auth::logout();
return redirect('/');
}
?>
In this case your User table should have fields with the user session data. If you like to use HTTP sessions then add Session::flush();to the logout controller function.
So I have a website which redirects to another part of the site ie, when pressing a button on "www.test.com" it reditects to "www.test.com/anotherpage". Now my problem is that I only want users to be able to access the second page when using the button and not just typing in "www.test.com/anotherpage" into the search bar.
So, is there any way to setup my page such that it cannot be accessed by the url but only redirected from another part of the website?
document.referrer
The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark). Since this property returns only a string, it does not give you DOM access to the referring page.
You need use Php code to login users and check sessions example like exaplain here: Login form and session example
of course you need basic know about Php
You could use a client or a server side technique.
Example of client side is Javascript, reading the document.referrer in the called page as #Barmar pointed out, and redirecting to the home in case the referrer is not from your home page.
The server side way could make use of parameters passed to the page, like a SESSION identifier that will be generate on the home page, for example and checked in the called page.
Actually there are a different ways to accomplish your goal.
You should provide some more info about the environment so we can help.
You can usee PHP. Simply put your button between form tags
<form action="http://www.test.com/anotherpage" method="POST">
<input name="mybutton" type="submit" value="Go to another page">
</form>
and on anotherpage
<?php
if (!isset($_POST['mybutton'])) { //check if the button was clicked
header('Location: index.html'); //forward to index if not
}
?>
I'm building a contact form for my website and I would like users to enter their information, click submit, have the information process with php and to just have a message display on the bottom of the form. Originally, I was redirecting to another page and the form was working properly, but now I just want to append a small message and can't get it to work.
This is what I have currently in my contactengine.php file for it to process all the variables and send the email.
if ($success){
THIS IS WHAT I DID BEFORE THAT WORKED BUT HAS TO REDIRECT
// print "<meta http-equiv=\"refresh\" content=\"0;URL=index_thanks.html\">"; //
//BELOW IS WHAT I WANT TO OCCUR
<script type="text/javascript">
$("#contact-area").append("Thanks for your message!")
</script>
}
You don't need JavaScript for this. JavaScript is great, but it should only be used where necessary, since it can add some brittleness to the user experience.
Here's a possible design approach:
Set up a POST form
Process the form, set a session variable to thank the user, and redirect to the form again. This switches the browser from POST to GET mode†, and is usually as simple as this:
header('Location: http://yourdomain.com/form.php');
exit();
Render the form as usual. If a session variable is set to thank the user, render the thank you message, and unset the session variable‡
I wouldn't use a <meta /> refresh here - it needs to load more data to work, and is more fiddly to implement.
† The POST-redirect approach is a common design pattern in web development. There are plenty of resources about this on the web, if you are unfamiliar with it. It fixes problems associated with rendering web content inside a POST method, particularly in relation to page refreshing and using the back/forward buttons.
‡ These temporary session variables are sometimes known as flash variables. They exist from one HTTP operation to the next, and are erased at the end of the second operation.
You cannot put JavaScript inside of your PHP code. However, I will give you an explanation of what you need to do.
On the client side, bind an event for the click, then
$('form button').click(function() {
$.post('file.php', {'object': 'property'}, function(success) {
if(success) {
$("#contact-area").append("Thanks for your message!")
}
});
});
On the server side, you will process this:
//file.php
$sentByAJAX = $_POST['object'];
return true;
I am trying to use the following javascript code to alert the user when a form has been updated.
Basically what happens is a user clicks on a list of prospective clients, they click edit, this then loads all the clients details into an editor form. Once they have finished editing the user they click the update button and the contents are posted to a php processing script, which also has various other php functions in it that perform other commands before the user is then sent back to the prospect editor where the user details are re loaded into the form again with all the edits applied, this is all done in a second or two.
Once the update has been successful it adds a token into the GET array called update=1 which is passed in the url back to the editor.
What I am trying to do is alert the user when the clients record has been successfully updated by way of an alert box in javascript.
I am using the following code but am no sure how to get the javascript to look for the update=1 in the url and only display update successful when the client has been updated, and not on the initial load when the client is getting loaded from the list of clients.
JAVASCRIPT
<script language="JavaScript">
function prospectupdated ()
{alert("Prospect Updated !")
}
</script>
HTML
<body onLoad="prospectupdated()">
As it stands at the moment it loads every time the page loads, whether the update=1 token in the url is there or not, does anyone know of any tutorials on how to do this, or knows how it do it themselves and doesn't mind sharing ? :-)
Thanks
You need to test the update:
<body <?php isset($_GET['update']) && $_GET['update'] == 1 ? print "onload='prospectupdated()'" : '' ?> >
Look here: How to retrieve GET parameters from javascript?
It will show you how to obtain the value for the update=1.
You would then have an if() statement to check if update=1. If it does, then execute the alert().
I need to do the following:
I have a textbox, which appears in every page of the site, that allows to subscribe to a newsletter. This I've done already and the user is redirected to previous view after subscription.
I'd like to add a javascript alert to the page the user is returned to, something like "Thanks for subscribing". How can this be done?
Thanks in advance.
EDIT: Propably it's not clear from the post tags. I'm using ASP.NET MVC 2 Preview 1
If you are doing a HTTP redirect, then the page you will render needs to be passed some information so that it knows to include the javascript to open the alert box (adding an optional element to the page might be a nicer way to do this).
That information needs to be stored either in a browser cookie, or in a session store (which is keyed from a browser cookie). You can remove this once you've rendered your message, so that it is only shown the first time you visit that page after the redirect.