2017-01-13 168 views
-2

我还在使用PHP,所以我有一个问题,当我运行这段代码,我的浏览器中的PHP显示。 我试着保存文件。 HTML,这是结果为什么php代码在我的网站页面显示?

File.html

,如果我试图挽救它.PHP,这是结果

File.php

,这里是我的代码

谁能帮助我 ?!

代码:

<?php 

include_once ("php_includes/check_login_status.php"); 

//If user is already logged in, header it away 

if ($member_ok == true) 

{ 
    header ("location: Member.php?u=".$_SESSION["Username"]); 

    exit(); 

} 

?> 

<?php 

//AJAX calls this part to be executed 

if (isset($_POST["e"])) 

{ 
    $e = mysqli_real_escape_string($db_conx, $_POST['e']); 

    $sql = "SELECT MmeberID, Username FROM Member WHERE Email='$e' AND activated='1' LIMIT 1"; 

    $query = mysqli_query($db_conx, $sql); 

    $numrows = mysqli_num_rows($query); 

    if ($numrows > 0) // The member exists 

    { 

     while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) 

     { 

      $id = $row["id"]; 

      $u = $row["username"]; 

     } 

     $emailcut = substr($e, 0, 4); //Cut the first 4 character of their mail 

     $randNum = rand(10000,99999); // generate 5 digits random number 

     $tempPass = "$emailcut$randNum"; //concatinate these two var to make the new random pass 

     $hashTempPass = md5($tempPass); //hash this new random password 

     $sql = "UPDATE Member SET temp_pass='$hashTempPass' WHERE Username='$u' LIMIT 1"; //Update the member table with the new password 

     $query = mysqli_query($db_conx, $sql); 

     $to = "$e"; 

     $from = "[email protected]"; 

     $headers ="From: $from\n"; 

     $subject ="yoursite Temporary Password"; 

     $msg = '<h2>Hello '.$u.'</h2> 

     <p> Somebody recently asked to reset your Facebook password. Didnt request this change? If you didnt request a new password.</p> 

     <p>We can generated a temporary password for you to log in with, then once logged in you can change your password to anything you like.</p> 

     <p>After you click the link below your password to login will be:<br /><b>'.$tempPass.'</b></p> 

     <p><a href="http://www.yoursite.com/forgot_pass.php?u='.$u.'&p='.$hashTempPass.'">Click here now to apply the temporary password shown below to your account</a></p> 

     <p>If you do not click the link in this email, no changes will be made to your account. In order to set your login password to the temporary password you must click the link above.</p>'; 

     if(mail($to,$subject,$msg,$headers)) 

     { 

      echo "success"; 

      exit(); 

     } 

     else 

     { 

      echo "email_send_failed"; 

      exit(); 

     } 
    } 

    else 

    { 

     echo "no_exist"; 

    } 

    exit(); 

} 

?> 
<!DOCTYPE html> 

<html> 

    <header id = "PageHeader"> 

     <script type="text/javascript" src = "Index.js"> </script> 

     <meta charset="utf-8"> 

     <!-- The website title --> 

     <TITLE> 8 BITES </TITLE> 

     <!-- Include the CSS file with this HTML file--> 

     <link rel="icon" type="iamge/x-icon" href="C:/Users/hp1/Desktop/Website/Pictures/Logo.jpg"> 

     <link rel="stylesheet" type="text/css" href="Style.css"> 

     <img id = "HeaderLogo" src = "C:/Users/hp1/Desktop/Website/Pictures/T_Logo.jpg" alt="Logo" style="width:46px; height:46px;"> 

     <h2 id = "HeaderQuote"> 8BITS </h2> 

    </header> 

    <body id ="ForgetPasswordPageBody"> 

     <?php include_once("template_pageTop.php"); ?> 

     <h1> Generate temporary log in password </h1> 

     <p> Note: This password will last only for 24 hours. In orde to obtain a new valid password please contact us! </p> 

     <form id = "ForgotPassForm"> 

      <div id = "Step1"> Step 1: Enter your Email! </div> 

      <input id = "Email" type="Email" onfocus="_('status').innerHTML ='';" maxlength="100"> 

      <br/> 

      <button id = "ForgotPass" onclick="ForgotPass()"> Generate </button> 

      <p id = "status"> </p> 

     </form> 

     <script> 

      function ForgotPass() 

      { 

       var email = ("Email").value; 

       if (email == " ") 

       { 

        _("status").innerHTML = "Type your Email address!"; 

       } 

       else 

       { 

        _("ForgotPass").style.display = "none"; 

        _("status").innerHTML = 'Please wait...'; 

        var ajax = ajaxObj ("POST", "forgot_pass.php"); 

        ajax.onreadystatechange = function() 

        { 

         if (ajaxRetrun (ajax) == true) 

         { 

          var response = ajax.responseText; 

          if (response == "success") 

          { 

           _("ForgotPassForm").innerHTML = '<h3> Step 2. Check your Email inbox please </h3>'; 

          } 

          else if (response == "no_exist") 

          { 

           _("status").innerHTML = "This is Email is not registered!"; 

          } 

          else if (response =="email_send_falied") 

          { 

           _("status").innerHTML = "Mail falid to be sent!"; 

          } 

          else 

          { 

           _("status").innerHTML = "An unknow error occured!"; 
          } 

         } 
        } 

        ajax.send ("e=" +e); 
       } 

      } 

     </script> 

     <?php include_once("template_pageBottom.php"); ?> 

    </body> 

    <footer id = "PageFooter"> 

     <div id = "Info"> 

      <ul id = "InfoLinks"> 

       <li> <a href ="AboutPage.html" target="_blank"> About </a> </li>       

       <li> <a href ="HelpPage.html" target="_blank"> Help </a> </li> 

       <li> <a href ="TermsPage.html" target="_blank"> Terms </a> </li> 

       <li> <a href ="PrivacyPage.html" target="_blank"> Privacy </a> </li> 

       <li> <a href ="CookiesPage.html" target="_blank" > Cookies </a> </li> 

       <li> <a href ="AddsInfoPage.html" target="_blank"> Adds Info </a> </li> 

       <li> @2017 8Bits </li> 

      </ul> 

     </div> 

     <div id = "Media"> 

      <ul id = "MediaLinks"> 

       <li> <a href ="https://www.facebook.com/MIU8BITS/" target="_blank"> <img src = "C:/Users/hp1/Desktop/Website/Pictures/Facebook.jpg" alt="Facebook" style="width:40px;height:40px;"> </a> </li>  

       <li> <a href ="#" target="_blank"> <img src = "C:/Users/hp1/Desktop/Website/Pictures/YouTube.jpg" alt="YouTube" style="width:40px;height:40px;"> </a> </li>  

       <li> <a href ="#" target="_blank"> <img src = "C:/Users/hp1/Desktop/Website/Pictures/Instagram.jpg" alt="Instagram" style="width:40px;height:40px;"> </a> </li>  

       <li> <a href ="#" target="_blank"> <img src = "C:/Users/hp1/Desktop/Website/Pictures/Twitter.jpg" alt="Twitter" style="width:40px;height:40px;"> </a> </li> 

      </ul> 

     </div> 

    </footer> 

</html> 
+1

你需要一个服务器端语言PHP的本地主机服务器。在Google上搜索WAMP或XAMPP或AMPPS。 – paolobasso

+1

你的服务器是什么?你的PHP引擎没有运行。 –

+1

默认情况下,使用php提供的文件必须具有'.php'文件扩展名。也有助于拥有一台可以运行这些文件的服务器,而且您不能像在纯文本文件中那样在浏览器中双击它们。 – cteski

回答

-1

的问题是,你有你的计算机上没有安装PHP的Web服务器。你在Windows上,所以安装Wamp:它是一个包含Apache2(服务器),PHP(将读取并执行你的php代码),MySql和许多其他组件的一体化web服务器。

+0

我的电脑上已经有Wamp –

2

编辑:如果您已经安装了WAMP,运行它,并把你的项目文件夹内:c:\wamp\www(虽然可能在版本而异)。

进行预览,键入您的浏览器网址:localhost/yourProjectFolderName

+0

OP说它安装在另一个答案里了。看截图,你会看到问题是什么。你有50%的权利,但。 –

+0

如果安装了,她不会通过它预览网站。再次; – Syden

+0

;看看截图,注意URL中的内容? –

相关问题