ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Assigning global variables in index.php to handle SSL pages

May 13, 2010 2:46pm

Subscribe [3]
  • #1 / May 13, 2010 2:46pm

    Ryan Blaind

    168 posts

    Quick question, kind of related to my question in the other thread. I am trying to achieve some functionality that was mentioned in a blog post by Brandon Kelly.

    Essentially I would like to add a couple of new global variables into index.php so that I can use them in my templates. The only problem is on Brandon’s site he is using EE 2.0, and on mine I am still on 1.6.9.

    The code for adding the variables is like so:

    $assign_to_config['site_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
    $assign_to_config['global_vars']['site_ssl_url'] = str_replace('http://', 'https://', $assign_to_config['site_url']);
    $assign_to_config['global_vars']['site_proto_url'] = ($_SERVER['HTTPS'] == 'on' ? $assign_to_config['global_vars']['site_ssl_url'] : $assign_to_config['site_url']);

    What I am wondering is how I can modify these lines to work with EE 1.6.9, or if it won’t work that way on this version, where/what can I add to get what I want.

    essentially this explains why I want to do this:

    Now, {site_url} is being defined right in index.php, {site_ssl_url} will always be the same as {site_url} except with an https:// prefix, and {site_proto_url} is either set to the {site_url} or {site_ssl_url}, depending on whether or not the current request is coming over SSL.

    From there, it was just a matter of plugging these new tags in where appropriate. Links to members/* (which would be redirected to https:// anyway) are now created using {site_ssl_url}:

  • #2 / May 13, 2010 4:14pm

    Ryan Blaind

    168 posts

    anyone have any ideas on this one by chance? would love to get it working this way instead of having to use conditionals in my templates.

  • #3 / May 13, 2010 4:22pm

    Lisa Wess

    20502 posts

    In 1.x, you’d use path.php Global Variables.

  • #4 / May 13, 2010 4:33pm

    Ryan Blaind

    168 posts

    Great, thanks Lisa. However, unfortunately I have no idea how to convert the example from my first post into the proper syntax for path.php global variables. Sorry to be a pain in the butt.

  • #5 / May 13, 2010 4:38pm

    Ryan Blaind

    168 posts

    I think I am going to take a stab at this using the fresh variables module and see how far I get. Thanks again Lisa.

  • #6 / May 13, 2010 7:05pm

    Gareth Davies

    491 posts

    Guess it’d be something like this? Open path.php and add this:

    Edited to remove incorrect code to avoid confusion
  • #7 / May 13, 2010 11:31pm

    Ryan Blaind

    168 posts

    hmm I pasted that into my path.php and then the site stopped loading /:

  • #8 / May 14, 2010 1:44pm

    Gareth Davies

    491 posts

    Sorry too much copying and pasting without thinking what I was doing. Wonder if this does the trick:

    $site_url = 'http://'.$_SERVER['HTTP_HOST'].'/';
    $site_ssl_url = str_replace('http://', 'https://', $site_url);
    $global_vars = array(
    'site_proto_url' => ($_SERVER['HTTPS'] == 'on' ? $site_ssl_url : $site_url),
    'site_ssl_url' => $site_ssl_url
    ); // This array must be associative
  • #9 / May 14, 2010 2:48pm

    Ryan Blaind

    168 posts

    wow! thanks Gareth. That worked like a charm. awesome, I am so happy right now. cheers (:

  • #10 / May 18, 2010 9:24am

    LucPestille

    146 posts

    That was exactly what I was looking for - thanks for converting to 1.6.X code for us…

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases