Jump to content

Archived

This topic is now archived and is closed to further replies.

DarkReaper

Php Header and body changes

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?! :)

Share this post


Link to post
Share on other sites
How exactly are you including this [i]header[/i]? Is it a frame or something? Use the include() function which makes the page into 1 before sending it to the client.

Share this post


Link to post
Share on other sites
@thorpe: yes i use include.

@joquius: the html and the code are so implemented in one another that i cant distictly classify them :( ... any other ideas?

Share this post


Link to post
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><?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
thanks the javascript trick is working :) ... its a little bit annoying .. but hey its my fault :)
thanks again.

Share this post


Link to post
Share on other sites

×

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.