2014-10-27 32 views
0

首先,在我開始之前,請原諒我的mysql我知道這是貶值的,我將來會更新到PDO。所以,我們走了。如果用戶登錄,試圖顯示其他內容?

基本上我有大部分頁面的重複,'index.php','index2.php'等等。基本上現在所有沒有數字'2'的頁面都是非註冊用戶,一旦用戶登錄,他們將被重定向到'index2.php',因此所有數字'2'都是註冊用戶頁面。所以我基本上想做的是不用重複頁面,我只能有'index.php'和其他頁面沒有重複?因此,用戶登錄將被重定向到'index.php',但具有相同的功能和'index2.php'。如果這有什麼意義哈哈!

註冊頁面代碼:

<?php 
session_start(); 
include ('../includes/config.php'); 
include ('../includes/header.php'); 
?> 


<!doctype html> 
<html> 
<body> 




       <div class="search1"> 

      <h2>Register</h2> 

      <form action="" method="POST"> 
     <center> 
      <label>Username:</label> 
       <input type="text" name="username" required /> 
      <label>Password:</label> 
       <input type="password" name="password" required /> 
       <label>Email:</label> 
       <input type="email" name="email" required /> 
       <input type="submit" value="Register" name="submit" class="submit" /> 
       </center> 

       <br><br><br> 
       <h2><p><a href="index.php">Back</a></p></h2> 


    </div> 
<?php 
if(isset($_POST["submit"])){ 

if(!empty($_POST['username']) && !empty($_POST['password'])) { 
    $username=$_POST['username']; 
    $password=$_POST['password']; 
    $email=$_POST['email']; 


$password = strip_tags($password); 
$password = md5($password); // md5 is used to encrypt your password to make it more secure. 

    $con=mysql_connect('localhost','root','') or die(mysql_error()); 
    mysql_select_db('aha') or die("cannot select DB"); 




    $query=mysql_query("SELECT * FROM login WHERE username='".$username."'"); 
    $numrows=mysql_num_rows($query); 
    if($numrows==0) 
    { 
    $sql="INSERT INTO login(username,password,email) VALUES('$username','$password', '$email')"; 

    $result=mysql_query($sql); 


    if($result){ 
    echo "<div class='passed'>Account Successfully Created</div>"; 
    } else { 
    echo "<div class='results'>Failure!</div>"; 
    } 

    } else { 
    echo "<div class='results'>Username already exists!</div>"; 
    } 

} else { 
    echo "<div class='results'>All fields are required!</div>"; 
} 
} 




?> 
</form> 
<img src="../images/main.jpg"> 
</body> 
</html> 

INDEX1.PHP-CODE:

<?php 
session_start(); 
include ('../includes/config.php'); 
include ('../includes/header.php'); 
?> 
<!DOCTYPE HTML> 
<html> 
<head> 
<title>Honda |</title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
<link href='http://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'> 
<link href="../css/style.css" rel="stylesheet" type="text/css" media="all" /> 
<!--slider--> 
<link href="../css/camera.css" rel="stylesheet" type="text/css" media="all" /> 
    <script type='text/javascript' src='../js/jquery.min.js'></script> 
    <script type='text/javascript' src='../js/jquery.mobile.customized.min.js'></script> 
    <script type='text/javascript' src='../js/jquery.easing.1.3.js'></script> 
    <script type='text/javascript' src='../js/camera.min.js'></script> 

    <script> 
     jQuery(function(){ 

      jQuery('#camera_wrap_1').camera({ 
       thumbnails: true 
      }); 

      jQuery('#camera_wrap_2').camera({ 
       height: '400px', 
       loader: 'bar', 
       pagination: false, 
       thumbnails: true 
      }); 
     }); 
    </script> 
</head> 
<body> 
<!--start header--> 
<div class="h_bg"> 
<div class="wrap"> 
<div class="wrapper"> 
<div class="header"> 
    <div class="logo"> 
     <a href="index.php"><img src="../images/logo.png"> </a> 
    </div> 


    <div class="cssmenu"> 
    <ul> 
     <li class="active"><a href="index.php"><span>Home</span></a></li> 
      <li><a href="about.php"><span>About</span></a></li> 
     <li class="has-sub"><a href="service.php"><span>Gallery</span></a> 
     </li> 
     <li class="last"><a href="contact.php"><span>Contact</span></a></li> 
    <div class="clear"></div> 
    </ul> 
        <div class="search"> 
        <h2>search</h2> 
      <form action="search.php" method="get"> 
       <input type="text" name="search" value="" placeholder="Enter Your search..."> 
       <input type="submit" name="submit" value=""> 
      </form> 
     </div> 

     <?php 
if(isset($_POST["submit"])){ 

if(!empty($_POST['username']) && !empty($_POST['password'])) { 
    $username=$_POST['username']; 
    $password=$_POST['password']; 



    $password = strip_tags($password); 
$password = md5($password); // md5 is used to encrypt your password to make it more secure. 





    $query=mysql_query("SELECT * FROM login WHERE username='".$username."' AND password='".$password."'"); 
    $numrows=mysql_num_rows($query); 
    if($numrows!=0) 
    { 
    while($row=mysql_fetch_assoc($query)) 
    { 
    $dbusername=$row['username']; 
    $dbpassword=$row['password']; 
    } 

    if($username == $dbusername && $password == $dbpassword) 
    { 
    session_start(); 
    $_SESSION['sess_user']=$username; 

    /* Redirect browser */ 
    header("Location: member.php"); 
    } 
    } else { 
    echo "<div class='results'>Invalid username or password</div>"; 
    } 

} else { 
    echo "All fields are required!"; 
} 
} 



?> 

       <div class="search1"> 

      <h2>login/Register</h2> 

      <form action="" method="POST"> 

      <label>Username:</label> 
       <input type="text" id="password" name="username" required /> 
      <label>Password:</label> 
       <input type="password" id="password" name="password" required /> 
       <input type="submit" value="Login" name="submit" class="submit" /> 
       <br><br> 
       <center> 
       <h2><p><a href="register.php">Register</a></p></h2> 
       </center> 
    </form> 
    </div> 




    </div> 

    <div class="clear"></div> 
</div> 
</div> 
</div> 
</div> 
<!-- start slider --> 
<div class="slider_bg"> 
<div class="wrap"> 
<div class="wrapper"> 
    <div class="slider"> 
    <!-- #camera_wrap_1 --> 
    <div class="fluid_container"> 
     <div class="camera_wrap camera_azure_skin" id="camera_wrap_1"> 
      <div data-thumb="../images/thumbs/slider1.jpg" data-src="../images/slider/slider1.jpg"> 
      </div> 
      <div data-thumb="../images/thumbs/slider2.jpg" data-src="../images/slider/slider2.jpg"> 
      </div> 
      <div data-thumb="../images/thumbs/slider3.jpg" data-src="../images/slider/slider3.jpg"> 
      </div> 
      <div data-thumb="../images/thumbs/slider4.jpg" data-src="../images/slider/slider4.jpg"> 
      </div>    
      </div><!-- #camera_wrap_1 --> 
     <div class="clear"></div> 
    </div> 
    <!-- end #camera_wrap_1 --> 
    <div class="clear"></div> 
    </div> 
</div> 
</div> 
</div> 

<!-- start content --> 
<div class="content_bg"> 
<div class="wrap"> 
<div class="wrapper"> 
    <div class="main"> 

    <!-- start content_right --> 


       <div class="image group"> 
       <div class="grids_of_2"> 
        <div class="grid images_3_of_1"> 
         <img src="../images/pic1.jpg"> 
        </div> 
        <div class="grid span_2_of_3"> 
         <h3>How it all started</h3> 
         <p class="para">Honda Motor Co., Ltd. (本田技研工業株式會社 Honda Giken Kōgyō KK?, IPA: [hoɴda] (listen); /ˈhɒndə/) is a Japanese public multinational corporation primarily known as a manufacturer of automobiles, motorcycles and power equipment. 

Honda has been the world's largest motorcycle manufacturer since 1959,[3][4] as well as the world's largest manufacturer of internal combustion engines measured by volume, producing more than 14 million internal combustion engines each year.[5] Honda became the second-largest Japanese automobile manufacturer in 2001.[6][7] Honda was the eighth largest automobile manufacturer in the world behind General Motors, Volkswagen Group, Toyota, Hyundai Motor Group, Ford, Nissan, and PSA in 2011.[8] 

Honda was the first Japanese automobile manufacturer to release a dedicated luxury brand, Acura, in 1986. Aside from their core automobile and motorcycle businesses, Honda also manufactures garden equipment, marine engines, personal watercraft and power generators, amongst others. Since 1986, Honda has been involved with artificial intelligence/robotics research and released their ASIMO robot in 2000. They have also ventured into aerospace with the establishment of GE Honda Aero Engines in 2004 and the Honda HA-420 HondaJet, which began production in 2012. Honda has three joint-ventures in China (Honda China, Dongfeng Honda, and Guangqi Honda). 

In 2013, Honda invested about 5.7% (US$ 6.8 billion) of its revenues in research and development.[9] Also in 2013, Honda became the first Japanese automaker to be a net exporter from the United States, exporting 108,705 Honda and Acura models while importing only 88,357</p> 
        </div> 
        <div class="clear"></div> 
        </div> 
        <div class="grids_of_2 top"> 
        <div class="grid images_3_of_1"> 
         <img src="../images/pic2.jpg"> 
        </div> 
        <div class="grid span_2_of_3"> 
         <h3>CEO of Honda</h3> 
         <p class="para">Kawamoto acted quickly to change Honda's corporate culture, rushing through market-driven product development that resulted in recreational vehicles such as the Odyssey[disambiguation needed] and the CR-V, and a refocusing away from some of the numerous sedans and coupes that were popular with Honda's engineers but not with the buying public. The most shocking change to Honda came when Kawamoto ended Honda's successful participation in Formula One after the 1992 season, citing costs in light of the takeover threat from Mitsubishi as well as the desire to create a more environmentally-friendly company image.[21] 

Later, 1995 gave rise to the Honda Aircraft Company with the goal of producing jet aircraft under Honda's name</p> 
        </div> 
        <div class="clear"></div> 
        </div> 
       </div> 
    </div> 
    </center> 
    <div class="clear"></div> 
</div> 
</div> 
</div> 
</div> 
<div class="footer_bg"> 
<div class="wrap"> 
<div class="wrapper"> 
    <div class="footer"> 
     <div class="copy"> 
      <p class="w3-link">© &nbsp;</p> 
     </div> 
     <div class="f_nav"> 
     <ul> 
      <li><a href="#">Skype</a></li> 
      <li><a href="#">Linked in</a></li> 
      <li><a href="#">Twitter</a></li> 
      <li><a href="#">Facebook</a></li> 
     </ul> 
     </div> 
     <div class="clear"></div> 
    </div> 
</div> 
</div> 
</div> 
</body> 
</html> 



</body> 
</html> 

最可是好景不長! INDEX2.PHP-CODE:

<?php 
session_start(); 
include "../includes/config.php"; 
include "function.php"; 
include ('../includes/header.php'); 

?> 



<!DOCTYPE HTML> 
<html> 
<head> 
<style> 
#error_box{display:none; position:relative;top:-25px} 
</style> 
<title>Honda |</title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
<link href='http://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'> 
<link href="../css/style.css" rel="stylesheet" type="text/css" media="all" /> 
<!--slider--> 
<link href="../css/camera.css" rel="stylesheet" type="text/css" media="all" /> 
    <script type='text/javascript' src='../js/jquery.min.js'></script> 
    <script type='text/javascript' src='../js/jquery.mobile.customized.min.js'></script> 
    <script type='text/javascript' src='../js/jquery.easing.1.3.js'></script> 
    <script type='text/javascript' src='../js/camera.min.js'></script> 

    <script> 
     jQuery(function(){ 

      jQuery('#camera_wrap_1').camera({ 
       thumbnails: true 
      }); 

      jQuery('#camera_wrap_2').camera({ 
       height: '400px', 
       loader: 'bar', 
       pagination: false, 
       thumbnails: true 
      }); 
     }); 
    </script> 
</head> 
<body> 

<!--start header--> 
<div class="h_bg"> 
<div class="wrap"> 
<div class="wrapper"> 
<div class="header"> 
    <div class="logo"> 
     <a href="index2.php"><img src="../images/logo.png"> </a> 
    </div> 


    <div class="cssmenu"> 
    <ul> 
     <li class="active"><a href="index2.php"><span>Home</span></a></li> 
      <li><a href="about2.php"><span>About</span></a></li> 
     <li class="has-sub"><a href="service2.php"><span>Gallery</span></a> 
     </li> 
     <li class="last"><a href="contact2.php"><span>Contact</span></a></li> 
    <div class="clear"></div> 
    </ul> 
        <div class="search"> 
        <h2>search</h2> 
      <form> 
       <input type="text" value="" placeholder="Enter Your search..."> 
       <input type="submit" value=""> 
      </form> 
     </div> 

         <div class="search1"> 


      <form action="" method="POST"> 
     <br> 
<h2>Welcome, <?=$_SESSION['sess_user'];?>!</h2><br><br> 

           <div class="pw"> 
       <a href="changepassword.php"><h3>Change details</h3></a> 
       </div> 

       <br><br> 
<h2><a href="logout.php">Logout</a></h2> 
    </form> 
    </div> 



    <div class="clear"></div> 
</div> 
</div> 
</div> 
</div> 
<!-- start slider --> 
<div class="slider_bg"> 
<div class="wrap"> 
<div class="wrapper"> 
    <div class="slider"> 
    <!-- #camera_wrap_1 --> 
    <div class="fluid_container"> 
     <div class="camera_wrap camera_azure_skin" id="camera_wrap_1"> 
      <div data-thumb="../images/thumbs/slider1.jpg" data-src="../images/slider/slider1.jpg"> 
      </div> 
      <div data-thumb="../images/thumbs/slider2.jpg" data-src="../images/slider/slider2.jpg"> 
      </div> 
      <div data-thumb="../images/thumbs/slider3.jpg" data-src="../images/slider/slider3.jpg"> 
      </div> 
      <div data-thumb="../images/thumbs/slider4.jpg" data-src="../images/slider/slider4.jpg"> 
      </div>    
      </div><!-- #camera_wrap_1 --> 
     <div class="clear"></div> 
    </div> 
    <!-- end #camera_wrap_1 --> 
    <div class="clear"></div> 
    </div> 
</div> 
</div> 
</div> 

<!-- start content --> 
<div class="content_bg"> 
<div class="wrap"> 
<div class="wrapper"> 
    <div class="main"> 

    <!-- start content_right --> 


       <div class="image group"> 
       <div class="grids_of_2"> 
        <div class="grid images_3_of_1"> 
         <img src="../images/pic1.jpg"> 
        </div> 
        <div class="grid span_2_of_3"> 
         <h3>How it all started</h3> 
         <p class="para">Honda Motor Co., Ltd. (本田技研工業株式會社 Honda Giken Kōgyō KK?, IPA: [hoɴda] (listen); /ˈhɒndə/) is a Japanese public multinational corporation primarily known as a manufacturer of automobiles, motorcycles and power equipment. 

Honda has been the world's largest motorcycle manufacturer since 1959,[3][4] as well as the world's largest manufacturer of internal combustion engines measured by volume, producing more than 14 million internal combustion engines each year.[5] Honda became the second-largest Japanese automobile manufacturer in 2001.[6][7] Honda was the eighth largest automobile manufacturer in the world behind General Motors, Volkswagen Group, Toyota, Hyundai Motor Group, Ford, Nissan, and PSA in 2011.[8] 

Honda was the first Japanese automobile manufacturer to release a dedicated luxury brand, Acura, in 1986. Aside from their core automobile and motorcycle businesses, Honda also manufactures garden equipment, marine engines, personal watercraft and power generators, amongst others. Since 1986, Honda has been involved with artificial intelligence/robotics research and released their ASIMO robot in 2000. They have also ventured into aerospace with the establishment of GE Honda Aero Engines in 2004 and the Honda HA-420 HondaJet, which began production in 2012. Honda has three joint-ventures in China (Honda China, Dongfeng Honda, and Guangqi Honda). 

In 2013, Honda invested about 5.7% (US$ 6.8 billion) of its revenues in research and development.[9] Also in 2013, Honda became the first Japanese automaker to be a net exporter from the United States, exporting 108,705 Honda and Acura models while importing only 88,357</p> 
        </div> 
        <div class="clear"></div> 
        </div> 
        <div class="grids_of_2 top"> 
        <div class="grid images_3_of_1"> 
         <img src="../images/pic2.jpg"> 
        </div> 
        <div class="grid span_2_of_3"> 
         <h3>CEO of Honda</h3> 
         <p class="para">Kawamoto acted quickly to change Honda's corporate culture, rushing through market-driven product development that resulted in recreational vehicles such as the Odyssey[disambiguation needed] and the CR-V, and a refocusing away from some of the numerous sedans and coupes that were popular with Honda's engineers but not with the buying public. The most shocking change to Honda came when Kawamoto ended Honda's successful participation in Formula One after the 1992 season, citing costs in light of the takeover threat from Mitsubishi as well as the desire to create a more environmentally-friendly company image.[21] 

Later, 1995 gave rise to the Honda Aircraft Company with the goal of producing jet aircraft under Honda's name</p> 
        </div> 
        <div class="clear"></div> 
        </div> 
       </div> 
    </div> 
    </center> 
    <div class="clear"></div> 
</div> 
</div> 
</div> 
</div> 
<div class="footer_bg"> 
<div class="wrap"> 
<div class="wrapper"> 
    <div class="footer"> 
     <div class="copy"> 
      <p class="w3-link">© &nbsp;</p> 
     </div> 
     <div class="f_nav"> 
     <ul> 
      <li><a href="#">Skype</a></li> 
      <li><a href="#">Linked in</a></li> 
      <li><a href="#">Twitter</a></li> 
      <li><a href="#">Facebook</a></li> 
     </ul> 
     </div> 
     <div class="clear"></div> 
    </div> 
</div> 
</div> 
</div> 
</body> 
</html> 



</body> 
</html> 

任何幫助,非常感謝!謝謝!

+0

你可能要檢查,如果用戶輸出任何東西之前登錄,然後修改密碼的那些看上去不同的註冊和未註冊會員(該部分取決於對第一檢查的結果 - 無論用戶已登錄或沒有登錄)。對不起,如果我說的話對你來說顯而易見,還沒有通讀你的所有代碼。 – Max 2014-10-27 16:56:43

+0

更新到PDO是一回事,但你甚至沒有使用'mysql_real_escape_string'。至少做到這一點! – rjdown 2014-10-27 17:00:14

回答

0

這是一個非常糟糕的設計,但我希望你能得到邏輯。

session_start(); 
if (!empty($_POST["username"]) && !empty($_POST["password"])) { 
    //If form has submitted 
    //Get user from database. 
    if ($numrows > 0) { 
     $_SESSION["loggedIn"] = true; 
     //You can set here more session things, like username, email, etc... 
    } else { 
     $_SESSION["loggedIn"] = false; 
    } 
} 


if (empty($_SESSION["loggedIn"])) { 
    //Show content if user is not logged in. 
    //You can include your file here, when user not logged in 
} else { 
    //Show content if user is logged in. 
    //You can include your file here 
    //The best practice, if you are redirect to the user here to another page. 
    //Do this check in all page, when user needs to be logged in 
} 
//HTML code comes here. 
+0

感謝您的回覆,但是如果這不是問題,您可以在上面的代碼中實現這一點嗎?謝謝! (我只是有點問題) – Elina 2014-10-27 17:01:50

+0

試着理解我做了什麼。我不會免費編碼。 – vaso123 2014-10-27 17:03:49

+0

https://www.youtube.com/watch?v=RA-klM5kGn8&list=PLyKBLKYqadGmD33SGjyk_MXrGAHVTVcqa&index=1只是想分享這個鏈接我無法抓住PDO,所以我通過教程的一半,我問了很多問題,是導致我被阻止。我剛剛意識到PDO解決了我遇到的很多問題。真的嘗試和理解PDO會幫助你很大的時間。我正在慢慢理解它。 – Donny 2014-11-09 04:21:30

相關問題