Shoutbox

PHP: refreshing a page with a button - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: PHP: refreshing a page with a button (/showthread.php?tid=61949)

PHP: refreshing a page with a button by Weyzza on 06-28-2006 at 09:01 PM

I need help with PHP since I'm not an expert in it.

So I have a form containing a table that goes to itself, and inside it there's a button that does some operation X.
What I want is, after the button's pushed, I want the page gets refreshed so the table content is updated.

What PHP code should I add near operation X?

I did google this, but all solutions I found were for auto-refreshing a page

Thanks.


RE: PHP: refreshing a page with a button by Ezra on 06-28-2006 at 09:40 PM

Do you mean how to redirect with php?

Send a location header like this:

code:
header("Location: page.php");


RE: PHP: refreshing a page with a button by Lou on 06-28-2006 at 09:41 PM

quote:
Originally posted by Ezra
Do you mean how to redirect with php?
quote:
Originally posted by thekid
refreshing a page with a button

Althought that method works:)

Other method:
code:
header( 'refresh: 0; url=http://www.example.net' );

RE: PHP: refreshing a page with a button by Ezra on 06-28-2006 at 09:44 PM

Yeah, well... he has a button that does an operation, after that operation is finished just use the header to reload the page.


RE: PHP: refreshing a page with a button by Lou on 06-28-2006 at 09:46 PM

quote:
Originally posted by Ezra
Yeah, well... he has a button that does an operation, after that operation is finished just use the header to reload the page.
Updated the post:P
RE: PHP: refreshing a page with a button by Weyzza on 06-28-2006 at 10:35 PM

I tried both methods and came up with some conclusion:

code:
if( $_POST['ok_btn'] == '1' )
    header( 'refresh: 0; url=http://www.example.net' );
I need to click the button twice to get "the refresh effect."
Can you explain this to me?
code:
if( $_POST['ok_btn'] == '1' )
    header("Location: page.php");
This has the closest result I want.

However, both methods don't really do "refresh" instead they redirect users to the URL in the link.
So, I click "Back" button on my browser, it goes to the page before the change was made.

I hope you understand what I mean :p
Thanks again.
RE: PHP: refreshing a page with a button by Ezra on 06-28-2006 at 10:41 PM

really refreshing isn't possible with php, try using javascript with xmlhttprequest for that, with the button first call the xmlhttprequest function to send the data to the server then edit the table with the new data received from the xmlhttprequest response data...

BTW: This doesn't even need a refresh ;-)

This JavaScript + XmlHttpRequest is better known as AJAX.


RE: PHP: refreshing a page with a button by lizard.boy on 06-28-2006 at 11:49 PM

could you not just make a link that links back to the page?.. I suppose that wont properly refresh content in all cases. If it did work couldnt you just do it like This
If thats not what you mean, sorry, i misinterpreted the question.


RE: PHP: refreshing a page with a button by Jhrono on 06-29-2006 at 12:05 AM

Nah, it probably wouldn't lizard.boy, because of the cache (am I right ?)