Akshay Pethani
Akshay Pethani

Reputation: 2580

php code have 2 output in same php interpreter using two different HTTP server

I am writing a code in which I have 2 files index.php and register.php.

index.php contains the code for html form which is given below:

<form action="register.php" method="POST">
            <fieldset>
                <legend>Personal Information</legend>

                First Name: <input type="text" name="fname">
                <br>
                <br>
                Last Name: <input type="text" name="lname">
                <br>
                <br>
                <input type="submit" name="submit" value="Submit">
            </fieldset>
</form>

register.php have the following code:

    <?php

//if(isset($_POST['fname']))
{
    $f_name= $_POST['fname'];
}

//if(isset($_POST['lname']))
{
    $l_name = $_POST['lname'];
}

echo $f_name;
echo "<br><br>";
echo $l_name;

?>

I've written the code in PhpStorm and I also have Xampp installed in my windows 10 installed system. I have set 'htdocs' directory of xampp as 'apache_http_server' in 'D:\' drive of my system and also create PhpStorm project in the sub directory of 'apache_http_server' so that I can run my php project using Xampp and PhpStorm IDE. I also set the php innterpreter supplied with Xampp as the default interpreter of PhpStorm so in both case my code uses same interpreter (PHP Version 7.0.4).

Now the problem is whenever I run this project using Xampp it runs without any kind of error and notice. but if I run the same project using PhpStorm IDE using its inbuilt httpserver on port 63342 its gives me following notice as o/p:

Notice: Undefined index: fname in D:\practice\apache_http_server\my_projects\login_form\register.php on line 5

Notice: Undefined index: lname in D:\practice\apache_http_server\my_projects\login_form\register.php on line 10

I also tried to solve this notice by using if(isset()) as per another answers on stackoverflow but it leads to the undefined variable error.

So why this happens ? where is problem occurs? Am I missed to make change in any configuration file? if yes than what changes need or where?

The o/p screenshots using Xampp server and PhpStorm are as follows:

  1. Using Xampp the final O/p:

enter image description here

  1. O/P with notice by PhpStorm's http server:

enter image description here

Upvotes: 0

Views: 129

Answers (3)

Prisha Savaliya
Prisha Savaliya

Reputation: 11

It seems that the problem is in configuration in http server. If you have installed Xampp than you can set the apache server of Xampp as the default http server. You can find step by step guide for integrating Xampp with PhpStorm in following link (the link is from official vendor of PhpStorm):

https://confluence.jetbrains.com/display/PhpStorm/Installing+and+Configuring+XAMPP+with+PhpStorm+IDE

Upvotes: 1

Jenny T-Type
Jenny T-Type

Reputation: 199

Try

echo $_SERVER['DOCUMENT_ROOT'];     //check if the root of the website is the same on both servers

if(!$_SERVER['REQUEST_METHOD']) {
    die("Something went REALLY wrong!!!")    //reinstall your server conf.
} 
if(!$_SERVER['REQUEST_METHOD'] !== 'POST') {
    die("We're not getting this request from POST. abort");
} 

if(!$_POST) {
    die("We're not receiving any data from post.");
} elseif(!$_POST['submit']) {
    die("PHP thinks the form wasn't actually submitted");
} else {
    if($_POST['fname']) {
        //work with your data
    } else {
        echo "<p>There\'s a problem. We're not getting fname from the form</p>";
    }
    ...
    ...
}

I don't have any experience with PHPStorm, but perhaps there could be a problem with the include_path of the PHPStorm built-in server? And more importantly. Are you including something from that include_path?

Upvotes: 2

Jasen
Jasen

Reputation: 12432

you've got different PHP configurations on the two servers, run phpinfo() on both servers and fix the differences.

Upvotes: 2

Related Questions