Click on page1 and refresh on page 2 - php

I am stuck with a problem. I am not finding further way. Please help me out with the logic.
I have page1.php besing used by user1 and have page2.php used by user2.
Now when the user1 clicks on a button in the page. The page2.php which is being viewed by user 2 must be refreshed. How can I do that.
Your help is most appreciated.
Thanks!
Abhilash

You cannot do it in php. Once the page is loaded, PHP dies and is out of control.
You have a few options:
Use javascript
Use the refresh meta tag
I think that the refresh meta tag is the most easy and convenient.

you can do it by using php ajax and javascript \ jquery
just save the click button flag in database, and by using php ajax continuesly check wether the button click flag is on or off,
if it is on than you can refresh the page by using javascript.window function

Related

Go to new php page

I'm wondering the best way to go to a new page. I have a PHP document with a submit button. Once that button is pressed, it runs the php code on that page, creates some session variables, then I want it to go to the next page after this code is executed. I know with traditional submit buttons you simply have the form that's run being the next page, but how do I link it differently?
You can force redirect with successful headers like as below:
header("Location: second.php");
In a well designed web application, there is no direct relation between the script and the page as the control script is the same for every page and simply shows the page needed based on what was selected or done.
There are many ways to implement this but a good starting point would be to look at MVC design.
set the URL of new page on form action='' to load the another script after submit the form.

How to resubmit PHP form with javascript

I am wondering if it is possible to to resubmit a form with a button click that calls up a javascript command.
So this is basically what I'm trying to do -
page 1: form; action = page2.php
page 2: generate a randomized list according to parameters set by page 1
I would like to place a button on page 2 so that on click, it would be as if the user has hit F5, and a new list would be generated with the same parameters.
I found a lot of help on Google with people trying NOT to get this to happen, but I'm not sure how to actually get it to happen.....
Thank you!
You could use location.reload(true); to refresh the page.
<button onclick="location.reload(true);">refresh</button>
you only need to use. location.reload() instead of location.reload(true). since this will not disable caching for the reload but using true as the parameter will.
here is the reference. How to refresh a page in jquery?
EDIT: why not just use hidden input field and preserve the values and fetch it anytime you want to?

Prevent users from re-clicking "Like" button on page refresh

I want to stop a user from clicking a Like button multiple times. I can disable the button on the first click using jQuery, but when the page is refreshed, the user can again click the button. How do I prevent a user from re-clicking the button on page refresh?
you can store the user id in database who have already liked and disable the like button/link for them so they once click on the button or link never click again
use js to block the UI
like so: http://www.malsup.com/jquery/block/#demos
google "js block ui"
sorry for the short answer
edit: did not read your question properly i guess, see Mayank swami's post , he has your answer
You should check it in Server side.
use can use $_SESSION for this purpose.
When user click on link set
$_SESSION['liked']=true;
and then check if user clicked before. Session won't be destroyed in when page refreshed.

Web page redirect and issue with browser button

I have a PHP data entry page and redirecting to the new page after data inserted successfully. But the user can go back using the Browser back button and click on the 'Save' button again. Is there any way I can prevent this kind of problem? Please suggest. Thank you.
I am using the following code to redirect.
header ("location:Redirect.php?ref=10");
Yes, you can store a variable in their session whenever they click the button then use this to show/hide the button accordingly by checking that session variable. Also if it's set then do not allow posting/processing of the form.

Can I have PHP redirect to an in-page link when I process a form?

I have a vertical scrolling website (lots of in-page links). I also have a contact form script I'm working on.
I'm trying to set it up so when someone completes/submits the contact form, it redirects them to #contact_area (on the same page), but calling the header function after is throwing a "Cannot modify header information" error.
Any suggestions on how to redirect after a script is processed from within ?
Thanks!
A header redirect needs to happen before PHP prints any output. If you want to direct the user to an anchor on the current page you have two options:
Submit the form as normal. Your PHP script processes the data and does this before any output: header("Location: /my_same_page#contact_area"); The page will be reloaded but they'll end up in the right spot.
Submit the form data via AJAX and then scroll to the #contact_area anchor.
The second options is probably the cleanest but the first one should be a lot easier for you to implement.
You can work around this using output buffering, few examples here
I am assuming you are posting the form back to the same right?
Maybe submit the contact form to another page for example contactus.php and once its been successful place your header location code into that OR you could use the jquery form plugin (submit() function I have used) which runs in the background and then you could maybe jquery scrollTo() your hashtag.
Go got option 1 and if you have time then play with the jquery version maybe.

Categories