Latest News
Đẩy log exception của spring boot lên elasticsearch
  • About
  • EmEditor
  • Register Google Adsense

Love Coding

Note anything I want

  • Home
  • Web Development
    • HTML
    • Javascript
    • jQuery
    • CSS
    • PHP
    • ASP
    • JSP
    • Fix Bug
  • Other Development
    • Desktop Java
    • Mobile J2ME
    • VBS
  • Operating System
    • Windows
    • Linux
  • Database
    • MySQL
    • Oracle
  • Software
Home » Laravel » Love Coding: Missing PHP debugbar popup with HTTPS

Missing PHP debugbar popup with HTTPS

HuyPV
Add Comment
Laravel
Thursday, July 5, 2018
Bạn chạy code ở local tại địa chỉ https://huypv.local và chạy bản dev ở địa chỉ https://dev.huypv.net. Hai bản này chung env, đều bật APP_DEBUG = true nhưng khi ở local thì debug bar hiển thị được cả các URL cũ còn trên dev thì lại ko hiển thị được. F12 thì thấy lỗi báo Mixed Content, debugbar gọi sai link ajax, đúng ra phải có https nhưng lại gọi http


Debug dần ta phát hiện ra tham số URL ajax được thiết lập ở đoạn code JS PhpDebugBar.OpenHandler ... Và nguyên nhân gốc rễ là hàm route() đã trả về link bị sai https

$openHandlerUrl = route('debugbar.openhandler');
$renderer->setOpenHandlerUrl($openHandlerUrl);

(code trong file LaravelDebugbar.php)

Vậy tại sao lại xảy ra vấn đề này khi mà local thì okie, dev mới bị! Tìm hiểu thêm thì ta thu được kết quả: do trên dev chạy qua proxy nên Laravel ko "nhận diện được" HTTPS. Lúc này hàm (1) $request->isSecure() cũng bị return false và route() trả về link http thay vì https

Cách xử lý: thêm vào hàm boot() trong file code AppServiceProvider.php đoạn sau:

$this->app['request']->server->set('HTTPS', 1);

Trường hợp local chạy http, dev mới chạy https thì phải dùng .env với APP_ENV khác nhau, ví dụ APP_ENV = local và APP_ENV = dev

Khi đó code sửa lại 1 chút để debugbar hoạt động ở cả local (HTTP) và dev (HTTPS)

$this->app['request']->server->set('HTTPS', $this->app->environment() != 'local');

Ghi chú:
1. namespace liên quan tới $request ở (1) là Illuminate\Http\Request
2. Để nhận diện HTTPS khi web chạy qua proxy thì có thể tham khảo biến _SERVER['HTTP_X_FORWARDED_PROTO'] nó sẽ là 'https'

Tweet
Missing PHP debugbar popup with HTTPS Title: Missing PHP debugbar popup with HTTPS
Description: Laravel does not load URL for PHP DebugBar because mixed content. How to fix it? ...
Rating: 4

No comments :

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments ( Atom )
Quảng cáo

Popular Posts

  • VBS - Upload file HTTP Post
    Source: http://www.ericphelps.com/scripting/samples/Reference/Web/HTTP_POST.txt   Sub Upload(strUploadUrl, strFilePath, strFileField, strD...
  • Add other collapse div to your forum
    Collapse <div style="height: 16px; padding-right: 4px; font-weight: bold;" class="blockhead"> <span style=...
  • Use the YouTube API with PHP
    Process and integrate data from YouTube into your PHP application with PHP's SimpleXML extension Summary:   The YouTube vide...
  • Check Laravel version
    Đối tác bảo đang code và dùng Laravel, giờ muốn biết version Laravel tương ứng là bao nhiêu để xem mà code theo. Làm sao check? Cách 1: Sử...
  • Trong laravel thì queue:work với queue:listen khác nhau thế nào?
    Trong laravel thì queue:work với queue:listen đều chạy jobs trong queue. Vậy 2 cái này cũng phải có gì đó khác nhau chứ, nếu ko thì nó là ...
  • Hàm chuyển từ ngày dương lịch sang âm lịch (PHP)
    <?php function INT($d) {     return floor($d); } function jdFromDate($dd, $mm, $yy) {     $a = INT((14 - $mm) / 12);     $y = $yy + 4800 ...
  • Character Set và Collation trong MySQL là gì? Tạo DB thì để UTF8_GENERAL_CI hay UTF8_BIN
    Character Set là một tập các ký tự và dạng số hóa của các ký tự đó Collation là một tập các luật để so sánh các xâu được sinh ra từ các ký ...
  • git checkout file from other branch
    Đang làm trên nhánh dev. Muốn lấy 1 file, ví dụ: xxx/helper.php ở trên nhánh master về dev thì làm thế nào? Cách 1: nông dân nhiều bước nh...
  • mysql_error: Undeclared variable: INF
    mysql_error: Undeclared variable: INF PHP Code: $limit = 10; $page = isset($_GET['p']) ? $_GET['p'] : 1; $offset = ($pa...
  • Download media files (video, audio) from VnExpress.Net
    Download media files (video, audio) from VnExpress.Net Example: http://vnexpress.net/GL/Vi-tinh/Giai-tri/2010/02/3BA18A0E/page_4.asp htt...
Back to top!
Copyright 2010 Love Coding - All Rights Reserved Design by Newbie_PC - Powered by Blogger