PHP Redirect with Google Analytics ?

Discussion in 'Web Design and Development' started by fab5freddy, Oct 5, 2009.

  1. fab5freddy macrumors 65816

    fab5freddy

    Joined:
    Jan 21, 2007
    Location:
    Heaven or Hell
    #1
    I would like to make a Redirect Page with some Google Analytics on the Page
    too, before i send the redirect page to an affiliate offer.

    What is the best way to do this ?

    ps. What's better a PHP Redirect or an.htaccess Redirect ?

    Thanks for any suggestions!
     
  2. pfealey macrumors member

    Joined:
    Aug 27, 2009
    Location:
    Weston-super-Mare, UK
    #2
    Something like this?




    PHP:
     
    <!-- Google Analytics Stuff Here -->
     
    header("Location: http://www.foo.com/bar.php"true301);
     
  3. fab5freddy thread starter macrumors 65816

    fab5freddy

    Joined:
    Jan 21, 2007
    Location:
    Heaven or Hell
    #3
    I have read that it won't allow any code before a PHP Redirect ??

    Is this true ?

    THanks!
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    You cannot have any output to the screen such as echo or print statements or any HTML before using the header function. PHP header.
     
  5. pfealey macrumors member

    Joined:
    Aug 27, 2009
    Location:
    Weston-super-Mare, UK
    #5
    Angelwatt. You're right. I've only used with an if...then, ie. Are you logged in? Then carry on, else go to the log in page.

    I'll have a look tomorrow and see if I can come up with anything for you.
     
  6. pfealey macrumors member

    Joined:
    Aug 27, 2009
    Location:
    Weston-super-Mare, UK
    #6
    I knew you could do it somehow....

    Try 'output buffering' and see if that works for you. I'd imagine it's resource hungry, and is a bit of a clunky workaround, but works at least..

    PHP:
    ob_start();
    echo 
    "Anything you like";
    header("Location: http://www.foo.com/bar.php");        
    ob_flush();    
     
  7. fab5freddy thread starter macrumors 65816

    fab5freddy

    Joined:
    Jan 21, 2007
    Location:
    Heaven or Hell
  8. pfealey macrumors member

    Joined:
    Aug 27, 2009
    Location:
    Weston-super-Mare, UK
    #8
    I've tried it, yes, and it seems to do the job - the trouble is, it happens so quickly I can't tell if the echo is occuring.

    I'll guess yes, but once you put your analytics stuff in, you should be able to look at the Google logs to see?

    (Google analytics - not my bag really, I have someone else do that for me)
     

Share This Page