Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Page re-direct

Options
  • 16-01-2004 10:55am
    #1
    Closed Accounts Posts: 23


    I wanted to set up multiple banners on the same site all linking to my site, to get an idea of what banners are being clicked more often I was going to link each to a different page that I will specially create - this page will then automatically redirect to my home page and my plan is then just to monitor how often the specific URLs are requested.

    Do you know of any quick methods of getting the page to redirect to the home page before they know what is going on?

    Thanks


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Easy enough.

    I have something similar on my site which counts the amount of times a link is clicked.

    There are two ways you can do it. The first doesn't involve a redirect. You put a little bit if code at the start of your home page which checks to see if a GET variable is set, say 'id' and increment a counter based on the value of variable. So then for each banner ad you just have a different value for id in the link, e.g www.mypage.com/index.php?id=4

    Redirects are just as simple, and probably better for getting a more accurate idea of clickthrough rates. For the previous one, people can hover over your ad, see your site's url and go "Oh, I've been there", etc. If they don't know where it brings them, they might click just to check.
    So if you just write a small script (e.g. in PHP) which counts that the link has been clicked, and then redirects to your home page without outputting any data. So in PHP, there is function "header(location: www.mypage.com/)" which redirects the browser to the correct page. You can check any data and increment any counters before the browser is redirected, so for example, your ad links to "www.myadserver.com/link.php?id=4", the link.php script counts that ad 4 was clicked, then redirects the browser to your home page. Most other languages used for web apps have equivalent header output functions that let you redirect without outputting any actual data.

    You could use meta redirects for the above, but they involve having to load an entire page and wait for a refresh, and they may also not work in some browsers. Using header redirects means that the client needs not download any extra pages, and has a much smaller delay than a meta redirect.


  • Closed Accounts Posts: 23 bailey


    Thanks for the help Seamus, but i seem to be doing something wrong.

    I have a link pointing to a black php page with this in the header (<?php
    header("Location: http://www.example.com/"); ?>) but each time I click on the link, instead of redirecting the page it prompts me to open the php document?


  • Registered Users Posts: 885 ✭✭✭clearz


    Are you setting the content type of the document to text/html


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Originally posted by bailey
    Thanks for the help Seamus, but i seem to be doing something wrong.

    I have a link pointing to a black php page
    I assume you mean blank page? There should be no output to the browser except for the header() function, i.e. no "<HTML><HEAD>......" etc.
    with this in the header (<?php
    header("Location: http://www.example.com/"); ?>) but each time I click on the link, instead of redirecting the page it prompts me to open the php document?

    Sounds like the webserver you'e running isn't set up to preprocess php pages. What server are you running?


  • Closed Accounts Posts: 23 bailey


    At the moment I have Apache PHP triad running on my PC and I am just trying to test it


  • Advertisement
  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    As clearz said, try setting the content type to text/html.

    Also if you download the page does it give you html or the php source (could just be a browser issue)?


  • Closed Accounts Posts: 23 bailey


    it gives me the PHP source, where do I specify the content type to text/html


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Originally posted by bailey
    it gives me the PHP source, where do I specify the content type to text/html
    You can force it using the same header() function, eg
    header("Content-Type: text/html; charset=iso-8859-1");

    But you probably don't need to - the content-type header is a directive to tell the browser to display it as text, as opposed to displaying it as a picture, or downloading it as a zip file. The directive has nothing to do with processing the PHP file on the server side.

    I'm not sure tbh.

    Newbie Question: You have the php file on the webserver, and not in a local directory? I.e. Your accessing http://localhost/link.php as opposed to c:\www\link.php? (You can never be sure what's been overlooked) :)


  • Closed Accounts Posts: 23 bailey


    got it working now, put it down to friday stupidity - thanks for all the help


Advertisement