Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

PHP echo returning entire PHP file after WWW request

Discussion in 'Scripting' started by Sargon_of_Akkad, May 30, 2013.

  1. Sargon_of_Akkad

    Sargon_of_Akkad

    Joined:
    Jan 16, 2011
    Posts:
    147
    I'm having a problem accessing my SQL database after transferring it to a new server.

    Previously, the scripts were working very well, but I had to migrate it to a new server (I have set up PHP on the new server, and the phpinfo(); function appears to be working successfully).

    I'm calling the PHP page with the WWW class in the same manner as before, and instead of returning an echo value that I am using to determine if the login details were correct or not, it's returning the entire contents of the PHP script, starting from <? onwards until ?>.

    Some Google-fu has turned up this:

    http://answers.unity3d.com/questions/221881/wwwtext-is-returning-entire-indexphp-page.html

    This was caused by the PHP page having HTML on it. My PHP page does not have any HTML on it (as far as I can tell) and the same problem is still occurring.

    Does anyone have any advice at all? I simply do not know where to look now.

    Thanks in advance. :)


    (I have put ---- in fields I do not want public, these are set to the correct values in the actual script)

    PHP:
    <?
    // CONNECTIONS =========================================================

    $host "localhost"//put your host here

    $user "----"//in general is root

    $password "----"//use your password here

    $dbname "----"//your database

    mysql_connect($host$user$password) or die("Cant connect into database");

    mysql_select_db($dbname)or die("Cant connect into database");

    // =============================================================================

    $unityHash anti_injection_login($_POST["myform_hash"]);

    $phpHash "hashcode"// same code in here as in your Unity game

    $useremail $_POST["myform_nick"];

    $userpassword $_POST["myform_pass"];

    if(!
    $nick || !$pass
    {
       echo 
    "Not enough data";

    else 
    {
        
    $SQL "SELECT * FROM database WHERE ouremail = '" $useremail "'";

        
    $result_id = @mysql_query($SQL) or die("DATABASE ERROR!");

        
    $total mysql_num_rows($result_id);

        if(
    $total
        {
            
    $datas = @mysql_fetch_array($result_id);

            if(!
    strcmp($userpassword$datas["userpasswordfield"])) 
            {
                echo 
    "login okay";
            } 
            else 
            {
                echo 
    "Incorrect details";
            }
        } 
        else 
        {
            echo 
    "Incorrect details";
        }
    }

    // Close mySQL Connection

    mysql_close();

    ?>
     
  2. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    974
    The server isn't parsing the file as PHP for some reason. I would guess the server isn't configured for PHP, but you said you have tried phpinfo() and it works.

    Does the file have the .php extension?
    What's the difference between the file that works and the one that doesn't?
    What happens if you only put phpinfo() in the file that doesn't work? Is it still returned as pure text?
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    And try

    PHP:
    <?PHP
    instead of
    PHP:
    <?
     
  4. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,617
    See if the phpinfo() test you did works from the same directory/filename as the file that's not working. Some servers have per-directory PHP configurations.

    It's perfectly valid for PHP and HTML to be in the same file, by the way.