CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions (Moderator: Dave Greenberg) »
  • Don't use a hardcoded value for the host
Pages: [1]

Author Topic: Don't use a hardcoded value for the host  (Read 1606 times)

Roman Zimmermann

  • I’m new here
  • *
  • Posts: 24
  • Karma: 2
    • more onion
Don't use a hardcoded value for the host
July 13, 2010, 07:37:27 am
Currently CiviCRM uses a hardcoded value ( CIVICRM_UF_BASEURL ) to construct some of it's URLs.

This is a nuisance for people have multiple domains pointing to the same installation of CiviCRM (or drupal in this case).

In our case we have different domains which respectively point to localized versions of our drupal pages. CivicCRM only works with one of them, as the session cookie is lost (or rather not submitted by the browser), when the browser is redirected to another domain.

To work around this, I would suggest to only set the directory part of the URL in the config-file and then construct the full URL with the variables $_SERVER['HOST'] and $_SERVER['PORT'].

I'll happily provide you with a patch to implement this. So what do you think?

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Don't use a hardcoded value for the host
July 13, 2010, 09:55:20 am
Hi,

That it won't work with the "right" combination of proxy/ reverse proxy, mod rewrite, http, https, white magic and black magic.

For instance, $_SERVER['HOST'] isn't set if you run the crons to send emails and so on from php-cli

Don't recall a framework that has been able to completely bypass it (in drupal, they still have this variable as an option, and that's a good think, because didn't work without it on my lighttd ;)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Roman Zimmermann

  • I’m new here
  • *
  • Posts: 24
  • Karma: 2
    • more onion
Re: Don't use a hardcoded value for the host
July 14, 2010, 12:45:34 am
Ok, I see.

For my setting I could simply configure this variable using the $_SERVER variables and make it work that way.

I just was irritated because drupal worked just fine and civicrm didn't…

Roman Zimmermann

  • I’m new here
  • *
  • Posts: 24
  • Karma: 2
    • more onion
Re: Don't use a hardcoded value for the host
July 14, 2010, 06:15:17 am
Ok for my site I use now a rather hackish solution in civicrm.settings.php:


$bu = 'http://www.domain.com/';
$bu_path = '/';
$bu_active = true;
if ($bu_active && isset($_SERVER['HTTP_HOST'])) {
        $bu_host = $_SERVER['HTTP_HOST'];
        $https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] != 'off';
        if (isset($_SERVER['SERVER_PORT']) && (
             ($_SERVER['SERVER_PORT'] != 80  && !$https) ||
             ($_SERVER['SERVER_PORT'] != 443 &&  $https)
          )) {
                $bu_host .= ':'.$_SERVER['SERVER_PORT'];
        }
        $bu = 'http'.($https ? 's' : '').'://'.$bu_host.$bu_path;

}
define( 'CIVICRM_UF_BASEURL'      , $bu );


It should work in most circumstances as it kicks in only when $_SESSION['HTTP_HOST'] is available - and it's also possible to switch it off via $bu_active.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Don't use a hardcoded value for the host
July 14, 2010, 07:27:32 am
Why do you keep a separate $bu and CIVICRM_UF_BASEURL ?

Better to

// uncomment the next line if you want to define yourself the base url. By default, it automatically try to find it
// define( 'CIVICRM_UF_BASEURL'      , 'http://example.org );

if ( not defined CIVICRM_UF_BASEURL)
  all the magic...
  and a big die ("need to set manually CIVICRM_UF_BASEURL in civicrm.settings") if you don't have all what you need


civicrew, all the magic should go into a function put somewhere to be as clean as possible, and get a chance to end up in the core ?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Roman Zimmermann

  • I’m new here
  • *
  • Posts: 24
  • Karma: 2
    • more onion
Re: Don't use a hardcoded value for the host
July 14, 2010, 11:13:21 am
Thanks for your suggestion.

I did plan to put this into an extra function, but I took your first comment as indication, that this would not become part of the core anyhow … Where would be the right location to put this? As static function into CRM_Core_Config?

Optionally defining the constant makes it necessary to replace each of it's occurrences with a function call. For maintainability reasons this is only a viable option IF this feature is accepted into civicrm.

Also your proposed solution does behave differently: My version uses the value of $bu as a fallback value (ie. when a script is called from CLI), whereas your's would simply fail to provide a meaningful value.

Perhaps I will prepare a patch in the next few days, if you see any chance that it's going to be accepted.
« Last Edit: July 14, 2010, 01:57:33 pm by torotil »

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Don't use a hardcoded value for the host
July 14, 2010, 02:45:16 pm
Check on IRC and ask, the core developers are there most of the time.

The idea of my solution was to mimic what drupal does: if this is hardcoded, use this one, but by default, try to guess, and fail if you can't guess nor is it hardcoded.

As you said, won't work from the cli, but then you hardcode it and it's like it is today.

Actually, might modify civicrm_cli to try getting drupal's hardcoded root url if the civicrm one isn't defined. So at least, you have to put it only once.

(thinking loud)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Roman Zimmermann

  • I’m new here
  • *
  • Posts: 24
  • Karma: 2
    • more onion
Re: Don't use a hardcoded value for the host
July 17, 2010, 10:18:26 am
I think searching for the userframework's configuration is not such a bad idea. But I think it's better suited to be implemented on it's own, in it's own module.

BTW: you probably already saw the issue I opened for this.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions (Moderator: Dave Greenberg) »
  • Don't use a hardcoded value for the host

This forum was archived on 2017-11-26.