Welcome Guest, Not a member yet? Register   Sign In
current_url returns the url from the config, not the real url!
#1

[eluser]Chad Crowell[/eluser]
I know from the url helper code that this is by design -

What I need is the actual url. I have a site that can be accessed via several subdomains, and based on the subdomain it will show certain info in the header. So,

abc.domain.com
def.domain.com
xyz.domain.com

are actually all the same website install and I need CI to actually read the domain name in the address bar, not what is in the config.

I have tried lots of options and am extending the current_url function of the URL helper but this code (actually any code where i try to use $_SERVER['HTTP_HOST']; or $_SERVER['REQUEST_URI']; is throwing an error) is giving me this error:


A PHP Error was encountered
Severity: Notice
Message: Undefined index: host
Filename: models/my_model.php
Line Number: 13


Here is my current function:

Code:
<?php //enhanced url helper

function current_url()
{
  $domain = '';
  
  $_URL = parse_url($_SERVER['HTTP_HOST']);
  
  // sanity check
  if ( empty($_URL) || empty($_URL['host']) )
  {
    $domain = '';
  }
  else
  {
    $domain = $_URL['host'];
  }
  
  return $domain;
}

?>
#2

[eluser]Cro_Crx[/eluser]
Can you put in the results of print_r($_SERVER) on the page you're getting an error as it may help.
#3

[eluser]Chad Crowell[/eluser]
Ah that helps - looks like I can use $_SERVER['SERVER_NAME'] to get what I need. Thanks for the pointer.




Theme © iAndrew 2016 - Forum software by © MyBB