dpbl91234 2015-11-05 06:13
浏览 48

删除php扩展和$ SESSION变量不起作用

Hi everyone I found this code here somewhere

RewriteEngine On

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]

This removes the .php file extension but my $_GET paramaters do not work anymore how can I go about to solve this thanks in advance. I have read other posts but didn't get what I wanted.

After further examination the problem is that when I log in

$_SESSION[profileId] // doesn't set anymore

When I clear .htaccess everything goes back to normal. My code reads

$sql = "SELECT * FROM mytable WHERE userName='$_GET['profile']' LIMIT 1";
$user_query = mysqli_query($db_conx, $sql);
$row = mysqli_fetch_array($user_query,MYSQL_ASSOC);

$profileId = $row['profileId'];

if($_SESSION['profileId'] === $profileId){
    if(isset($_GET['profile']) && !isset($_GET['edit'])){

    echo '<a id="editButtons" href="../profile.php?profile='.$_GET['profile'].'&edit=1">Edit Profile</a>';
    }

    if(isset($_GET['profile']) && isset($_GET['edit'])){

    echo '<a id="editButtons" href="../profile.php?profile='.$_GET['profile'].'">Done editing</a>';
    }    
}

This is the code where I set the sessions

session_start();

$username = mysqli_real_escape_string($db_conx, $_POST['u']);
$password = $_POST['p'];
$ip = preg_replace('#[^0-9.]#', '', getenv('REMOTE_ADDR'));

if($username == "" || $password == ""){
    echo "login_failed";
}else{
    $sql = "SELECT * FROM myTable WHERE username='$username' AND activated='yes' LIMIT 1";
    $query = mysqli_query($db_conx, $sql);
    $row = mysqli_fetch_array($query);
    $profileId = $row['profileId'];
    $compName = $row['compName'];
    $db_username = $row['username'];
    $db_email = $row['email'];
    $db_pass_str = $row['password'];


    if(password_verify($password,$db_pass_str)){

        $_SESSION['profileId'] = $profileId;
        $_SESSION['username'] = $db_username;
        $_SESSION['password'] = $db_pass_str;
        setcookie("id", $profileId, strtotime( '+30 days' ), "/", "", "", TRUE);
        setcookie("user", $db_username, strtotime( '+30 days' ), "/", "", "", TRUE);
        setcookie("pass", $db_pass_str, strtotime( '+30 days' ), "/", "", "", TRUE); 
        // UPDATE THEIR "IP" AND "LASTLOGIN" FIELDS
        $sql = "UPDATE myTable SET ip='$ip', lastlogin=now() WHERE profileId='$profileId' LIMIT 1";
        $query = mysqli_query($db_conx, $sql);

        if($query){
            echo $compName;
        }

    } else {
        echo 'login_failed';

    }       
}
  • 写回答

1条回答 默认 最新

  • douxuan4556 2015-11-05 10:22
    关注
        You are redirect any url to .php page without passing argument.
    
        So passed argument also using htaccess.
    
        Please try these.
    
        For example :-
    
        you want to call test page with your id as parameter then
        make request like these /test/12 then it will redirect to test.php?id=12
    
        RewriteRule ^/?(.*)/(.*)$ /$1.php?id=$2 [L]
    
    Please change htaccess like these
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题