Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Getting parent url codeigniter
#1

[eluser]riwakawd[/eluser]
On my codeigniter project I have sub folder called admin so url would be http://localhost/project/admin/

On the admin index.php I have a function which allows me to define url path so do not have to enter it in config.php so all I would have to enter in base url is $config['base_url] = BASE_SERVER; which returns http://localhost/project/admin/

Problem

But also I same function renamed that should get the parent url but does not.

Still gets the current url.

Question

How do I change the $catalog_url to get parent url http://localhost/project/

On my admin index.php
Code:
<?php
// Admin Server

if (isset($_SERVER['HTTP_HOST'])) {
    
$base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
$base_url .= '://'. $_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);

} else {

// Back Up Url
$base_url = 'http://localhost/';

}

define('BASE_SERVER', $base_url);

unset($base_url);

// Catalog Server

if (isset($_SERVER['HTTP_HOST'])) {
    
$catalog_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
$catalog_url .= '://'. $_SERVER['HTTP_HOST'];
$catalog_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);

} else {

// Back Up Url
$base_url = 'http://localhost/';

}

define('CATALOG_URL', $catalog_url);

unset($catalog_url);


config.php

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/

$config['base_url'] = BASE_SERVER;

$config['catalog_url'] = CATALOG_URL;
#2

[eluser]riwakawd[/eluser]
After thinking about it for a while I had to do this working great now.

Code:
if (isset($_SERVER['HTTP_HOST'])) {

$catalog_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';    
$catalog_url .= '://'. $_SERVER['HTTP_HOST'] . rtrim(rtrim(dirname($_SERVER['SCRIPT_NAME']), 'admin'), '/.\\'). '/';

} else {

// Back Up Url
$base_url = 'http://localhost/';

}

define('CATALOG_URL', $catalog_url);

unset($catalog_url);




Theme © iAndrew 2016 - Forum software by © MyBB