Apache Server Downloads .php Files in Subdirectories - php

So I've been searching all over the internet for a solution to my problem and I've tried just about everything I could find, but still nothing is working.
My problem is that when I open a .php file in chromium by using:
localhost/filename.php
it works fine. If I put the file in a subdirectory and access it as such:
localhost/subdirectory/filename.php
it works fine as well. The problem comes when I try to access the .php file in the subdirectory from another file. For example I have an entire project located under:
var/www/test
with the index.html sitting in that folder and then the .php scripts in a folder located at:
var/www/test/php_scripts
In the HMTL file there is a form that sends the form data to one of said .php scripts and when I click the submit button it downloads the .php script instead of navigating to it and executing in the browser.
I tried moving the script into the "test" folder so it was with the index.html file and that didn't fix anything. If I place everything in:
var/www
it all works fine. But I don't want to do that because then I have to deal with a cluttered mess of files which no one likes doing...
I did search for the past couple hours all over stack exchange and other sites and couldn't find anything that worked. If this is a duplicate question then please point me in the direction of the answer, if not, hopefully one of you jedi coders can solve my headache.
Thanks,
Zak

It sounds like you need to look at the action part of your html form.
Make sure that the action starts with a /
Example
<form action="/php_scripts/script_name.php>

Related

PHP can't file contact.html, but it shouldn't exist? (Smarty Engine)

I've got a legacy PHP project to fix a thing or two. I've downloaded it via FileZilla and served it on my local machine with a local copy of the database. The project is exactly the same with the live one, yet the live one can open the url/contact.html but on my machine it says no such file is found. All other pages go for url/categories/ or url/products/ so I've tried altering the url but no use.
All the other pages within the site are simple: one .php controller one .php model and one .tpl smarty template view. Requiring no .html at all. But this one is somehow different. The .htaccess file is exactly the same as the live version. I've tried adding a rewrite rule to direct every .html to .php but didn't work. I'm lost and out of options, please help? It doesn't even have to be an answer,"Try looking into that" would work too.
I'm working via XAMPP on windows, and I've configured the https:// to http:// on my project but that's all. Even hidden files are checked and confirmed.
have checked that contact.html is a static file (like a real existing html file?)
is there some kind of "routing" within the PHP of the project? If there is route urls might be really anyware.. in the mysql database, redis, a json file and whatnot.. have seen them all.
try to debug where and how it works on the "production" server by using some logging to a file edit the file through filezilla and log to a 'mylog.log' file until you find out what is going on.. or if the site is not used all the time by clients - you can just try to echo stuff to figure out how this exact /contact.html works

Website hosted on 1and1 only display index.php

I recently suscribed to a 1and1 hosting contract. I've been having issues to display my website, so I tried to put some very basic pages online in order to tell wether the issue was in my file or on the server side.
The homepage is named index.php and has a link to another page (page1.html) that is supposed to display a "Hello World".`
Clique
The homepage is online but there are some issues.
The homepage only works when it's called index.php and doesn't work when it's called index.html.
When I click on "Clique", the url changes to mywebsite.com/page1.html but the content is still "Clique" while it should be "Hello World".Also, the CSS file isn't read.
I've read a lot of threads dealing with similar issues and apparently it might be a problem with the .htaccess file. I don't have a .htaccess in the folder where my files are and I don't know much about how it works. Also, the CHMOD is 705 for both files.
Maybe try the 1and1 support for this issue.
I don't think this is the right place to ask.
Do you have root access, or just FTP.
If there is no .htpasswd, try uploading one.
A generator which will help you is just one google away.

Trying to run a PHP script in and HTML document with Apache

I am very very new to PHP, but I have looked everywhere (it seems) and cannot figure out how to run a simple PHP script on an HTML webpage using Apache. I am pretty sure I am doing something wrong or missing a step. I have a contact form. I have the .html with action=example.php.
<form name="htmlform" method="post" action="../../../../../../xampp2/php/www/html_form_send.php">
I tried putting the html_form_send.php file in both the php/www and the htdocs folder.
Do I need to put the .html file in a different folder as well?
I tried changing the httpd.conf, but that did not seem to work either.
Oh, and Apache is running. What am I missing? I would really appreciate your help! Thank you!!
UPDATE:
Thank you all for your help! I really appreciate it. I decided to use a different contact form, and it works just fine. I am still not exactly sure what all was wrong with the other one. However, I really appreciate the help and your answers did help clear up some questions I had. Thanks!
Inside the xaamp/htdocs
create folder and put all the .html and .php files
Then in .html file give form action='html_form_send.php'
You may not run php on a html page.
PHP would run if you have a .php file having the php code on the server.
In XAMPP :
Save your .php in htdocs folder.
Start the XAMPP server and open the .php from the browser using : localhost/<file_name>.php
You may also create folders inside htdocs to store php files and later open it as localhost/<folder_name>/<file_name>.php from your browser.
Also form form action just use ./file.php to redirect to file.php found in same folder or ../<folder>/file.php to redirect to file.php in another folder present in the parent directory.
You can not put php script on a html page. You need to create a new page and make it a php page of its own.
From your question i see you're using xamp. Create two different pages Eg Form_Receive.php (which will receive all the information sent from your form) and a different page to hold your form Eg. From_Post.php(which will hold the form and send all the information via POST or GET method.
Also be mindful of the url of the "form action" in your form. Once it points to the wrong directory or file, all information will be posted wrongly.

WAMP: Index.php executes/runs immediately when selecting the directory it is in

I had a little, slightly annoying problem that was an easy fix but I didn't understand why it took place.
I have a several folders in ../wamp/www/- and in one of them I had a file, that I had created, named index.php. When I clicked on the other directories I could browse through the normal list where I saw all the files, but when I opened the folder where the file Index.php was it executed immediately and I never saw what was in the folder. Instead I had to manually change the url to open other files in that directory.
I deleted index.php and half expected it to run some other .php-file in that directory, but didn't.
I'm aware of that there is a index.php-file in the www-directory (the comments in French though), which clearly is part of the WAMP system I downloaded, but having seen tutorials where people use index.php I'd have expected someone to mention this potential problem.
This is not a problem!
This is how web servers work.
To be specific there is a setting in the Apache config that tells Apache the names of files that it should run Automatically if no actual file is specified in the URL
Specifically this line in httpd.conf
DirectoryIndex index.php index.php3 index.html index.htm
It is normal that a web server will run any of these files if it sees them when only the directory is specified on a URL.
And before you consider changing it, dont. Almost everything you will come accross EXPECTS this to be the case.

php code displaying on web page instead of working behind the scene

I have an index.html in my wampserver www directory. On this html, there is a link for a user to upload file. When I hit the link, I select files to upload but instead of the uploadmanager.php which i have tested in my eclipse debugg environment to work, it displays the some part of the code on the web page without doing anything thing. This is not what I expect. Can someone please tell me what is wrong? Thank you.
sound like you are using php-short-open-tags (<? instead of <?php) without enabling this in your php.ini. change your php.ini or use the standart open-tags to solve this.
Are you sure you enabled PHP in WAMP?
Try creating a new uploadmanager.php file directly in wamp/www (or whatever subdirectory) and paste the code from your tested uploadmanager script into the new file. Then try to run it in WAMP.
I think it is a permissions problem. I copied an index.php file into a c:/wamp/www/subdirectory and it only displayed the code. Once I created a new index.php file and pasted the contents of the old file into it, it worked perfectly.
Are you posting to the uploadmanager.php page? Are you getting an error or just seeing the code? Can you post the code from the index.html page that handled the form and the part of the php code you're seeing for us to look at?
Every now and then I have Apache serving the .php as downloadable files instead processing them on the server, but only with random requests.
Some reasons, why this might happen, are
PHP misconfiguration
PHP-files in a directory without execute rights
wrong content type sent
timeout from script execution
In my situation the last bullet is the most dangerous, but luckily it seems to show up only immediately after modifying some of the .php files. I haven't tracked the problem any deeper yet, but it seems to relate some filesystem level operations (as the disk I/O is a bottleneck) and presents itself only in testing env.

Categories