0

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

Runey
  • 179
  • 1
  • 10
  • So even after you submit the form your array is empty? try replacing `action=""` with `action=' '`... you do not need to call the page again with `PHP_SELF` it is unnecessary. – MinistryOfChaps Jul 19 '17 at 10:11
  • Also, I believe your project is in a folder called `php` so that is why you can only access your index by going to `localhost:8081/php/index.php`...if you go to just `localhost:8081/index.php` you are not actually calling any files in your project folder, hence the error. – MinistryOfChaps Jul 19 '17 at 10:19
  • Hi, thanks for the quick response. I replacing the action as you said, but it has the same result: after submitting the form I still get an empty array. As for your second comment: that is not true, my project is in a folder called Site, which before I had the webserver I needed to type (http://localhost:63342/Site) would redirect me to index.html. – Runey Jul 19 '17 at 10:29
  • No problem, This does sound like a PHP setting config issue. Have a look [at these possible solutions](https://stackoverflow.com/questions/9914979/php-post-not-working) as they seem to cover the usual issues that occur with `$_POST` not being set when they should be. Yes if you have the folder name only in your link it will usually go to your index page. If I'm understanding you correctly, you are saying localhost:63342/index.php should redirect you to your index.php in your Site folder? – MinistryOfChaps Jul 19 '17 at 10:38
  • I editted my post, adding a check to see if the server requested a post, this maybe clarifies the problem more – Runey Jul 19 '17 at 10:39
  • Is upload_max_filesize and post_max_size set in your php.ini file? In my own php.ini file they are set to the following: `upload_max_filesize = 20M post_max_size = 20M` – MinistryOfChaps Jul 19 '17 at 10:44
  • I'm taking a look at it. Exactly (index.html though) before I was using a php webserver I could surf to my home page by navigating to http://localhost:63342/Site/ or http://localhost:63342/Site/index.html . when this worked, php did not work. Then I went to the phpstorm Run/Debug configurations, added a php built in webserver there and that fixed my php file. This is however, what messed up my navigation. e.g. surfing to localhost:8081 did not redirect me to index.html, while surfing to localhost:8081/randomcharacters did – Runey Jul 19 '17 at 10:44
  • post_max_size is not defined, the others are. I tried copying your exact settings but this does not fix the problem either. It had been a long time since I used php, so I suspect I may have done something basic wrong. – Runey Jul 19 '17 at 10:48
  • I wouldn't be familiar with PHPstorm unfortunately so I couldn't give you any help that you wouldn't of seen anywhere else on SO and other sites when you checked the issue. I'd say having another run through how you set up PHPStorm and comparing each step to other persons would be a good direction to go to solve the problem. – MinistryOfChaps Jul 19 '17 at 10:52
  • I'll give that a try: deinstall phpstorm, deinstall xampp and start from scratch. Hopefully that will work! thanks for your time – Runey Jul 19 '17 at 10:55
  • Sounds like a good idea, no problem! – MinistryOfChaps Jul 19 '17 at 10:57

0 Answers0