I have received website code from somebody else & it's giving a lot of errors in loading. Every CSS, image or anything is loaded by this code
href="<?php echo asset_url();?>/css/...
Now I checked, asset_helper.php & found out this
function asset_url(){
return BASE_URL.'public'
}
In my config.php, line says $config['base_url'] = '';.
Finally when I tried to echo asset_url();, it gives me https://somerandomwebsite.com/.... I'm not sure from where this is coming from.
Sorry I'm new to CodeIgnitor & tried everything I could to find out but there was no luck. Can anybody help me in this?
Your Helper function might be using constant function. Check your constan.php file.
define(BASE_URL, "http://test.com");
First things first: the manual!
https://codeigniter.com/user_guide/helpers/url_helper.html?highlight=base_url#base_url
ok so they made a new function just to deal with an extra subfolder name in stead of just doing base_url(). 'public' or base_url('public') and have defined a BASE_URL somewhere which is not part of the core of CI. Track that BASE_URL down and kill it if possible. You can and should use base_url().
I use this for base_url (avoids hardcoded url):
$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']);
I usually autoload the thing in config/autoload.php:
$autoload['helper'] = array('url');
Related
I am trying to use baseurl() in my application, but it's not working. I've attached two photos, and . Can anybody help me solve this?
$config['base_url'] = 'http://localhost/class-19/';
hiii...Please replace baseurl() to base_url().
In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php:
$autoload['helper'] = array('url');
Or, manually:
$this->load->helper('url');
Once it's loaded, be sure to keep in mind that base_url() doesn't implicitly print or echo out anything, rather it returns the value to be printed:
echo base_url();
Good evening guys, I have a problem with the attribute href because I don't know how to access folders, I give an example:
I stay in root/store/products/details.php
I want to go root/index.php
My answer is : How do I arrive to root/index.php ? I has been trying with ../../index but that didn't worked
If root is the base path on your domain, e.g. example.com/root, then if you're at example.com/root/store/products/details.php, you would have a link like below to get to your root. This href will actually work on any page. If you use ../../index.php it will only work on some pages.
Root
This is how I make all of my template links portable.
For files processed Server-Side you would link by using the SERVER_ROOT and for links in an -a href=...' you would use the SITE_ROOT.
define('SERVER_ROOT', dirname( __FILE__ ) . DS);
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ?
'https://' : 'http://') . $_SERVER['SERVER_NAME'];
if (strlen( $url ) <= 10) $url = null; // For IDE Support
define( 'SITE_ROOT', $url . DS); // The base URL
So to implement the above
Post Score</li>
Use <a href="../../index.php">
Demo Snippet:
var base = 'https://example.com/store/products/details.php'
var relative = '../../index.php'
var target = new URL(relative, base).toString()
console.log(target)
PHP defaults to index.php so you can link to
Link text
By prefixing a URL with /, like "/root/" instead of "root/", you are forcing it to read from the root of your webhost or with a VPS the directory of the website.
If you customised the DirectoryIndex you can do Link
I am using CodeIgniter 3 as a web platform and trying to import semantic-UI CSS into my page. I'm doing so by using CodeIgniter's base_url() method in the href property for the CSS import.
However, semantic.css itself imports some other fonts on my server, which cannot load because of Cross-Origin resource sharing policy. This is the error message chrome gives me:
Font from origin 'http://[::1]' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
This is because base_url() echoes the domain has been [::1] and not localhost as I've typed into the browser.
For some reason, it appears to me that chrome (and also Edge) does not consider [::1] and localhost as the same host, or maybe I'm just being dumb. What I know though is that if I change the path of the main semantic.css file and complex code localhost into it, it works, and it also works if, instead of requesting my page using localhost, I use [::1]
I've done other projects very similar to this and never had this "[::1]" appear. What exactly is causing PHP to echo such a path?
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\]/
You need to edit your $config['base_url'] as follows,
$config['base_url'] = '';
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://" . $_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']);
File location: codeigniter/application/config/config.php
Use above code to get dynamic url.
More accurate and dynamic way
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= dirname($_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
Though you can still use port.
In order to use base_url(); you must first have the URL Helper loaded. This can be done either in application/config/autoload.php (on or around line 67): or you can manually using
$this->load->helper('url');
than set the
$config['base_url'] = 'http://localhost/your_site_url';
i think it will help you
This is what you need to alter in config/config.php, it works properly in "localhost" as well as in your "server":
$config['base_url'] = "http://".$_SERVER['SERVER_NAME'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
if(!defined('DOCUMENT_ROOT')) define('DOCUMENT_ROOT',str_replace('application/config','',substr(__FILE__, 0, strrpos(__FILE__, '/'))));
$config['base_path'] = constant("DOCUMENT_ROOT");
$config['js_url'] = $config['base_url'].'js/';
$config['css_url'] = $config['base_url'].'css/';
$config['image_url'] = $config['base_url'].'img/';
// Host resolution for cross origin requests
if(ENVIRONMENT == 'production') {
$config['host'] = 'www.<domain_name>.com';
} else {
$config['host'] = 'localhost';
}
I found it is unusual with the latest stable version of CI (3.03),
I tried echo base_url() and it returns some unusual thing,
**Note: ** I have loaded the URL helper .
The following code
$this->load->helper('url');
echo base_url();
returns http://127.0.0.1/ (I have used http://localhost/ to interpret the application) in Firefox.
And:
http://::1/ (Same I have used http://localhost/ ) in Chrome ?
Help me guys in fixing this.
Please remove base_url form the config file if you set there,
$config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/";
In your config, use define. like below:
define('base_url', 'http://localhost/your_project name/');
And then try
echo base_url() ;
Make sure you have set a base url
$config['base_url'] = 'http://localhost/project/';
Some times for me that is issue.
In older versions of CI you use to be able to leave that blank but.
Now it is recommended that you do not leave that base_url blank.
And I would auto load the url helper as it is the most common one.
I've built a function that basically links an excerpt to its relative post. In order to do that I have figured that the variable $_SERVER['SERVER_NAME'] could come in handy in building the path.
I don't know if this is due to the fact I am testing the page on a local environment, but on my local machine the path I have is like http://localhost/webdir/localhost/index.php?p=3 localhost is repeated twice. What could possibly cause this?
Try even this
Edit works great for almost all type of URL..
<?php
$l1=explode('?',$_SERVER["SERVER_NAME"]);
$link='http://'.$l1[0];
echo $link;
echo '<h2><center>Add users</center></h2>';
$pageURL = $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
$pageURL1 = $_SERVER['SERVER_PORT'] != '80' ? $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"] : $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$pageURL=$pageURL.$pageURL1;
//$pageURLt=explode('?',$pageURL);//Uncomment this and next line if you don't want get variable
//$pageURL=$pageURL.$pageURLt[0];
echo $pageURL;
?>
use like this
$link='http://'.$SERVER_['SERVER_NAME'];
And if you don't want any GET type of value use this
$l1=explode('?',$SERVER_['SERVER_NAME']);
$link='http://'.$l1[0];
Hope this help you.