Jump to content


Photo

Php Header and body changes


  • Please log in to reply
7 replies to this topic

#1 DarkReaper

DarkReaper
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 13 June 2006 - 03:55 PM

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

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 13 June 2006 - 03:59 PM

How exactly are you including this header? Is it a frame or something? Use the include() function which makes the page into 1 before sending it to the client.

#3 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 13 June 2006 - 04:07 PM

just load your code before the html header.
z..z..z..z..z..z..z..z..

#4 DarkReaper

DarkReaper
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 13 June 2006 - 07:15 PM

@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?

#5 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 13 June 2006 - 08:15 PM

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><?
z..z..z..z..z..z..z..z..

#6 DarkReaper

DarkReaper
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 13 June 2006 - 09:27 PM

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.

#7 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 13 June 2006 - 10:30 PM

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
z..z..z..z..z..z..z..z..

#8 DarkReaper

DarkReaper
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 14 June 2006 - 07:32 AM

thanks the javascript trick is working :) ... its a little bit annoying .. but hey its my fault :)
thanks again.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users