htaccess重定向双查询字符串

时间:2016-01-12 14:15:35

标签: string .htaccess mod-rewrite

由于编码错误,我有一堆需要在htaccees中重写的虚假URL。

URL的查询部分以某种方式重复,现在必须剥离到单个查询部分,例如

http://www.example.com/?abc=def/?abc=defhttp://www.example.com/?abc=def

我希望找到一个带有通配符的解决方案,以便无论何时出现双查询字符串,它都能正常工作 - 无论查询是什么。但是我的编码技巧还不够好......

希望你能帮忙! : - )

1 个答案:

答案 0 :(得分:-1)

尝试:

<?php
require "dbcon.php";
//Check Perms
//Errors

//Clean Up Old Sessions from DB
$session_clear=mysqli_query($con, "DELETE FROM global_sessions WHERE expiration < NOW()");
if (!$session_clear) {
    die('Error: ' . mysqli_error($con));
}

$key = mysqli_real_escape_string($con, $_COOKIE['session']);    

//Gets Login information Regarding the data inputed
$results=mysqli_query($con,"SELECT u.student_id, u.school_id, u.username, u.nickname, u.email, u.house, u.verified, u.permission_group FROM global_sessions s LEFT JOIN global_userdata u ON s.user_id = u.student_id WHERE s.hash = '$key'");
if (!$results) {
    die('Error: ' . mysqli_error($con));
}

//Gets URL and counts '/' to work out where is is in the directory listing
$url = $_SERVER['REQUEST_URI'];
$urlcount = 0;
$strcount = 0;
$strlen = strlen($url);
while ($strlen > $strcount){
    //echo "len: " . $strlen . ' | ';
    //echo "count: " . $strcount . ' | ';
    //echo "letter: " . substr($url, $strcount, 1) . '<br>';
    if (substr($url, $strcount, 1)=="/"){
        $urlcount++;
    }
    $strcount++;
}
$strcount = 0;
//Check School is set, if nots logs the user out and returns to index
$school = mysqli_real_escape_string($con, $_COOKIE['school']);
if (empty($school)){
    if ($urlcount == 3){
        setcookie("session", $key, time()-3600, '/');
        header("location: loggedout/index.php?login_error=notschool");
        exit;
    }elseif ($urlcount == 4){
        setcookie("session", $key, time()-3600, '/');
        header("location: ../loggedout/index.php?login_error=notschool");
        exit;
    }else{
        die("Error: An Error Occurred - (Make Log) [L1]");
    }
}
//Gets School Information From Database 
$results2=mysqli_query($con,"SELECT * from global_schools WHERE code = '" . $school . "'");
if (!$results2) {
    die('Error: ' . mysqli_error($con));
}

//Checks if logged in.

$count = mysqli_num_rows($results);
if ($count == 0) {
    //No Account Found - And Redirect
    if ($urlcount == 3){
        header("location: loggedout/index.php?login_error=invalid");
        exit;
    }elseif ($urlcount == 4){
        header("location: ../loggedout/index.php?login_error=invalid");
        exit;
    }else{
        die("Error: An Error Occurred - (Make Log) [L2]");
    }
} elseif ($count > 1) {
    //More than one account with the same unique details
    die('Error: Aaaah too many people!!! I get scared when there are crowds. Please contact an admin and tell them that there is a problem!');
    exit;
} else {
    //Login Successful
    //Get user Details and store them in a global Variable
    $logged_user_details = mysqli_fetch_array($results);
    //Get school Details and store them in a global Variable
    $logged_school_details = mysqli_fetch_array($results2);
    //Store Details in web page in commented form
    echo "<!-- ";
    print_r ($logged_user_details);
    print_r ($logged_school_details);
    echo "-->";
    //Check if account if verified
    if ($logged_user_details['verified'] != 1){
        die("You haven't verified your account. Please check your emails and click the link to complete your registration. Then click back on your browser!");
}
    //Check if the user has the same school linked with their account as they are trying to login on - Redirect if not
     if ($logged_school_details['school_id'] != $logged_user_details['school_id']){
         if ($urlcount == 3){
             setcookie("session", $key, time()-3600, '/');
             setcookie("school", $school, time()-3600, '/');
             header('Location: ' . $school . '/notschool');
             exit;
        }elseif ($urlcount == 4){
             setcookie("session", $key, time()-3600, '/');
             setcookie("school", $school, time()-3600, '/');
             header('Location: ../' . $school . '/notschool');
             exit;
        }else{
             die("Error: An Error Occurred - (Make Log) [L3]");
        }
    }
}

//!! Check if the user has accepted the terms and conditions !! - Might need a rewrite
/*$result=mysqli_query($con,"SELECT agreed FROM users WHERE id='".$logged_user_details['id']."'");
 if (!$result) {
     die('Error: ' . mysqli_error($con));
}
#header('Location: ../index.php');
$agreedresult=mysqli_fetch_array($result);
//echo $agreedresult['agreed'];
if ($agreedresult['agreed'] == 0){
    setcookie("session", $key, time()+1200, '/');
    setcookie("id", $logged_user_details['id'], time()+60, '/');
    header('Location: ../tsandcs.php');
    exit;
}*/

//Login successful, Set login information - Session Key
$result=mysqli_query($con,"UPDATE global_sessions SET expiration=DATE_ADD(NOW(), INTERVAL 20 MINUTE) WHERE hash='$key'");
if (!$result) {
die('Error: ' . mysqli_error($con));
}
setcookie("session", $key, time()+1200, '/');
?>