Https (SSL) in Codeigniter not working properly - codeigniter

I have a CI site with several form using jquery .click function, when I was in http its worked well, when I change to https all the form click button cannot be fire, its happen in localhost and in web host as well, is that anything need to config to run CI in https?
please advise and thanks!
Solved:
I just remove the url from $config['base_url'], and now the issue is solved, but I wonder how come when running https couldn't set value on $config['base_url']? hope someone would clear my doubt.
Thanks guy for taking time to view my question.

Set your base_url protocol independent:
$config['base_domain'] = 'yourdomain.com'; // a new config item if you need to get your domain name
if (isset($_SERVER['HTTP_HOST']))
{
$protocol = ($_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://');
$config['base_url'] = $protocol.$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
}
else
{
$config['base_url'] = '';
}
I am guessing your ajax request fails because you are trying to access no-secure content from a secure site.

I had a similar issue. I simply changed the base URL from HTTP to HTTPS in the config file and it worked well for both protocols.
# Base URL in codeigniter with HTTP
$config['base_url'] = 'http://mysite.abc/';
# Base URL in codeigniter with HTTPS
$config['base_url'] = 'https://mysite.abc/';
Remember, when you change HTTP to HTTPS, the site should work well for both protocols but it doesn't work the other way around.

Related

Yii2 https URLs do not work

I try to run my local copy of my yii2 site with https.
I use this in config to force http url to https
'on beforeRequest' => function ($event) {
if(!Yii::$app->request->isSecureConnection){
$url = Yii::$app->request->getAbsoluteUrl();
$url = str_replace('http:', 'https:', $url);
Yii::$app->getResponse()->redirect($url);
Yii::$app->end();
}
},
The only url I can reach is the home page i.e. a bare url such as
example.ext
Other URLs give
Not Found The requested URL /site/index was not found on this server.
When removing the 'onbeforerequest' in the config, I can reach every http URL.
Question: why https URLs become unreachable?
Eventually I made out that there was no url rewrite for pretty url in the virtualhost litening to 443 port.
Adding the recommended rewrite rule in it solved the problem.
#stfsngue: Thank you for comment
Do you see any particular reason for preferring .htacces to 'onbeforeRequest' to force https?

CI 3.1.3 URL in the address bar changed but showing the same page (default controller)

I got a problem here, I just created a website using CI 3.1.3, I already add a .htaccess file and also Setup the base_url config
$config['base_url'] = $_SERVER['REQUEST_URI'];
I already create the Controller, and add it to the routes.
But whenever I click a link that redirect to another page, the url in the address bar is changed, the browser is loaded, but it still showing the same page that were set in the default controller,
I already tried to search it on the google but can't find the answer, and actually I don't know how to describe my problem is.
But please help me to solve this problem, thank you
This is what I use
$protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://';
$config['base_url'] = $protocol . $_SERVER['HTTP_HOST'] . str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']);
Does it work without .htaccess and/or route config?

Codeigniter url changes from 'localhost' to 'http://127.0.0.1/'

https://stackoverflow.com/a/29562910/4713946
This is my problem, and I am not sure about the answer. I am unsure where I put this code. I cannot comment on the post itself as I do not have enough reputation so I have to start a new thread. /:
Can someone maybe help me out.
I do a redirect() and when I do this, the 'Localhost' changes to '127.0.0.1'
So turns out all I had to do was change 'base_url' in 'config.php' file:
$config['base_url'] = '';
to
$config['base_url'] = '/';
You should set your base url if your using codeigniter 3 versions
$config['base_url'] = 'http://localhost/yourproject/';
If base url is blank it codeigniter 3 versions will show ip_address in url instead of localhost.

codeigniter baseurl not working

I am using the baseurl() in my application. ex: "http://www.edocapp.in"
This is working in case if we type domain name with "www" but not working if I use "only http".
Application is hosted on server.
try
$config['base_url'] = 'http://www.edocapp.in';
this
Base URL should have / in the last char:
$config['base_url'] = 'http://www.edocapp.in/';
anyway, you should check your DNS record in your server/hosting.
Does it have an alias (CNAME Records) to redirect www.edocapp.in to edocapp.in ?

Codeigniter: how to use secure urls along with normal url

How can I use HTTPS along with HTTP in codeigniter and in its base_url.
Note sure about the link generation, yet I might be able to help you with the base URL. PHP usually offers you the $_SERVER array which is available within the config files. So instead of hard coding the Base URL I usually make it dynamic using the server URL. Same works with the HTTPS status. Untested but should work:
$config['base_url'] = sprintf('%s://%s/', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'), $_SERVER['HTTP_HOST']);
Be careful when using the HTTPS index. I've read about setups where its 1 instead of on. You better probe your server variables using phpinfo().
cu
Roman
If you use Codeigniter 2.0 and above,
You need not to specify base_url in the config file rather if you let it empty, it automatically detects whether it may be a HTTP or HTTPS url.

Resources