note 69949 added to function.header

From: Date: Wed, 27 Sep 2006 16:12:58 +0000
Subject: note 69949 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-117739@lists.php.net to get a copy of this message
There has been some discussion on the best way to FORCE a refresh of a page. In general, the solutions revolve on reducing or eliminating caching. However, I think that what some people are looking for... is how does one force a real refresh of the page after some internal action on the page (be it a javascript action OR a button was pressed). I found the following code VERY helpful when I encountered this need. Specifically, I had a listbox where one could press a button to delete a selected entry in that listbox. The listbox was dynamically linked to the contents of an external source only in the sense that the listbox got updated with the current list ONLY when the page got refreshed. Thus, I needed a way to force a refresh after the person pressed the delete button. I did this by adding the following code after my actual delete action. <?php header( "Location: http" . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on" ? "s" : "") . "://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . ( isset($_SERVER['REQUEST_URI']) ? $_SERVER ['REQUEST_URI'] . ( $_SERVER['QUERY_STRING'] ? "?" . $_SERVER ['QUERY_STRING'] : "" ) : "" ) ); ?> Do note, the above code is written to be VERY generic. You can probably simplify it greatly if the port is a standard port and/or you are always using http or https and/or you don't expect to have a query string appended to the end. BTW, I didn't come up this code myself... I happened across it while reading the following article on auto-login techniques for Mediawiki: http://meta.wikimedia.org/wiki/ User:Otheus/Auto_Login_via_REMOTE_USER/code ---- Server IP: 64.71.164.2 Probable Submitter: 65.222.202.26 ---- Manual Page -- http://www.php.net/manual/en/function.header.php Edit -- https://master.php.net/note/edit/69949 Del: integrated -- https://master.php.net/note/delete/69949/integrated Del: useless -- https://master.php.net/note/delete/69949/useless Del: bad code -- https://master.php.net/note/delete/69949/bad+code Del: spam -- https://master.php.net/note/delete/69949/spam Del: non-english -- https://master.php.net/note/delete/69949/non-english Del: in docs -- https://master.php.net/note/delete/69949/in+docs Del: other reasons-- https://master.php.net/note/delete/69949 Reject -- https://master.php.net/note/reject/69949 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117739) next »