Rewriting the "redirect.html" script

Discussion in 'Customization & add-ons' started by dereck_j2, Aug 25, 2011.

  1. dereck_j2

    dereck_j2 Member

    Joined:
    Aug 22, 2006
    Messages:
    42
    Hi all,

    I am trying to rewrite the "redirect.html" script so I can redirect to different redirect script depending on the browser type accessing an account.

    This is what I have:
    Code:
    {if $browser = strstr($_SERVER['HTTP_USER_AGENT'],"iPhone")}
    			{if $browser == true }
    				{$_SESSION['iPhone'] = 1}
    				{header ("location: redirect_iphone.php")}
                {/if}    
    {elseif $browser = strstr($_SERVER['HTTP_USER_AGENT'],"iPad")}
    			{if $browser == true }
    				{$_SESSION['iPad'] = 1}
    				{header ("location: redirect_ipad.php")}
                {/if}     
    {elseif $browser = strstr($_SERVER['HTTP_USER_AGENT'],"Android")}
    			{if $browser == true }
    				{header ("location: activate/account_activation_android.php")}
                {/if}     
    {elseif $browser = strstr($_SERVER['HTTP_USER_AGENT'],"BlackBerry")}
    			{if $browser == true }
    				{header ("location: activate/480_360_account_activation.php")}
                 {/if}   
    {else}
    			{header ("location: ")}
    			
    {/if}	
    
    When I try and run the script I get an error "unbalanced parenthesis in if statement"

    Can anyone spot where I am going worng.

    Many thanks in advance.
  2. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
  3. dereck_j2

    dereck_j2 Member

    Joined:
    Aug 22, 2006
    Messages:
    42
    Hi David,

    Many thanks for your reply. I did what you stated but I get the same error:
    I removed the {/if} before the {elseif, error is "unbalanced parenthesis in if statement"

    The way I am looking at it is the {/if} closes the {if $browser == true }
    statement. within in each of the "if" and "elseif" statements I have another "if" which test for $browser content. Or am I doing this completely wromg.

    Code:
    {if $browser = strstr($_SERVER['HTTP_USER_AGENT'],"iPhone")}
    	{if $browser == true }
    	     {$_SESSION['iPhone'] = 1}
    	     {header ("location: redirect_iphone.php")}
                 {/if} 
    {elseif $browser = strstr($_SERVER['HTTP_USER_AGENT'],"iPad")}
    	  {if $browser == true }
    	     {$_SESSION['iPad'] = 1}
    	     {header ("location: redirect_ipad.php")}
                 {/if}     
    {elseif $browser = strstr($_SERVER['HTTP_USER_AGENT'],"Android")}
    	  {if $browser == true }
                     {$_SESSION['Android'] = 1}
    	    {header ("location: activate/account_activation_android.php")}
                 {/if}    
    {elseif $browser = strstr($_SERVER['HTTP_USER_AGENT'],"BlackBerry")}
    	{if $browser == true }
                     {$_SESSION['BlackBerry'] = 1}
     	    {header ("location: activate/480_360_account_activation.php")}
                {/if}     
    {else}
    	{header ("location: ")}
    			
    {/if}	
    
    Again, many thanks for your help.
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Dereck,
    You use wrong syntax for template.
    For example, these lines are incorect:
    {$_SESSION['Android'] = 1}
    {header ("location: activate/account_activation_android.php")}
    Also you don't need to use smarty for this task at all.
    You can use regular php code inside smarty template:
    Code:
    {php}
    if($browser = strstr($_SERVER['HTTP_USER_AGENT'],"iPhone")){
    header('Location: ...');
    }
    {/php}
    
    Also I don't think that redirect.html template is correct place to make such mod for several reasons:
    1. This is not good to use header('location ') here.
    2. aMember use this template to redirect user to several places depending on situation, but your mods will break this.
    Please explain what you try to do exactly I will help.

Share This Page