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

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.

Related

Default controller (under modules) not loading under HMVC, CodeIgniter, throws 404 err

Just migrated my CI from localhost to live. Everything works fine on localhost with same settings.
Here're the folder/file structure and contents of routes.php
-application
--controllers
---Home.php
--modules
---specs
----controllers
-----Specs.php
----models
----views
$route['default_controller'] = 'Specs/index';
//$route['default_controller'] = 'Home/index';
$route['404_override'] = 'Errors/show_404';
$route['translate_uri_dashes'] = FALSE;
Both Specs and Home controllers have index method. When I load the home page url with Specs/index as default controller, I get 404 error. But if I change the default controller to Home/index, it loads just fine. Strange. Everything else works just fine on whole site. Can't figure out.
The website is live but I'm not sure if providing url is allowed, so I'm including spaces in it. It's unspecs dott comm. Admin/Mods may please remove if url isn't allowed.
Thanks for reading.
I think you are doing mistake in routing, for HMVC it should be like that -
$route['default_controller'] = '<folder name>/<controller name>/<function name>';
$route['default_controller'] = 'specs/Specs/index';
Please follow this, hope it will work fine.
Try this https://stackoverflow.com/questions/6529026/codeigniter... But better use standart folder for default controller /application/controllers

How to convert static IP address to new domain name

I have developed a website in codeigniter that has been hosted on a static ip address http://182.184.79.154.
Now I want to transfer all the urls of this website to a new domain http://integratedschoolsystem.com.
Can anyone help me how to do this ?
If I understand the question, you're trying to change the PHP application to address the links, not the DNS entry. In that case, assuming you followed Codeigniter's practices by using base_url() for all of your links, then all you have to do is update the config file.
\application\config\config.php
Line 26 (usually) is $config['base_url'] = '';
So set that to whatever your domain is, in this case:
$config['base_url'] = 'http://integratedschoolsystem.com';
https://www.codeigniter.com/userguide3/libraries/config.html

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 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 ?

Https (SSL) in Codeigniter not working properly

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.

Resources