2017-07-03 53 views
1

該代碼在本地主機xampp服務器上完美工作,但不能在Cpanel上工作我認爲sesion_start命令不工作。如果我登錄使用錯誤密碼,然後將它顯示了一個錯誤LoinPage.php wroks其平均PHP代碼,但是當我輸入正確的用戶名和密碼,它會顯示而不是帶我去AdminDashboard.php
LoginPage.php登錄頁面php代碼不工作cpanel空白頁後成功完成登錄

空白頁
<!DOCTYPE html> 


    <html > 
    <head> 
     <meta charset="UTF-8"> 
     <title>Seza Admin Login</title> 



      <link rel="stylesheet" href="css/loginStyle.css"> 




    </head> 

    <body> 


    <?php include("connection.php"); 

    error_reporting(E_ALL); 

      $msg=null; 



      if(isset($_POST['login']) && $_POST['login']=='ok') 
      { 
      $username =$_POST['username']; 
      $password = $_POST['password']; 

      $selectuser = mysqli_query($conn,"select * from admins where USERNAME='".$username."' and PASSWORD ='".$password."'") or die(mysqli_error($conn)); 
      $no_users = mysqli_num_rows($selectuser); 
      if($no_users>0) 
       { 
        $fetch_user = mysqli_fetch_array($selectuser); 
        $_SESSION['adminid']= $fetch_user['AID']; 

        alert("success"); 
        header("location:AdminDashboard.php"); 

       } 
       else{ 
        $msg = "The username or password is invalid"; 
       } 
      } 
      else{ 
       if(isset($_POST['login']) && $_POST['login']=='ok') 
       { 
       echo"invalid"; 
       } 
      } 


     ?> 
     <div class="site_wrapper"> 




     <form method="post" id="additem-form" > 
     <input type="hidden" id="login" name="login" value="ok" /> 
     <div class="login"> 

      <div class="login-screen"> 
       <div class="app-title"> 
        <h1>SezaPharma</h1> 
        <h3>ADMIN LOGIN</h3> 
       </div> 

       <div class="login-form"> 
        <div class="control-group"> 
        <input type="text" class="login-field" value="" placeholder="username" id="username" name="username"> 
        <label class="login-field-icon fui-user" for="login-name"></label> 
        </div> 

        <div class="control-group"> 
        <input type="password" class="login-field" value="" placeholder="password" id="password" name="password"> 
        <label class="login-field-icon fui-lock" for="login-pass"></label> 
        </div> 

        <button class="btn btn-primary btn-large btn-block" type="submit" value="login" >login</button> 
        <a class="login-link" onClick="alertRset()" href="">Lost ? Reset your password?</a> 

         <div style="color:#FF0004"> 
        <?php 
        if(isset($msg) && $msg!="") 
        { ?> 
         <div class="alert-danger"><?php echo $msg; ?></div> 

         <?php } 

     ?></div> 
       </div> 
      </div> 
     </div> 

     </form> 


     <script> 
    function alertRset() { 
     var txt; 
     if (confirm("It will Reset username and password to default.") == true) { 
      window.close(); 
      window.open("resetadmin.php"); 
     } else { 
      txt = "You pressed Cancel!"; 
     } 
     document.getElementById("demo").innerHTML = txt; 
    } 
    </script>`enter code here` 
    </body> 
    </html> 

AdminDashboard.php

<!DOCTYPE html> 

<html> 
<head> 

</style> 
</head> 
<body> 

<?php include("connection.php"); 
error_reporting(E_ALL); 

     if (isset($_SESSION['adminid'])) { 

?> 

<div class="dashboard"> 
<div class="tab"> 
    <button class="tablinks" onclick="openCity(event, 'London')" id="defaultOpen">All Products</button> 
    <button class="tablinks" onclick="openCity(event, 'Paris')">Add New Product</button> 
    <button class="tablinks" onclick="openCity(event, 'Tokyo')">Setting</button> 
    <a href="logout.php" ><button class="tablinks" onclick="openCity(event, 'Tokyo')" >Loggout</button></a> 
</div> 

<div id="London" class="tabcontent" style="overflow:auto"> 


    <div class="site_wrapper" > 




<div class="clearfix margin_top10"></div> 


<div class="works01" > 

<div class="container" > 



    <div id="grid-container" class="cbp-l-grid-fullWidth" style="overflow:visible;"> 


    <?php 


    $select_post=mysqli_query($conn,"select * from products ORDER BY PID desc") or die(mysqli_error()); 

    while($post=mysqli_fetch_array($select_post)) 
    { 

    ?> 

     <div class="cbp-item <?php echo $post['PTYPE'];?>"> 
      <div class="cbp-caption"> 
       <div class="cbp-caption-defaultWrap"> 
        <img style="width:100%; height:200px;" src="UploadedImage/<?php echo $post['PIMAGELOC'];?>" alt=""> 
       </div> 
       <div class="cbp-caption-activeWrap"> 
        <div class="cbp-l-caption-alignCenter"> 
         <div class="cbp-l-caption-body"> 
          <h3><?php echo $post['PNAME'];?></h3> 
          <br /> 
          <a href="#" class="cbp-l-caption-buttonLeft">Edit</a> 
          <a href="delete_product.php?PID=<?php echo $post['PID']; ?>" class="cbp-l-caption-buttonLeft" data-title="Looking Publishing <br>reasonable always">Delete</a> 
         </div> 
        </div> 
       </div> 
      </div> 
     </div><!-- end item --> 

     <?php 
     } 

    ?> 




    </div> 



</div> 
</div><!-- end works section --> 













<a href="#" class="scrollup">Scroll</a><!-- end scroll to top of the page--> 



</div> 

</div> 
<div id="Paris" class="tabcontent"> 
<form action="add_item.php" method="post" enctype="multipart/form-data" onsubmit="return validateForm()" id="additem-form" name="additem-form"> 

    <div class="contactcontainer"> 
    <header> 
    <h1>Add new Product</h1> 
    </header> 
<table width="100%" align="center"> 
<tr> 
<td colspan="2"> 
    <input style="width:74%" placeholder="Product Name" type="text" id="pname" name="pname"> 
    </td> 
    </tr> 

<tr> 
<td colspan="2"> 
     <select class="select" style=" width:74%;" name="cat" id="cat"> 
     <option value="Category" selected="selected">Product Category</option> 
       <option value="livestock" > livestock Products</option> 
       <option value="Poultry">Poultry Products</option> 

      </select> 
      </td> 
      </tr> 
      <tr> 
      <td colspan="2" > 
      <div style="border:dashed; width:75%;" align="center"> 
      <h4>Choose Product Picture</h4> 
      <input type="file" id="pimage" name="pimage" class="input-file" title="upload Photo/video" /> 
      </div> 
      </td> 
      </tr> 

      <tr> 
     <td> 
     <select class="select" style=" width:55%;" id="ptype" name="ptype"> 
       <option value="Type">Product Type</option> 
       <option value="Injections">Injections</option> 
       <option value="Anthilmentics">Anthilmentics</option> 
       <option value="Natural">Natural Products</option> 
       </select> 
       </td> 
       <td> 
       <select class="select" id="availability" style=" width:55%;" name="availability"> 
       <option value="Availability">Availability</option> 
       <option value="yes">Yes</option> 
       <option value="no">No</option> 
       </select> 
       </td> 
    </tr> 
<tr> 
<td colspan="2"> 
    <input style="width:74%" class="email" placeholder="Full Farmula with quantity" type="text" id="pfarmula" name="pfarmula"> 
    </td> 
    </tr> 
    <tr> 
<td colspan="2"> 
    <textarea style="width:74%" placeholder="Product Description" id="pdesc" name="pdesc"></textarea> 
    </td> 
    </tr> 
<tr> 
<td colspan="2" > 
<div style="width:74%" align="center"> 
    <footer> 
    <button style="width:20%" id="addbtn" name="addbtn" >Add</button> 
    </footer> 
    </div> 
    </td> 
    </tr> 
    </table> 
</div> 
</form> 

</div> 

<div id="Tokyo" class="tabcontent"> 
    <h3>Tokyo</h3> 
    <p>Tokyo is the capital of Japan.</p> 
</div> 
</div> <!--end of tabs--> 


<script> 


function validateForm() 
    { 
    var a=document.forms["additem-form"]["availability"].value; 
    var b=document.forms["additem-form"]["pname"].value; 
    var c=document.forms["additem-form"]["cat"].value; 
    var d=document.forms["additem-form"]["ptype"].value; 

    if (a=="Availability" || b=="" || c=="Category" || d=="Type") 
     { 
     alert("Please Fill All Required Field"); 
     return false; 
     } 
    } 



function openCity(evt, cityName) { 
    var i, tabcontent, tablinks; 
    tabcontent = document.getElementsByClassName("tabcontent"); 
    for (i = 0; i < tabcontent.length; i++) { 
     tabcontent[i].style.display = "none"; 
    } 
    tablinks = document.getElementsByClassName("tablinks"); 
    for (i = 0; i < tablinks.length; i++) { 
     tablinks[i].className = tablinks[i].className.replace(" active", ""); 
    } 
    document.getElementById(cityName).style.display = "block"; 
    evt.currentTarget.className += " active"; 
} 

// Get the element with id="defaultOpen" and click on it 
document.getElementById("defaultOpen").click(); 
</script> 



<!-- ######### JS FILES ######### --> 
<!-- get jQuery used for the theme --> 
<script type="text/javascript" src="js/universal/jquery.js"></script> 
<script src="js/style-switcher/styleselector.js"></script> 
<script src="js/animations/js/animations.min.js" type="text/javascript"></script> 
<script src="js/mainmenu/bootstrap.min.js"></script> 
<script src="js/mainmenu/customeUI.js"></script> 
<script src="js/scrolltotop/totop.js" type="text/javascript"></script> 
<script type="text/javascript" src="js/mainmenu/sticky.js"></script> 
<script type="text/javascript" src="js/mainmenu/modernizr.custom.75180.js"></script> 
<script type="text/javascript" src="js/cubeportfolio/jquery.cubeportfolio.min.js"></script> 
<script type="text/javascript" src="js/cubeportfolio/main31.js"></script> 

     <?php } else{ echo " You mus Loggedin to acces this page"; } ?> 
</body> 
</html> 

connection.php

<?php 

session_start(); 
// Create connection 
$conn = mysqli_connect("localhost", "username","password", "sezaphar_sezapharmadb") or die($conn->connect_error); 

?> 
+0

它看起來像你的PHP混合的JavaScript(警報)。請記住,必須在發送任何實際輸出之前調用header(),或者通過普通的HTML標記,文件中的空行或來自PHP。如果您在發表任何聲明前已將任何內容發送給客戶,則標題不起作用。 –

回答

0

你有個錯誤e代碼。
您需要呼應警報( 「成功」)之前標題( 「位置:AdminDashboard.php」);LoginPage.php

下面的代碼:

echo "<script>alert('success');</script>"; 
+0

但在此之前,代碼也無法正常工作。 –

+0

我已經改變了它,但仍然沒有把我帶到AdminDashboard.php。 –

+0

警報將無法使用標題。你需要使用JavaScript重定向,如window.location =「http://www.yoururl.com」; –