I apologize if I asked this question before - I may have.

I am hearing two sides to this issue:

  1. .php files WILL display in a web browser
  2. .php files will NEVER display in a web browser

I find this very confusing. I am watching video tutorials and people are creating then saving a file as .php (which primarily contains html with a bit of php also). They then display the .php page in their browser.

When I try renaming a .html file to .php and load it, the entire page is blank and no source code is available.

I realize that .php is server-side, but how are people getting this to run in this manner?

I need to be able to convert a .html file to .php and run it.

Thanks,
Matthew

in order to view php files (which are proccessed server side) you need to be running some kind of webserver

I have my files on a hosting service company running Apache.

Do you mean that in order for me to see them I need to be running a local server? I have a server on my machine but that does not help really - I need these files to be live on the Web via the hosting company.

can you post some code then

if error reporting is disabled and you've got something bad thats the effect you'd get

This is the code for the .html (Same code as when I save it as .php). Please excuse the messy code, I am in the middle of many things concerning this page.

`

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<!--Used to clear form upon submit-->
<script>
function clearForms()
{
  var i;
  for (i = 0; (i < document.forms.length); i++) {
    document.forms[i].reset();
  }
}
</script>

    <title>Sliding Login Panel with jQuery 1.3.2</title>
    <meta name="description" content="Demo of a Sliding Login Panel using jQuery 1.3.2" />
    <meta name="keywords" content=" " />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />    

    <!-- stylesheets -->
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="css/slide.css" type="text/css" media="screen" />

    <!-- PNG FIX for IE6 -->
    <!-- http://24ways.org/2007/supersleight-transparent-png-in-ie6 -->
    <!--[if lte IE 6]>
        <script type="text/javascript" src="js/pngfix/supersleight-min.js"></script>
    <![endif]-->

    <!-- jQuery Slide -->
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <!-- Sliding effect -->
    <script src="js/slide.js" type="text/javascript"></script>
    <script>
      function validateEmail(email) { 
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
      } 


      $(document).ready(function() {
        $('.error_message').hide();
        $('#first_val').val(Math.floor(Math.random()*11));
        $('#second_val').val(Math.floor(Math.random()*11));
        $('#loadingGif').hide();

      $('.bt_register').click(function(e){
        $('#loadingGif').show();

        e.preventDefault();
        $('.error_message').hide();
        $('#email_error').html("Please enter a valid email.");
        $('#user_error').html('Required');

        error=false;

        if ($('#user').val().length<1) {
          error=true;
          $('#user_error').show();
         }
         if ($('#email').val().length<1 || !validateEmail($('#email').val())) {
          error=true;
          $('#email_error').show();
         }
         if ($('#pass').val().length<8) {
          error=true;
          $('#pass_error').show();
         }
         if ($('#city').val().length<1) {
          error=true;
          $('#city_error').show();
         }
         if ($('#pass').val() != $('#confirmpass').val()) {
            error=true;
            $('#confirmpass_error').show();

          }

          var disallowed_characters=/www|http|@|com|\./;

          if (disallowed_characters.test($('#city').val())) {
            error=true;
            $('#city_error').show();
          }
          if (disallowed_characters.test($('#company').val())) {
            error=true;
            $('#company_error').show();
          }

          $.getJSON('ajax.php?username='+$('#user').val(), function(data) {
            if (data.error) {
                error=true;
                alert('An error has occured');
            } else {
                if (!data.isUnique) {
                    error=true;
                    $('#user_error').html('This username is already taken.');
                     $('#user_error').show();
                }
            }


          $.getJSON('ajax.php?email='+$('#email').val(), function(data) {
            if (data.error) {
                error=true;
                alert('An error has occured');
            } else {
                if (!data.isUnique) {
                    error=true;
                    $('#email_error').html('This email is already being used.');
                     $('#email_error').show();
                }
            }


               if ($('#equals_val').val() != (parseInt($('#first_val').val()) + parseInt($('#second_val').val()))) {
                    error=true;
                    $('#captcha_error').show();
                }      

              if (!error) { 
                console.log('submit');
                $('#member-signup').submit();

              }
              $('#loadingGif').hide();
              });
          });
      })
    })
  </script>



    <!--Favicon-->
    <link rel="icon" href="favicon.ico" type="image/x-icon"/>
        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>

<!--Country Dropdown-->

<!-- <msdropdown> -->
<link rel="stylesheet" type="text/css" href="css/msdropdown/dd.css" />
<script src="js/msdropdown/jquery.dd.min.js"></script>
<!-- </msdropdown> -->
<link rel="stylesheet" type="text/css" href="css/msdropdown/flags.css" />
<style>
.error_message {
  color: #cf1717; 
  font: Arial; 
  font-size: 14px; 
  display:block;
}
#panel {
    height: auto;
}
</style>

</head>


<!--Used to clear form upon submit-->
<body "onUnload="clearForms()">


<?php

define('DB_HOST','');
define('DB_NAME','');
define('DB_USER','');
define('DB_PASSWORD','');

$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL:" . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL:" . mysql_error());


function NewUser()
{  
    $userName = $_POST['user'];
    $email = $_POST['email'];
    $password =  $_POST['pass'];
    $countries = $_POST['countries'];
    $city =  $_POST['city'];
    $company = $_POST ['company'];
    $state = $_POST ['state'];//Added 11/3/2014

    $query = "INSERT INTO Table4 (userName,email,password,countries,city,company,state) VALUES ('$userName','$email','$password','$countries', '$city','$company','$state')";
    $data = mysql_query ($query)or die(mysql_error());
    if($data)
    {
    echo $state
    //echo "YOUR REGISTRATION IS COMPLETED...";
    }
}

function SignUp()
{
    if(!empty($_POST['userName']))   //checking the 'user' name which is from Sign-Up.html, is it empty or have some text
    {
        if ($_POST['equals_val'] != ($_POST['first_val'] + $_POST['second_val'])) {
            echo "CAPTCHA IS NOT CORRECT";
        } else {
            $query = mysql_query("SELECT * FROM WebsiteUsers WHERE userName = '$_POST[user]' AND pass = '$_POST[pass]'") or die(mysql_error());

            if(!$row = mysql_fetch_array($query) or die(mysql_error()))
            {
                NewUser();
            }
            else
            {
                echo "SORRY...YOU ARE ALREADY REGISTERED USER...";
            }
        }
    }
}
if(isset($_POST['submit']))
{
    SignUp();
}
if (isset($_POST['type'])) {
    if ($_POST['type'] == "login") 

}
?>

<!-- Panel -->
<div id="toppanel">
    <div id="panel">
        <div class="content clearfix">
            <div class="left">
                <h1>Welcome to RedLineDown</h1><div style="color:#FFFFFF;">RedLineDown</div>

                <p class="grey">###</p>

            </div>
            <div class="left">


                <!-- Login Form -->
                <form class="clearfix" action="#" method="post">
                    <h1>Member Login</h1>
                    <input type="hidden" name="type" value="login" />

                    <label class="white" for="log">Username:</label>
                    <input class="field" type="text" name="log" id="log" value="" size="23" />

                    <label class="white" for="pwd">Password:</label>
                    <input class="field" type="password" name="pwd" id="pwd" value="" size="23" />

                    <div class="clear"></div>
                <input type="submit" name="submit-form" value="Login" class="bt_login" />    
                </form>
            </div>
            <div class="left right"> 


                <!-- Register Form -->
                <form method="POST"  id="member-signup" action="dbConnect100.php">
                    <h1>Not a member yet? Sign Up!</h1>
                    <input type="hidden" name="type" value="signup" />
                    <!-- Username Field -->              
                    <label type="grey" for="signup">Username:</label>
                    <input type="field" type="text" name="user" id="user" value="" size="23")/><span class='error_message' id='user_error'>Required</span>

<!-- Email Field(s) -->  
<label type="grey" for="email">Email:</label>
<input type="field" type="text" name="email" id="email" value="" size="23" /><span class='error_message' id='email_error'>Please enter a valid email.</span>

<!-- Password Field -->
<label type="grey" for="email">Password:</label>
<input type="password" name="pass" id="pass" value="" size="23" /><span class='error_message' id='pass_error'>Password must be at least 8 characters long.</span>

<!-- Password Field -->
<label type="grey" for="email">Confirm Password:</label>
<input type="password" name="confirmpass" id="confirmpass" size="23" /><span class='error_message' id='confirmpass_error'>Passwords do not match.</span>

<!-- Country Dropdown -->

<!-- City Field -->  
<label type="grey" for="email">City:</label>
<input type="field" type="text" name="city" id="city" size="23" />

<!-- State Field --> 

<span class='error_message' id='city_error'>Please enter a valid city.</span>

<!-- Company Field -->
<label class="white" for="email">Company:</label>
<input class="field" type="text" name="company" id="company" size="23" />
<span class='error_message' id='company_error'>Please enter a valid company name.</span>

<!--Mona Captcha-->
<!--<label class="white" for="captcha">Are you human:</label><br>
<input class="field" type="text" name="first_val" id="first_val" style="width: 30px;" size="3" disabled/> + &nbsp;
<input class="field" type="text" name="second_val" id="second_val" style="width: 30px;" size="3" disabled/> = &nbsp;
<input class="field" type="text" name="equals_val" id="equals_val" style="width: 30px;" size="3" /><br>
<span class='error_message' id='captcha_error'>Captcha is not correct.</span>-->


<!--Google reCaptcha-->
<?php

require_once('recaptchalib.php');

// Get a key from https://www.google.com/recaptcha/admin/create
$publickey = "6LeqvAMTAAAAAIVbXMpKzxjtB_Cb07DmT_43sQJD";
$privatekey ="6LeqvAMTAAAAAC41AY8gVnzX7Sb5jY06HtrpcYq3";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);


?>

<input type="submit" name="submit-form2" value="Register" class="bt_register" />
<img src="loading.gif" id="loadingGif">  
<!-- Captcha End-->




                </form>

            </div>
        </div>
</div> <!-- /login -->    

    <!-- The tab on top -->  
    <div class="tab">
        <ul class="login">
            <li class="left">&nbsp;</li>
            <li>Hello Guest!</li>
            <li class="sep">|</li>
            <li id="toggle">
                <a id="open" class="open" href="#">Log In | Register</a>
                <a id="close" style="display: none;" class="close" href="#">Close Panel</a>           
            </li>
            <li class="right">&nbsp;</li>
        </ul> 
    </div> <!-- / top -->

</div> <!--panel -->

    <div id="container">
        <div id="content" style="padding-top:100px;">

        </div><!-- / content -->      
    </div><!-- / container -->
</body>
</html>

`

define('DB_HOST','');
define('DB_NAME','');
define('DB_USER','');
define('DB_PASSWORD','');

$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to >MySQL:" . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL:" . mysql_error());

you've got a db connection command but no connection set up
you didnt put any values into your definitions

Member Avatar for diafol

I think the confusion is about allowing php code to run.

As a rule Apache will not run any php in files without certain extensions like ".php". So if you want to run php without messing with Apache setup, just use the .php extension for your files.

Naming files with .html, .htm etc is fine as long as they don't contain php code as Apache won't run it.

You can set up Apache to run php code inside named extensions like .html etc, but I never understood the need for this (these days at least). Prettifying urls (e.g. leaving off extensions or "mod rewriting") pretty much obviates the need for it.

You will not be able to see the raw PHP code in the browser - usually just the effect of it via html output.

**1.php files WILL display in a web browser
2.php files will NEVER display in a web browser****

                           **example**



                        <html>
                                <body>
                                    <?php echo "Hello"; ?>
                                </body>
                        </html>

if the source code above is processed, right click on the page, and hit on view source, you will only see

                        <html>
                                <body>

                                </body>
                        </html>

html-> source code will be processed on the computer user/client's side through chrome, ie, mozilla

php-> source code will be processed on the server, example apache, iis

you might like to use pdo

I know its old, but, it popped in "Articles recomended for me" so I looked at it

Now that the display errors are repaired
You might like to consider
1. Html5 not xhtml , easier, less extraneous crap
2. Replacing mysql with mysqli, or PDO ; mysql is deprecated(1) and a little dangerous

(1.) Deprecated: adjective, :: will cease to function in the near future with catastrophic results for the user and humor for everyone else

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.