I've already tried the advice given on this page, by opening my .php page with Chrome, Mozilla, and IE (instead of dragging it to them), my EasyPHP is started (along with the other services I just installed with it), my files are located in C:\inetpub\wwwroot (on Vista), and so far, no PHP is being outputted. It either shows up as code on the page, or it doesn't work at all (includes don't work, for example). I tried configuring the DirectoryRoot in the httpd.config file (I commented out the original first, instead of deleting it), so it would point to the wwwroot directory, but that didn't work either. I am very new to EasyPHP and it's been a few years since I really dealt with regular PHP, Apache, and MySQL, so I'm grasping at straws here.
The code in my .htm file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head>
<title>MySite</title><link href="MySite.css" rel="stylesheet" type="text/css"></head>
<body>
<?php
include("topbar.php");
?>
<div id="content">
<h2>Content Goes Here</h2>
</div>
</body>
</html>
The code in my topbar.php file:
<?php
echo '<div id="container"><div id="header">';
echo '<h1>This is the header.</h1><p class="description">';
echo 'Usually some sort of tagline or description is placed here.</p></div>';
?>
I don't know. I've been searching all over the PHP main site, as well as a few random pages that came up when I used my search engine... I've gone through the EasyPHP FAQ page, and I haven't yet found an answer the would point me in the right direction. Other than attempting to edit the httpd.config file, I haven't gone through any other files created by EasyPHP, mainly because I wouldn't know which ones to try editing, nor which lines, or with what. I just installed EasyPHP last night. I'm glad for any assistance anyone can provide in plain English (please, no one try to show off how cool you are with all your fancy technobabble that I'd have to get out a tech dictionary for, or lengthy examples that would be hard for a newb to read, thanks).
Web server will not process PHP code written in file extension other than .php. Try changing file extension to .php instead of .html.
You can use HTML tags within .php file.
Related
I've found lots of iterations of this question. Most solutions are something like, "take the header that should be on all pages and turn it into an html file, like this:
(One example that I've tried to put in a file called header.php)
<!--PAGE HEADER-->
<div width="100%">
<img src="images/headerimage.jpg" height="240">
</div>
"Then make that header.php. Then insert the file into each page in the site like this" -
<?php include 'header.php';?>
I have tried and tried many different combinations of file paths, existing php code that I know works, examples off of the internet. It doesn't work. When I view the source code, i just see:
<?php include 'header.php';?>
It shows up red (Firefox inspector). As far as I understand it, I should see the imported page header code in its place.
The code hasn't been imported. And none of the code from header.php gets run.
It looks so easy, I have followed tutorials on Youtube, for them it works, for me, nothing. I have tried setting up Apache server and running it (not really knowing what I was doing though).
welcome to StackOverflow!
You can't run PHP in an HTML document. Try to change the file extension from .html to .php
Hope this helps!
Dang! I just dug the reply notifications out of my junk mail. Sorry!
Yes, I think my understanding was that I could just copy all the header code out of my html files and paste it into an empty document and call it header.php. Then I would insert the php include statement in my code, and that should basically look like it did before to the browser. But what it looks like is just the php include statement, and no code is imported.
To answer the question what tutorials I followed, I followed a billion tutorials, and all of it is starting to meld into my confused brain. I've actually been trying to do this for years on and off and have never figured it out.
I tried the link recommended above, and got hung up when I didn't have a directory called mods-enabled in my apache2 directory. I have almost no understanding of what is going on behind the scenes, so when I run into something that doesn't fit the example, I just get lost.
And though a couple of days ago I went through this procedure to run apache and then check if php was working, it looked like apache was working and so was php, but even the mail send php file doesn't work when testing locally, so I think php not being enabled is probably the issue. I just have found it very difficult knowing exactly what that means.
I'm currently beginning with PHP and I wanted to get started with a mini-project for some hands-on experience. Here's the code that I began with:
<html>
<header>
<title>Test</title>
</header>
<body>
<h3>Some example title</h3>
<?php
$randomNumber = rand(1000,9000);
print "Here's a random number: {$randomNumber}.";
?>
<p>Some more text.</p>
</body>
</html>
However, when I saved it as index.php and previewed it on Google Chrome, the PHP part doesn't show up. Can anyone help me realize what I'm doing wrong?
Thanks!
To run PHP code (server side) you need a server, or a 'server-emulator' some of the most commonly used are:
XAMPP
WAMP
Unlike the html in your .php files, the php code must be processed by a server and returned to the browser. I've tested your code with a server and it works like a charm.
After installing one of the above "emulators" you need to (this is a simplified tutorial, check a real tutorial):
place your .php files in the public_html or htdocs folders that are
created in the emulator's folder in your computer.
Turn on your server
go to localhost/your-file-path/index.php
If you only need to test soft code (like what's on yout example) and not develop whole projects use IDONE
PHP is used in the server side, so, you need to install an environment (Apache, PHP) to interpret the PHP. If you use Mac or Windows, you can install Mamp. For unix, you need to install some packages, i'll invite you to see this tutorial: Lamp tutorial.
so i worked on a php project on my localhost and every thing was ok but now, every php file im trying to open just downloads itself (Chrome) or asks if i want to download it (Firefox). i tried to go back to as basic as possible and came out with this index.php file :
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
but the only way i can open it without downloading itself is if im changing it to .html file and than i just don't see the hello world. i already re-installed xampp. i can go to phpmyadmin on my local (if it helps) and thats unfortunately all te useful information i can come up with...any help please?
Make sure your httpd.conf has properly configured php module. And, you have enabled support for php files.
I'm new to PHP and I'm following the PHP tut on w3schools. I am using Eclipse's latest IDE version (3.6 I think). for my script helloDriver.php it functions fine when ran as a php script. it doesn't on my html file especially when I use a similar method to the example from w3schools:
http://www.w3schools.com/PHP/php_forms.asp
This would be my code for helloDriver.php:
<html>
<body>
go
<?php
echo "giga";
?>
power rangers
</body>
</html>
This is my code for homepage.html
<html>
<body>
Hey
<form action="helloDriver.php">
<input type="submit />
</body>
</html>
"Hey" and "go" both display so I know that the php file is being called but I don't know why the echo command doesn't.
Even before this I copied line by line with what the w3schools example was with the exception of welcome.php since that is helloDriver.php
How I access the html file is double clicking it since Eclipse doesn't have any options to run the program. Any ideas what I am doing wrong?
Where are these files hosted? I'm guessing your web server (e.g., Apache or IIS) isn't configured to run .php files through the PHP interpreter, but instead is serving them statically.
I'm having a really hard time working out what your question is.
Some problems with your HTML file are:
You're missing the closing </form> tag
You haven't closed the quotes on your submit button.
The complete markup should probably be more like
<form action="helloDriver.php">
<input type="submit" />
</form>
Another thing that might be the problem, you need to access the PHP scripts through a web server. Have you installed something like XAMPP?
I ended up figuring it out. Thank you guys for help and thanks for suggesting XAMPP.
Installed it from this link (googling XAMPP works just as well):
http://www.apachefriends.org/en/xampp-windows.html#1173
It was straightforward and easy to set up. Set the destination to install on the C: drive. Also stumbled across this tut vid on how to set up a PHP project using PHP, XAMPP, and Eclipse:
http://www.youtube.com/watch?v=hfHEmZXJLgw
I should be able to figure things through trial and error. Thanks again!
IIS is literally sending <?php ... ?> code to the browser rather then executing it.
But, only for the root http://domain.com/index.php file.
All other .php files in that folder and index.php files in subfolders execute as expected.
How can I get my root index.php code to execute?
Update: "index.php" is a Default Document of my Web Site...
alt text http://img412.imageshack.us/img412/4130/defaultdocumentmt9.gif
It seems you have properly configured your handlers.
If you're using <? ... ?> make sure you have
short_open_tag = On
in your php.ini.
I was having this issue and ultimately tracked down the source to be the encoding of the PHP file. Apparently I had set my editor to use Unicode (2-byte unicode, not UTF-8) as the encoding. This causes PHP not to see the <? tags, but the browser seems to be able to read the Unicode file just fine, so viewing source reveals the actual PHP code. (Even though the file had a content-type=utf-8 meta tag!) Saving the PHP file in ANSI or UTF-8 encoding solved the problem.
Lots of debugging went into finding that simple solution, so I thought I'd add it here for anyone else who has this problem.
An interesting side-effect of the problem was that Firefox and Chrome didn't seem load the CSS file. Upon further examination, I found that browsers are supposed to assume the same encoding for CSS as for HTML, unless explicitly specified in the CSS file. Viewing the CSS in Chrome or Firefox would show Chinese characters! This helped lead me to the solution, actually.
IIS 5.1 does not run PHP properly under root directory, but fine in all other folders
Running a WordPress blog in site root using IIS
UPDATED: I have found a few possible workarounds for PHP 5 and IIS 7. If those solutions are not working, please provide more details about your index.php, IIS setup, or try to use IIS 6 compatibility.
Problem with PHP Includes on IIS7
PHP5 set-up - Relative paths for includes and other file references
Have you tried bouncing (stop/restart) IIS? Maybe even restarting the machine? I know there have been times when I've done some IIS configuration changes that I would have sworn should have only needed only a bounce to take effect that didn't get going until a full machine restart.
All though this is an old question, over 11 years later this is still an issue. My work around was to create default.aspx file and perform a redirect from within it. Save the file to the root directory of your website and add default.aspx to the default documents in IIS. Make sure you move it to the top of the list to prioritize it to be processed first. The below code is what I used.
<%# Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected override void OnLoad(EventArgs e) {
Response.Redirect("index.php");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Title Of Your Website Here</title>
</head>