Click to See Complete Forum and Search --> : [RESOLVED] Parse it!
ididntdoit
Apr 16th, 2008, 10:50 PM
I have searched long and heard, but I have failed to find a working instructions on how to accomplish the following:
I have a web server (in my closet ;)) that is running Windows XP Pro SP2 and Apache 2.2 and PHP 5.2.5.5 (I believe) and I have lots of PHP codes that I'm dying to integrate on my site, but would like to make it like CSS (one PHP page that is linked to). My problem is that I cannot link to the php page from an HTML document. I have tried a few ways and none work. I was told that I need to configure Apache to parse the PHP in the HTML (<?php import("myfile.php"); ?>) and actually run the code in myfile.php instead of just read it and ignore it. How can I achieve this? Any help would be much appreciated!
EDIT: I also have MySQL 5.0 installed, in case that makes a difference...
penagate
Apr 17th, 2008, 02:47 AM
How is PHP configured? If CGI, did you add the CGI handler directives? If SAPI, did you add the LoadModule and content type directives?
There is an installation tutorial for PHP and Apache in the FAQ thread of this forum.
visualAd
Apr 17th, 2008, 02:57 AM
You do need to configure Apache to send the request to the PHP interpreter. Would you like to run PHP as a module (within the Apache process) or as a CGI (a separate process from Apache)?
ididntdoit
Apr 17th, 2008, 04:01 PM
Hmmm... I'm new to most of this. I'm not sure what CGI or SAPI is or what the difference is. As for VisualAd's comment, I have added it ass a module to apache with:
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php .html
AddType application/x-httpd-php-source .phps
and
PHPIniDir "C:/php"
I can run a straight PHP file fine, and one web page I have uses
<form enctype="multipart/form-data" action="uploader.php" method="POST">
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
<a href="uploads">Uploaded stuff</a>
as an upload code which is in uploader.php and it works fine. Is there some other way to reference a PHP file like this to include it's code? I'll attach the php I'm trying to get working. It's a visual hit counter.
k1ll3rdr4g0n
Apr 19th, 2008, 08:07 PM
So much for OOP now a days!
But really, you should just be able to include (http://www.php.net/manual/en/function.include.php) counter.php where you want it displayed and it should work.
ididntdoit
Apr 19th, 2008, 09:52 PM
I know. It just refuses to. I have:
<html>
<font face="Courier New">
Hello <(^^,)>
</font>
</html
<?php
function foo()
{
global $color;
include 'vars.php';
echo "A $color $fruit";
}
/* vars.php is in the scope of foo() so *
* $fruit is NOT available outside of this *
* scope. $color is because we declared it *
* as global. */
foo(); // A green apple
echo "A $color $fruit"; // A green
?>
in index.html, and:
<?php
$color = 'green';
$fruit = 'apple';
echo "A $color $fruit"; // A
include 'vars.php';
echo "A $color $fruit"; // A green apple
?>
in vars.php. For some reason, Apache REFUSES to allow PHP to be run in an HTML document. Does anyone know why and/or how to fix it? Please?
ididntdoit
Apr 19th, 2008, 09:55 PM
WOW! This is really weird.
<html>
<font face="Courier New">
Hello <(^^,)>
</font>
</html
<?php phpinfo() ?>
Shows <(^^,)> AND the PHP info screen! BUT,
<html>
<font face="Courier New">
Hello <(^^,)>
</font>
</html
<?php include'test.php' ?>
with <?php phpinfo() ?> in test.php doesn't work. Does anyone have any suggestions about this?
EDIT: nvmd, I named test.php wrong. Now it works. I will have to check around to see why my other code won't work. I will mark this resolved when I get it fixed.
k1ll3rdr4g0n
Apr 19th, 2008, 10:08 PM
Lets tackle one problem at a time.
The reason Apache doesn't automatically parse PHP in an html document because it's not told to. Check your Apache configuration.
But the better question is why do you want to use PHP coding in an html file, the unofficial standard is that php code should be in .php (or .php5, phps ect) files.
ididntdoit
Apr 19th, 2008, 10:09 PM
OK, I have no idea why it wasn't working before - not one clue. But, it seems to work now. Yes I did forget to close the html tag properly in my last post, but closing it works fine too. Thanks guys!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.