I have a list of links of twitter accounts (on people.php) a user can follow by pressing the persons name. When they press the link the follow.php script is run and the user is following the person. At the end of this script there is a header("Location:people.php") redirecting the user back to the people page.
What I want to do is give the user a message when they are redirected to the people.php page in a slide down message saying they are now following whatever person they clicked on.
I understand how to make this (this is what I am going to make http://www.youtube.com/watch?v=7wNz5T8SepQ), I just don't know how to connect it so the slide down message is triggered only on this redirect, not when the user first visits the people.php page, and how to make it so the message say which person you just followed. Thanks a lot for the help!
Since you are controlling the redirect, can you append a variable on the query string that will force a notification, ala:
http://www.yoursite.com/people.php?notify=true
You might also use a session cookie. Set the cookie when the user click the link and remove it when the message displays. Since you'll be using jQuery, you can use the jQ cookie plugin for simplicity:
https://github.com/carhartl/jquery-cookie
change your redirect header to include an extra flag - header("Location:people.php?following=who") and then you can look for that param when they return to the people.php page after following someone
Related
I have a logging application. You click the "Log" button, it takes you to another page with all of the forms etc. After I click "Submit" on this page, it submits to my database and redirects back to the home page. What I want to happen is when I click "Submit", it redirects to home page, and then has a pop-up that says something like "Thanks for the submission!". I've looked through the forums but can't really find anything specific to this application. Thanks.
There are a ton of ways to do this. The general idea is
The home page must contain code that displays the "popup," but only under certain conditions (e.g. a flag is passed somehow). Normal access to the home page should not trigger the condition.
The DB submission page must trigger the aforementioned condition when redirecting to the home page.
The "condition" could be as simple as setting a variable in the querystring, e.g. http://domain.com/home.php?showConfirmation=true. The problem with using the querystring is that the user could bookmark it and see the confirmation every time he uses the bookmark.
Another way to set the condition is to set a cookie, session variable, or pass the data via form/post. All of these have advantages and disadvantages.
You could also do it some fancy way, e.g. perhaps your site needs the general capability of displaying one-time messages. If the user is registered and authenticated, you'd be able to look up a DB table to see what messages are left to display to the user, and the home page would be coded to automatically display them (marking the DB record so that it doesn't get displayed again). The DB submission page would add the record for the confirmation message, and in addition you could use this feature for other types of home page messages that you dream up later, e.g. special promotions or new features. (I don't recommend building features you don't really need).
Send a paramater in the query string.
//home-page/?registered=1
Or you can set a cookie and check for the cookie if its set.. show the popup and delete it when user clicks on close popup.
My question is it possible to display a message if browser buttons have been pressed in order to be able to display a message stating if user should leave the page or stay on a page? Also can a message be displayed if user tries to change a url if they are on a certain page?
Thanks
Server side is needed for foolproofing this. On the server, when assessment is started, you should first have start screen URL. You must program it so that once assessment is started (after clicking start), it goes to the exam URL, and your assessment is always saved - when user goes back, using server side tricks have it so that instead of showing the start screen, it redirects back to the correct page (in a way that still maintains history), shows the exam with the data still in it, and pops up the warning not to click back button. Then, if user does it again, it does the same thing, again.
You have to have it so the exam is saved all the time. unload javascript event can be used to notify via alert() that they shouldn't be leaving the exam, and thats about all. onbeforeunload event can be used to try to give them the choice to stay, but shouldn't be depended on as it doesn't work on every browser.
Use onbeforeunload as suggested in a comment. There are various example, like this one: https://web.archive.org/web/20211028110528/http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm
If you want to call out the buttons that the user must click, you will need to do some browser detection, as most browsers have OK/Cancel buttons on the window that they display, but Chrome has "Leave this page" and "Stay on this page".
So I want to add like a box that says that you have been logged in successfully, but I don't want to add the code to every page. How can I make it so that the code is added to the login page (which redirects you to the home page, or whatever)?
Use the $_POST global on the page what is the submit page of the login form. The most useful is when that is the index.php, which includes all the other active pages.
if( isset($_POST['loginname']) )
{
>>write out the welcome message<<
}
it means, that immediatelly before that was submitted the form with the loginname input field.
After that save the login event into a session (ex. $_SESSION=$_POST['loginname']), only this will accesible on all further pages. But on logout do not forget to clear that session.
That depends on your login system structure but if you have a login box at the top of everypage for example there should be a script to process those logins without adding code to everypage other than a header include.
Again, depends on how your site is setup
If your question is how to send that information and store it from page to page, you would use _POST to send to login page, store the information in a session/cookie. Etc
Edit: if i am misunderstanding the question, let me know.
The question is not really clear. Looks like you need to think of a include file which can have your success message and related processing.
I am creating a quiz game in PHP.
I maintain a session from the start to the end of the quiz.
When the user clicks on the back button in the middle of the quiz
It display a page with message
"Confirm Form Resubmission This web page requires data that you entered earlier in order to be properly displayed"
So, I m trying to keep it on the same page on click of back button
I have handled the "onbeforeunload" event & it's firing up too.
code snippet
Redirectpage
{
javascript:window.history.forward(1);
}
but still am getting the same error?
thankyou folks.
Your page does not have rights to control the browser. OnbeforeUnload you can alert user and return false to stay on the page. Otherwise you cannot do much on it except expiring the previous page, so that user cannot go to previous page.
Two possible solutions:
Don't use use post, that's what causes the warning, if you submit using get, you won't get the warning.
If you can't do that:
Use AJAX instead of posting and replacing the entire page. That is so 1990s and leads to very confusing code. Keep state on the client. It doesn't seem you have a need to bookmark each of the pages, and if you did, you'd have to learn how to handle back button within an AJAX app. Here's one solution: http://www.zedwood.com/article/101/ajax-back-button-fix
Is there any way by which I can attach the back button of my browser to any particular link?
Actually I am designing a login page in PHP. After login I want the back button of my browser to open any particular page that I want, how can I do that in PHP?
Actually I am not a PHP guy, so my question might sound silly to some. :P
I suspect you want to redirect the user to a particular page after he logs in, you can simply use the header function for that:
header("LOCATION: user-panel.php");
That will redirect home to user-panel.php page.
The browser's back button goes back until there is history found, just to add that you can use javascript for that although this might not be required in your case:
Go Back
More info here
Update Based On Comment:
Basically you set a session when the user is authenticated for the first time, here is an example:
session_start();
// check if the user is already logged in: if yes redirect him even if the back button is clicked
if (isset($_SESSION['logged']))
{
header("LOCATION: user-panel.php");
}
// below is your own normal code
// your db query if the user specified criteria was met
if (user found)
{
$_SESSION['logged'] = true; // you should add this line if not already there
// redirect the user
}
As #Sarfraz correctly says header is the way to go. The back button is on the browser. PHP runs on the server, it does know anything about what happens in the client's browser. The page may as well have been accessed from a shell, for instance, where you have no back button.
Also, that would not be good page design, as people expect the page to rediret automagically after a login, not to have to push the back button.