I have a login with sessions.
And I want to know how to condense it.
login.html
// form
login.php
//actually checks if there logged in.
Is there a way to combine the two? Would I do..
// HTML //
// THEN PHP//
I basicly want to combine the form and the actual php code together into one php file, if I can...
ID:34315
![]() Aug 28 2007, 12:19 pm
|
|
PHP and HTML can be combined seamlessly into the same page using any method you like.
PHP MUST be contained within a <?php ?> tag, and HTML must either be passed via the echo() function, or outside of a <?php ?> tag. Variables defined in one <?php ?> tag are still available in another <?php ?> tag in the same .php file. Some things, however, must be done OUTSIDE of the <HTML> tag. Things like rerouting the user's page, etc. Must be done before header information is generated. Also, note the use of the include() function. Include will insert the entire file into the HTML page at that position, so you can actually create template files using raw HTML code and PHP variables simply by using include() to load the template. The page, however, should be saved as a .PHP file, as a lot of webservers won't parse php tags on non .php files. Enjoy! |
Ter13 wrote:
PHP and HTML can be combined seamlessly into the same page using any method you like. Right, I've been using include() and it's been working great, but that still doesn't stop there from being 4 pages, when it seems I could do it all in one php file, How can I have my LOGIN inputs (html), and then have those inputs route to the PHP on the same file after the user hits submit? |
<?php
include("htmlfile.htm");
# put your PHP stuff here
?>
- along with the .PHP file.
If you're looking to be able to use PHP in HTML files, you could edit your .htaccess file to treat them the same (assuming you're using apache).
In the root website directoy (I'm using netserv, so it's 'C:\netserv\www'), create a file called '.htaccess' (assuming it doesn't already exist).
Add this to the file:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
Also, nothing is stopping you from using HTML in the PHP file.
This is normal HTML.
<?php
echo "This is PHP.";
?>