Teach you to quickly implement PHP full-site permissions Validation _php Tutorial

Source: Internet
Author: User

PHP Full-Site Authorization code example:

  1. < html>
  2. < head>< title> e
  3. < /title >
  4. < /head >
  5. < body>
  6. < form action="login.php"
    method="POST" >

User:

    1. < input type="text"
      name="username">
    2. < br>

Password:

  1. < input type="password"
    name="password">
  2. < input type ="Submit"
    value = "OK" >
  3. < input type ="Reset"
    value = "Cancel" >
  4. < /form >
  5. < /body >
  6. < /html >

----------------conn.php--------------------------

  1. < ? PHP
  2. $ Host = ' 127.0.0.1 ' ;
  3. $ Mysql_user = ' Root ' ;
  4. $ Mysql_password = ' qeephp ' ;
  5. $ MyDB = ' Learn ' ;
  6. $ Link = mysql_connect ($host,
    $mysql _user, $mysql _password)
  7. Or Die ("Unable to connect to database:"
    . Mysql_error ());
  8. mysql_select_db ($MYDB);
  9. ?>

----------------------------login.php------------------

 
 
  1. < ?
  2. $ username =$_post[' username '];
  3. $ Password =$_post[' password '];
  4. if ($username= = "") {
  5. echo " < script language=' javascript '>
    Alert (' Illegal operation! '); location.href=
    ' index.php ' ; < /script > ";
  6. Exit
  7. }
  8. Require_once ("conn.php");
  9. $ SQL = "SELECT * from admin where
    Username= ' $username ' ";
  10. $ result = mysql_query ($sql);
  11. $ Row = Mysql_fetch_array ($result);
  12. if ($row [' username ']== "") {
  13. echo " < script language=' javascript '>
    Alert (' Wrong username! '); location.href=
    ' index.php ' ; < /script > ";
  14. Exit
  15. }else if ($row [' Password ']!= $password) {
  16. echo " < script language=' javascript '>
    Alert (' Wrong password! '); location.href=' Index
    . php '; < /script > ";
  17. echo "Wrong password";
  18. Exit
  19. }else{
  20. Session_Start ();
  21. $_session[' user ']= $username;
  22. echo " < script language=' javascript '>
    Alert (' Landed successfully! '); location.href=
    ' list.php ' ; < /script > ";
  23. }
  24. ?>

------------------check.php--------------------

 
 
  1. < ?
  2. Session_Start ();
  3. if (! isset ($_session[' user '))
  4. {
  5. echo " < script language=' javascript '>
    Alert (' Illegal operation! '); location.href=
    ' index.php ' ; < /script > ";
  6. Exit
  7. }else{
  8. echo "Welcome". $_session[' user '
    ." Login System ";
  9. }
  10. ?>

---------------------list.php-----------------

 
 
  1. < ?
  2. Include ' check.php ';
  3. ?>
  4. < html >
  5. < head >
  6. < script type="Text/javascript"
    src = "Player/swfobject.js" > < /script >
  7. < /head >
  8. < body >
  9. < h3> Single file playback:< /h3>
  10. < p id="player1">< A href = "
    http://www.macromedia.com/go/
    Getflashplayer "> get player < /A> watch movies < / P >
  11. < script type="text/javascript">
  12. var S1 = New swfobject ("player/
    Flvplayer.swf "," single "," 300 "," 170 "," 7 ");
  13. S1.addparam ("allowFullScreen", "true");
  14. S1.addvariable ("File", "player/ad.flv");
  15. S1.addvariable ("image", "player/preview.jpg");
  16. S1.addvariable ("width", "300");
  17. S1.addvariable ("height", "170");
  18. S1.write ("Player1");
  19. < /script >
  20. < h3>playlist file, with different
    Colors:< /h3>
  21. < p id="player2">< a href="http:
    Www.macromedia.com/go/getflashplayer ">
    Get the Flash Player < /A > To see this player. < / P >
  22. < script type="text/javascript">
  23. var S2 = New swfobject ("Player/flvplayer
    . swf "," playlist "," 300 "," 312 "," 7 ");
  24. S2.addparam ("allowFullScreen", "true");
  25. S2.addvariable ("File", "Player/playlist.xml");
  26. S2.addvariable ("Displayheight", "200");
  27. S2.addvariable ("BackColor", "0x000000");
  28. S2.addvariable ("Frontcolor", "0xCCCCCC");
  29. S2.addvariable ("Lightcolor", "0x557722");
  30. S2.addvariable ("width", "300");
  31. S2.addvariable ("height", "312");
  32. S2.write ("Player2");
  33. < /script >
  34. < /body >
  35. < /html >

--------------------logout.php-------------------------

 
  
  
  1. < ? PHP
  2. unset ($_session[' user ');
  3. unset ($_session[' password ');
  4. echo "Logout success";
  5. ?>

The above is the specific implementation of PHP full-site authorization verification.


http://www.bkjia.com/PHPjc/445984.html www.bkjia.com true http://www.bkjia.com/PHPjc/445984.html techarticle PHP Full-Site Authorization code example: HTML head title E/title/head body Form action = login.php method = POST User: input type = text Name = Username br Password: input type = ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.