1. <?php
    2. header("Content-Type:text/html;charset=utf-8");
    3. function alert_herf($text){
    4. echo'<script language="javascript">alert("'.$text.'");top.location='."'"."./login.html?a=login"."'".';</script>';
    5. }
    6. $type=$_GET['a'];
    7. switch ($type) {//当变量$type的是login的时候执行,login下的内容,如果是login_api就执行login_api下的分支语句
    8. case 'login':
    9. include("./tamplate/login.html");
    10. break;
    11. case 'login_api':
    12. $username=$_POST['username'];
    13. $password=$_POST['password'];
    14. if (empty($username)) {
    15. // code...
    16. alert_herf("请输入用户名,再提交");
    17. }
    18. if(empty($password)){
    19. alert_herf("请输入密码,再提交");
    20. }
    21. if ($username == "admin" && $password == "123456") {
    22. $text= "登陆成功";
    23. alert_herf($text);
    24. }else {
    25. $text= "登陆失败";
    26. alert_herf($text);
    27. }
    28. default:
    29. // code...
    30. break;
    31. }
    32. ?>

    switch作为分支机构语句进行php的代码当中