Is it possible to refresh a page without using header("Location: XXXX");?
I would like something like a forced mouseclick on a link, kind of like header works but something that doesn't interfer with session_start(); the way headers do.
Simply, no. I've been looking for this myself and I couldn't find anything.
Sorry, I might be wrong though, and if I am i'd quite like to hear what could be used.
PHP is server side scripting. If a user presses a button you cant lift the event with php (unless you make a link or a form submit).
I dont really know if I understood what you need, but if you need to "refresh" a site with a click, thats easy: you put a link to the same site (or an action="site" if its a form submit).
But what I think is more suitable is that you use jaascript. you can use something like:
| Code: |
| <input type=button value="Refresh" onClick="history.go()"> |
or
| Code: |
| <a href="javascript:location.reload(true)">Refresh page</a> |
If you don't want to wait for user input just use
| Code: |
| <body onLoad="javascript:location.reload(true)"> |
or just put a timer..
If you could please be more specific about what you want.
Thanks,
K
The reason I want some kind of page refresh is this:
I have a site where users loggin, which makes the $_Session[] array fill
with there username when they logg out I destroy the session by doing
a unset() and a destroy() just to be sure. I then don't want someone to be able to gain entrence to the member pages by pushing the backbutton. There for I check if the superglobal array is empty or not this works on all memberpages exept for nylank.php. the relevant parts of the pages are presented below.
Any thought on what could be wrong? Oh, and if I use the back button to gain access to nylank.php and then refresh the page inloggcheck.php kicks in like I want to, but I want to do that instantly.
Hope all of this made any sense to someone
---------------------
the file nylank.php:
---------------------
<?PHP
@SESSION_START();
include 'inloggcheck.php';
if(isset($_COOKIE['stylesheet'])?$i=$_COOKIE['stylesheet']:$i="davlin");
$a="";
$b="alternate ";
include 'inloggcheck.php';
?>
---------------------
the file inloggcheck.php:
---------------------
<?PHP
if($_SESSION['inloggaduser']== "")
{
echo "<html><head><title>Davem Lingu</title>";
echo "<link rel='stylesheet' type='text/css' href='davlin.css' title='davlin'/>";
echo "</head><body><div id='container'><div id='header'><h1>Lab2 - PHP och MYSQL</h1><h2>Link archive</h2></div><div id='navigation'>";
echo "<ul><li><a href='start.php'> STARTSIDA </a></li><li><a href='links.php'> Länkar </a></li>";
echo "<li><a href='nyanvandare.php'> Registrera </a></li></ul></div><div id='content'>";
echo "<b>Du är inte inloggad och har därför inte tillgång till denna sida</b> <br> Om du har ett konto klicka på STARTSIDA och logga sedan in,";
echo "<br> om inte klicka på registrera och skapa en användare och logga <br> därefter in för att få tillgång till medlemssidorna.<br><br>";
echo "</div><div id='footer'><p>© 2007 <a href='http://www.liu.se'>DavLin</a></p></div></div></body></html>";
exit;
}
?>
Last edited by dawiid on Mon Jan 29, 2007 5:53 pm; edited 1 time in total
| dawiid wrote: |
| kind of like header works but something that doesn't interfer with session_start(); the way headers do. |
What do you mean?
I've never had any interference from header() to the session_start() or the other way around.
You cannot do what you want -- not reliably anyway.
You can try messing with the cache functions of your webserver/script.
Read http://www.mnot.net/cache_docs/
Best thing to do is to pass the responsibility of clearing the cache to the user. When the user logs out, tell them to clear the cache for security.
OK, thx for the answers!
Guess I've to accept there is no quick fix here. I have got to check the header and session for the 100:th time and see what I have missed, somewhere there is probably an output before the session or something like that or some little ' or " that I've missed. Thx again, keep up the good work!
header("Location: $location");
works fine for me 
phpinfo() is your friend. Just don't let anyone else see it.
Sessions can be tricky if you don't know what's happening behind the scenes. If session cookies are turned off, but trans sid is enabled, you still have to code the header like trans sid is disabled.
Oops, forgot to mention that ob_start and ob_flush will take of headers sent before the header call.
you should place ob_start(); at the beginning, and ob_end_flush(); at the end of the page
at least, that is the way i'm using 
The only difference between ob_flush and ob_end_flush is that ob_end_flush destroys the buffer and the other does not. If it's before a header call, it doesn't matter because the buffer will self-destruct. 