John Davidson

php - On production protocol change from https to http on server

0 comments
Message:


I am using the latest version of select2 with Codeigniter 4


I have 3-4 dropdown with ajax search on same page. And when page load select2 initialized on those dropdown.
On the same page I am using base_url to create dynamic Url.


Sections are


This is form action


action="<?= base_url('requests/booking/' . (isset($file['myId']) ? $file['myId'] : '')) ?>"

And it converted to

https://mysiteurl.com/requests/booking/myId

Above code generates https url with same as domain.


This is dropdown section


I set these attributes in my dropdown with select 2


<select class="ms select2 select2-ajax companyAddress"
data-call-url="<?= base_url('ajax/bookingShipperAddress') ?>"
data-placeholder="Company">
</select>

In above section when it initialized the data-call-url, It's protocol change to http instead of https
There are also more dropdown except only url endpoint changed.


My JQuery Code.


applySelect2: function (className = 'select2-ajax') {
$('.' + className).each(function () {
var url = $(this).data('call-url');
let placeholder = $(this).data('placeholder');
if (url && ((url != "undefined") || (url != "undefined"))) {
$(this).select2({
placeholder: placeholder ?? 'Select an option',
ajax: {
url : url,
dataType: 'json'
}
});
} else {
$(this).select2({
placeholder: 'Select an option'
});
}
$(this).removeClass(className)
});
/**
* Use below code to get other variable for selected value
*
* var select2Obj = $(this).select2('data').find(item => item.element.selected);
*/
}

Although It works on my local because of http but not on production


See these Screenshots of element code of server


. Check form url with page url. Link
. Check dropdown url with page url. Link



My Answer:
"https://example.com/form_submit"

If you are experiencing an issue where the protocol changes from HTTPS to HTTP on the server, you may need to check your server configuration or any redirects that may be causing this behavior.

In Codeigniter 4, you can set the base URL in your config file located at `app/Config/App.php`. Make sure that you have set the base URL to use HTTPS:

php
public $baseURL = 'https://example.com/';


Additionally, when creating dynamic URLs using `base_url()` function in Codeigniter, make sure to always use the `base_url()` function to generate URLs to ensure that the correct protocol is used:

php
echo base_url('controller/method');


If you are still facing issues with the protocol changing from HTTPS to HTTP, you may need to check your server configuration or consult with your hosting provider for further assistance.

Rate this post

4 of 5 based on 1608 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us