I have started the book ‘Build your own database driven website using PHP & MySQL’.
Following the books instructions I have installed separately,MYSQL, PHP 5.3.2 and Apache 2.2.15 over Windows 7
Yesterday, as soon as I stopped Skype using port 80, and changed the windows host file to include: 127.0.0.1 localhost connecting the localhost, worked. But not today.
The books ‘Connect’ example returns ‘Database connection established.’ inferring MySQL and PHP and Apache are all running OK.
But connecting to local host fails and I just get the message ‘Index of /’ instead of ‘It works’
:tup: I think that the localhost location is the point of contention here. So, was localhost redefined (from htdocs)? Is the file requested in the htdocs folder? Has the DirectoryIndex been changed?
If I run a php file like the book’s example today.php it runs fine and produces the correct result: Today’s date (according to this web server) is Sunday, March 21st 2010.
That’s because your today.php is not the index file or defined as a DirectoryIndex.
If you rename today.php to index.php, your page will load instead of the default directory listing page (which is what you’re seeing now)\
The DirectoryIndex value is responsible for finding a page to load when a directory is visited. If there’s no available page to act as that default page, the generic directory listing appears.
in order for a page to load by going to http://localhost, you either need to have a page named index.php or include the file name for the DirectoryIndex option.
According to the book and what happened yesterday, when everything is running correctly, when I go to: http://localhost/ i should have a message ‘It works’ confirming the browser has found its way to the default index.php
I have just discovered that if I stop Apache running and I go to http://localhost I get the message: Firefox can’t establish a connection to the server at localhost
If I do the same with Apache running then I get: Index of /
This makes me think that I am connecting to my localhost, but just not finding the default index.php in spite of having the entry in httpd.conf:
The first line will CHANGE the default page to index.php (then index.html if index.php does not exist). The second line will turn off the Directory listing and is, aside from a good thing to do on a production server, will be a good test that you’re in the correct directory.
Remove the <IfModule dir_module> and </IfModule>, save and restart Apache.
What I was asking for you to do was to create a nameless text file with an .htaccess extension in your htdocs directory. That’s the EASY way to do the above for your localhost files.
Hi, I have re-installed Apache and now I can see the localhost great! Now I can’t get the $_GET function.
In Kevin Yang’s book the first example uses an html file to pass a ‘name’ variable to a php file. The main part for the html file is:
<a href=“welcome1.php?name=Kevin”>Hi, I’m Kevin!</a>
and for the main part of the welcome1.php:
<?php
$name = $_GET[‘name’];
echo 'Welcome to our web site, ’ . $name . ‘!’;
?>
The result I should get is: Welcome to our web site, Kevin!
What I actually get is: Hi, I’m Kevin!
The frustrating part is, more complicated (for me) examples that pass variables using forms do work. Just not the $_GET command.
I read something about turning on 'register_global’s but that did on work.
Well, both files are named “welcome1” and it sounds like you’re seeing welcome1.html when you’re expecting to see welcome1.php
Are you certain the link is OK? I can’t think of a reason why Apache would send a request for a PHP file to an HTML file unless you added some sort of directive somewhere, and I imagine you would remember if you had done that.
And please DON’T rely on register globals. It may save you a few lines of code, but it introduces security risks (as well as other issues). IMHO not worth it.
If you’re sure you’re on the PHP page, try adding a
var_dump($_GET);
to see if it looks like you expect it to.
That’s a basic PHP setup for a form so I’ll have to ask you to post the CODE of your php script. I’m sure Kevin knows how to do that correctly so I’ll have to compare your script’s code with Kevin’s to point out the errors (or show alternative code).
Mitt’s advice re register globals is spot on! DON’T use those as they are a MAJOR security risk!