Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMiha Vičič
10,262 PointsServer or php problem
Hello! I have a problem (probably with my MAMP setup?). When i open the index.php file it loads up normally but when I click on a link in shows me only the php code in that file.
7 Answers
thomascawthorn
22,986 PointsIt sounds like you're either:
- not adding .php to the end of your filename
- you're linking to the file instead of the server e.g. /doc/webstuff/file.php instead of localhost/file.php
Stephen Little
8,312 Pointsthat's why I was asking to see the code for the link :)
Miha Vičič
10,262 PointsI think I got the code right (i tested with Mike T-shirt site). The page loads normally. Both when i'm testing the links the browser shows me only the php code :/
Stephen Little
8,312 Pointsyou should post the code that your are trying to run so that members can see it. This allows people to see what your trying to do and maybe see the errors.
Stephen
thomascawthorn
22,986 PointsThe only reason you would get php code printed to the screen is if you're not telling the server "hey, this is a php file". This is done by making sure all your files end in .php and you're using the server to view them.
You might have correctly navigated to the home page (localhost/), but your links may be set up incorrectly. If you're using MAMP, you should be browsing localhost. Take a look at the url of the broken page - what does it say? It should look like 'localhost/some-page.php' or similar.
Miha Vičič
10,262 PointsYes I thought the same problem I checked and rechecked. that's why I use the final version of Shirt 4 Mike. I check the localhost directory (http://localhost:8888) an it opens the Shirt 4 Mike but when I click on a link (http://localhost:8888/shirts/105/) the site doesn't load
thomascawthorn
22,986 PointsHave you got to the point in the project where you've started to use rewrite rules in a .htaccess file?
If you've used the final version and haven't set up the rewrite rules etc, this might be the cause of your issues.
Stephen Little
8,312 Pointscheck to see if your .htaccess file looks like this maybe.
RewriteEngine On
RewriteRule ^shirts/$ /shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1
RewriteRule ^receipt.php$ /receipt/ [R=301]
RewriteRule ^contact.php$ /contact/ [R=301]
RewriteRule ^shirts.php$ /shirts/ [R=301]
RewriteRule ^(shirts/[0-9]+)$ /$1/ [R=301]
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^shirt.php$ /shirts/%1/? [R=301]
Miha Vičič
10,262 PointsI finally found the problem :D
It seems I didn't correctly composed the links (in the "inc" folder) on my page. Thanks all for the help I hope one day I can give you the needed advice. :)
Some Person
4,218 PointsHi Miha Vičič
What changes did you make in the "inc" folder to make it work?
My site loads in localhost. displays everything. When I click the t-shirts for eg: server/mikeshirts/shirts/131/ I get 404 error.
Some Person
4,218 PointsIt just says The requested URL /shirts/shirts.php was not found on this server.
Stephen Little
8,312 PointsStephen Little
8,312 PointsCould you show us the code that makes up the link? that would be a great help in figuring this out :)
cheers! Stephen