Codeigniter Echoing [::1] Instead of Localhost

Codeigniter echoing [::1] instead of localhost

It's because of your base_url is empty.

In config/config.php

$config['base_url'] = 'http://localhost/project_name';

Something more interesting about http://\[::1\]/

base_url() echoing localhost path instead of live server path

When environment is changed (eg. dev/pro/local) make sure that you have cleared browser cache memory so new values that are set by application are shown correctly.

All in all:

-Windows

Ctrl+F5

-MacOS

Cmd+Shift+R

Or use private browsing window.

Very useful links:

  • How do I clear my web browser's cache, cookies, and history?
  • What requests do browsers' "F5" and "Ctrl + F5" refreshes generate?
  • Keystroke to reload a page without cache in Chrome for OS X
  • https://superuser.com/questions/220179/how-can-i-do-a-cache-refresh-in-google-chrome

Why I'm not redirected properly to base_url() in CodeIgniter?

Because your href does not start with http:// or / so the browser will simply append the url into your current url.

Take a look at the difference here:
https://jsfiddle.net/ChinLeung/c1t6vw4v/

To fix it, change your config to:

$config['base_url'] = 'http://localhost/projekt/';

CodeIgniter base_url(), link in localhost gives me to live server

You can create two folders inside application/config one for production(live server) and one for development(localhost)

  • development => application/config/development
  • production => application/config/production

Then copy any file in the main application/config folder and paste it into both development and production folders.

application/config/development/config.php

$config['base_url'] = 'http://localhost';

application/config/production/config.php

$config['base_url'] = 'http://example.com';

Based on your ENV constant in index.php it will load settings from either production or development folders. So if ENV == 'development' the settings in application/config/development will get used.

If you want a relative path to your assets, add this to the HEAD of your html

<base href="<?php echo base_url();?>" />

Then you can just ref your assets like so

<link rel="stylesheet" href="assets/styles.css" />

I cannot pass the id to the controller?

You are opening php tags twice. make it like this:

<?php 
$i = 1;
foreach ($view as $row)
{
echo "<tr>";
echo "<td>".$i."</td>";

echo "<td><a href='" . base_url('admin/play' . $row->audio) . "'>" . $row=>audio . "</a><td>";

$i++;
echo "</tr>";
}

how to remove index.php from codeigniter path

HTACCESS

RewriteEngine on
RewriteRule ^(.*)$ ./index.php/$1 [L]
RewriteCond $1 !^(index\.php|resources|robots\.txt)


Related Topics



Leave a reply



Submit