Jump to content

Recommended Posts

Okay so i have a header of the page which displays some information about the user. Unfortunatelly this header is updated on every click. And the problem is that when i click on the main page for something lets say change my name. On the next page load it will remain the same because the header is displayed before the main body (where the changes take place). So after i reload the page one more time, then i have the updated info. Any ideas how to avoid this?

My first guess was to cache all of the header in a session ... but that failed to workout. Basically i want to process the request first then to display the whole page in 1 piece. Help?! :)
Link to comment
https://forums.phpfreaks.com/topic/11884-php-header-and-body-changes/
Share on other sites

oh got you. just add

header ("location: ".$PHP_SELF); //or something similiar

after each change which requires a refresh. (add it before your html). Wouldn't trust $php_self though, you're better off specifying the page.
if you have already output html, just use

?><script type="text/javascript">location = '<?=$PHP_SELF?>';</script><?
Hm i still think you dont understand me so i will provide maybe a better example:

$_SESSION['username'] by default in our example has a value of "test";

header.php
-------------
echo $_SESSION['username'];
-------------

main.php
-------------
$_SESSION['username'] = 'as;lkd';
-------------




So when i load the page at first i will see the 'test' and after i hit refresh i will see 'as;lkd'

I want to display the new property without refreshing twice. Which will happen if i used the following construction:

$_SESSION['username'] by default in our example has a value of "test";

main.php
-------------
$_SESSION['username'] = 'as;lkd';
-------------

footer.php
-------------
echo $_SESSION['username'];
-------------


As output i will get 'as;lkd', and not 'test' as in the first example.


I hope you understand me now.
well it's impossible to get a value which is set later, you would have to export the var to javascript via var = <?=$phpvar?> and then write that var to the header in a javascript once all the php has loaded (obviously).
Unless you can set the username attribute before any html is sent
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.