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.

Help with PHP Redirect

March 22, 2012 9:54am

Subscribe [2]
  • #1 / Mar 22, 2012 9:54am

    brianrivet

    48 posts

    Hi,

    I’m sort of new to EE and the development side of things and I need some help. I’m running Structure on an EE site I’m building, but I have a couple of subnav items that I need to redirect to other sites. The location these links will go to depends on what user is logged in (each user has specific sites these are supposed to go to). I’ve created custom fields for the members that store the URLs of the sites. Where I’m having trouble is getting the redirect set up. I tried using the User module to access the custom fields to get the URL, but when I try to use logged_in_member_id to set the member id parameter, it doesn’t work. I’m guessing that that variable isn’t parsed early enough. So next I tried using PHP to access the session to get the member id of the current user. That works, but since I have to have the php parse stage set to input, I can’t use it to do the redirect.

    What I’ve tried doing that also doesn’t seem to work is I use an embed to get the url from the custom field. Here the code for that:

    {exp:user:users dynamic="no" limit="1" member_id="<?php echo $this->EE->session->userdata('member_id'); ?>"}{employee_hr_syslink}{/exp:user:users}

    The php setting on this template is for input, so it pulls the url just fine. I then access this embed from the following template:

    <?php
    header("Location: {embed='embeds/.employeeLink'}");
    exit;
    ?>

    The php setting on this template is set to output. If I remove the exit line, it just returns an empty page with no redirect. If I add the exit line I still get an empty page, but the EE embed tag is showing up in the window URL.

    Can anyone give me a suggestion on a good way to do this with PHP? I can make the redirect work with Javascript if there is no other way, but I’d prefer to do the redirect server side.

    Thanks,

    Brian

  • #2 / Mar 22, 2012 1:35pm

    the3mus1can

    426 posts

    This is a parse order issue. PHP on Output get parsed before the embeds do. For future reference: http://loweblog.com/downloads/ee-parse-order.pdf

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

ExpressionEngine News!

#eecms, #events, #releases