0

A while ago I attempted to re-open previous work but could not get the XAMPP Control Panel to open, I guess because I re-installed Windows 10. I then decided to download the latest versions of XAMPP & CodeIgniter and then transfer my previous files to the new system.

Previous CI_VERSION = '3.1.1' - Latest CI_VERSION = '3.1.9' - Previous PHP version: 7.0.8 - Latest PHP version 7.2.3

When my current system directs to the "username" page which is where the username & password are created, I get the following error. This function was working OK in my previous system. It appears to be caused by a difference between the versions of PHP.

A PHP Error was encountered Severity: Warning

Message: Use of undefined constant BASE_URL - assumed 'BASE_URL' (this will throw an Error in a future version of PHP)

Filename: username.php Line Number: 47

This is Line 47

<form class="form" method="post" action="<?php echo BASE_URL . 'username'; ?>">

Backtrace:

File: C:\xampp\htdocs\application\views\username.php Line: 47 Function: _error_handler This is Line 47 - ">

File: C:\xampp\htdocs\application\controllers\Username.php Line: 70 Function: view This is Line 70 - $this->load->view('username', $data);

File: C:\xampp\htdocs\index.php Line: 315 Function: require_once BASE_URLusername"> This is Line 315 - require_once BASEPATH.'core/CodeIgniter.php';

Can somebody advise me of what I need to change?

Update 1

The only place I can find a definition of base_url is in /config/config.php which is following;

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

And that has not been changed between my previous work and this current system.

Update 2

In the Controller Username.php there is a load function

$this->load->helper(array('form', 'url'));

But I can't find anything in the helper folder other than index file.

And again that has not been changed between my previous work and this current system.

1

4 Answers 4

0

The constant BASE_URL was defined somewhere in the old code but is not in the new. CodeIgniter does not define a constant called BASE_URL so it was done in some custom code. It probably looked something like this

define('BASE_URL', base_url());

There are other ways to obtain the value so the main thing to look for is define('BASE_URL',.

Likely places to look are customized versions of /config/config.php or /config/constants.php, but there are lots of other places including a base controller, custom library or some other user-created configuration file.

Sign up to request clarification or add additional context in comments.

Comments

0

I couldn't find any constant called BASE_URL in the latest CodeIgniter source code. Their documentation recommends using the base_url() function for returning the site's base URL. https://www.codeigniter.com/user_guide/helpers/url_helper.html?highlight=base_url#base_url

There was, however, and older repo on GitHub where I could find a version of CodeIgniter where the constant BASE_URL was defined in the constants.php file. https://github.com/assoft/codeigniter/blob/master/application/config/constants.php Probably this was common practice for older versions.

So, in your example you can use the base_url() function. This should output http://www.example.com/username

<form class="form" method="post" action="<?php echo base_url('username'); ?>">

You have to import the url helper in the method of the controller corresponding to the view you're using.

$this->load->helper('url');

You should also fill in the value for the base url in the application/config/config.php file.

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

Comments

0

you have to define base_url. i am using this in header file.

 <script>
 var base_url = '<?php echo base_url(); ?>';
 </script>

Comments

0

I found my problem. In constants.php of my old system there is the following,

define('BASE_URL', 'http://localhost/');

I copied that into the my current contants.php file and it works, that is to say I don't get the error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.