I am trying to run a simple PHP file, using xampp and phpstorm 2017.1 . First I had lots of problems figuring out how to get this running, and I had a scenario where my php worked, because my php file containing this :
<?php phpinfo(); ?>
worked so I figured it should be working. However when I went to my "slighty more advanced" page to test it out, it was not working. I was trying to post a variable and read it (post to phpself) I used $var_dump to see if anything was received, but to no avail.
<html>
<?php
var_dump($_POST);
?>
<body>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<label for="name">Your Name:</label>
<input type="text" id="name" name="yourname" />
<p><input type="submit" value="Send it!"></p>
</form>
</body>
</html>
The $var_dump gave me back: 'array(0)'. I still have not solved what the reason for this is.
This made me think I might did something wrong with the php installation. After a lot of trying things, I ended up going to run > edit configuration and adding a new PHP Built-in Web Server. I gave this a port, and the root folder of my files and then the weirdest thing so far happened. The structure of my project is a folder Site. Site (the root) contains a folder php, and a file index.html. php contains a file test.php
When I surf to localhost:8081 (the port I put for the built in webserver) I see nothing: I do not get redirected to index.html.
When I surf to locahost:8081/php/test.php it opens my test.php file and it works, including the posting and reading variables.
When I surf to localhost:8081/index.html or localhost:8081/index.html/ it does not work and I see nothing.
When I surf to localhost:8081/randomsomethingnotrelatedatall it works and redirects me to index.html, supposedly because it does not find the folder thus sends me to index.html
I do not understand however why I can't find index.html by just surfing to it. I have another file test.html under the root folder, and that one I can surf to.
Does anyone know what might be causing this?
My goal is to run my website with a local php server for testing, and I seem to be unable to accomplish this. I have looked everywhere on stackoverflow, and could not find helpful posts.
Especially the first problem with my php server apparently working, yet not being able to post variables stuns me.
Thanks in advance!
--------------------- EDIT ----------------------------
For those who were wondering, the post does go through: If i add this check:
if($_SERVER["REQUEST_METHOD"] == "POST") {
var_dump($_POST);
}
then I do get array(0) after submitting the form