Welcome! Log In Create A New Profile

Advanced

[PHP] reload page without use header

Posted by Farzan Dalaee 
Farzan Dalaee
[PHP] reload page without use header
June 17, 2012 10:10AM
hi guys
is there any way to reload page without using header('location :index.php'); and javascript?
Best Regards


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Simon Schick
Re: [PHP] reload page without use header
June 17, 2012 12:20PM
Hi, Farzan

Redirecting is something you can do in a way the user doesn't see anything
(I call them server-side redirects) and in a way the user get's informed
that the url has changed (I call them client-side redirects).

What I mean with server-side (mostly called internal redirects) is if the
user requests a page, you can do stuff with mod_rewrite (in Apache) or some
equal webserver-module to call another file than requested. The user will
not get any notice about that.

Client-side redirects can be done using the HTTP-header (see
list-of-http-status<http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection>;),
JavaScript (please think also about a non-js solution) and by using a HTML-Meta
tag http://en.wikipedia.org/wiki/Meta_refresh.
In my opinion the best way to do a redirect, where the user gets noticed
about, is the HTTP-header. This can be set f.e by your webserver or by a
php-script.

Example for PHP-script:

header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: http://www.new-url.com"; );

As far as I know, this is the only way to let other services (f.e. a
search-engine) know that this page has been moved permanently (or
temporarily) to another url.
That's the reason why I use the header-command (incl. setting the
HTTP-Status explicitly). If you don't set the HTTP-header, it will be added
(by PHP or your webserver). In my case, I use PHP 5.4 and nginx 1.2.1, the
header-code 302 is added if I don't set it.

May there are more ways to set redirects, but this are the one I know of.

Bye
Simon

On Sun, Jun 17, 2012 at 10:06 AM, Farzan Dalaee <[email protected]>wrote:

> hi guys
> is there any way to reload page without using header('location
> :index.php'); and javascript?
> Best Regards
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
As'ad Djamalilleil
Re: [PHP] reload page without use header
June 17, 2012 01:00PM
you can use header("Refresh: 60"); to refresh your current page if that
what you really need. 60 means it will be refresh in 60 seconds.

On Sun, Jun 17, 2012 at 12:06 AM, Farzan Dalaee <[email protected]>wrote:

> hi guys
> is there any way to reload page without using header('location
> :index.php'); and javascript?
> Best Regards
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Stuart Dallas
Re: [PHP] reload page without use header
June 17, 2012 01:10PM
On 17 Jun 2012, at 09:06, Farzan Dalaee wrote:

> is there any way to reload page without using header('location :index.php'); and javascript?

When you say "reload page" do you mean redirect to another page or refresh the current page?

You can reload or redirect a page using a meta tag in your HTTP head block -- http://en.wikipedia.org/wiki/Meta_refresh -- but if you're wanting to redirect the user to another page you really should use an HTTP header.

-Stuart

--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Sorry, only registered users may post in this forum.

Click here to login