HTML files included PHP inside

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fuyenhou
Forum Newbie
Posts: 9
Joined: Tue Jun 22, 2004 4:54 am
Location: Malaysia
Contact:

HTML files included PHP inside

Post by fuyenhou »

I had developed a web site with HTML files
Then i would like to add in PHP program into the web site
Hm.. for example

I had create a cookie inside a xxx.php fields an examples --
setcookie("username",$username);

thus I would like to display in HTML pages

<html>
<head> try </head>
<body>
'I had insert alot of fixed image and also flash inside this HTML page
then in the means tims I need these cookie help to disply the information so i write
---CODE CODE

you are: <?php echo $_COOKIE["username"] ?;>

</body>
</html>


Nothing show out.. wat can I do... HELP
TOLONG in malay :P



?>[/php_man]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

first off, make sure display_errors is turned on, make sure error_reporting is E_ALL.

if you are using any code that affects headers (cookies, sessions, header function calls) they must happen prior to any output, be it text, whitespace, anything; otherwise, you will get errors and warnings about headers being already sent, which will make your cookie/sessions/header calls not work. read Warning: Cannot add header information for additional information about the errors, and how to fix them.

next, make sure to read Posting Code in the Forums for our guidelines about posting bits of code/output what have you.

Finally, it is suggested that you do all php processing outside of "presentation" level things. In other words, 99.9999% of your php code should occur prior to any HTML. This is mostly to get the greatest seperation from the HTML and php as possible. The reason for this, is the page design will change, how the code works (behind the scenes) shouldn't change much at all in respect to the changing design. Plus, a designer can be working on the HTML while a programmer can work on the code without any overstep. Which is always productive.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Also, a more obvious solution, if you're setting the cookie on the same page as you're trying to display it, then it won't show up.

Try this:
process.php:

Code: Select all

<?php setcookie("username",$username);
header("Location:display.php"); ?>
display.php:

Code: Select all

<html>
<head> try </head>
<body>
'I had insert alot of fixed image and also flash inside this HTML page
then in the means tims I need these cookie help to disply the information so i write
---CODE CODE
you are: <?php echo $_COOKIE["username"] ?;>

</body>
</html>
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

If i followed what you said, you actually have your PHP in an .html file?? If so, then you would need to set up PHP to parse .html files aswell so it will execute the PHP code inside, if that makes any sense!
Post Reply