dpf7891 2019-08-02 10:12
浏览 85

如何通过加密cookie来保护我在api中的api

I have a question is it possible to encrypt the cookies for my api in php?

i have this code to be not used directly or they need account to able to use my api

include('../../info.php'); // here is the code for session
      if(!isset($_SESSION['user'])){ // user is the user_type in my db
      header("HTTP/1.1 401");
readfile('../../error/401.html');
exit();
  }
    if ( $_SERVER['REQUEST_METHOD']=='GET' && realpath(__FILE__) == realpath( $_SERVER['SCRIPT_FILENAME'] ) ) {
        http_response_code(401);
        header( 'HTTP/1.0 401 Forbidden', TRUE, 401 );
        die( readfile('../../error/401.html') );

    }

but when i try POSTMAN with my cookies it still give me the response of the api instead of getting the response code 401 but if i disable cookies in POSTMAN i get 401.

How do i secure my api?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大