Results 1 to 8 of 8

Thread: Force redirect

  1. #1
    Join Date
    Jun 2006
    Posts
    42
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Force redirect

    Hello all

    On my website there is many pages,for images(http://mywebsite/image/index.html), forum
    (http://mywebsite/forum/index.php).I would like to force visitors to come from
    my homepage (http://mywebsite/index.html) even if they bookmarked the link of my image and forum index (because the complete link appear in message and status bar).
    How could i do it

    Any advice would be helpfull

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    For security, you'd want to use php. I don't even know if you can use javascript for this.

    Anyway, it's something like this:

    <?php
    if ($_SERVER[HTTP_REFERER] != "http://yourwebpage.com/page.htm") {
    die('<meta http-equiv="redirect" content="0;url="http://your.com/page.htm">');
    }

    Notes:
    -I don't thnk that the server variables need '' around them.... might be 'HTTP_REFERER', but I don't think so. Check that if you get an error.
    -Using a header redirect would be a bit better, but I'm not sure on the code for those. Look them up if you want.


    This work?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jun 2006
    Posts
    42
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    Thanks for the answer

    I didn't understand the difference beetwen http://yourwebpage.com/page.htm and http://your.com/page.htm so i can't try this solution.
    I understand that:
    http://yourwebpage.com/page.htm = http://mywebsite/index.html and
    http://your.com/page.htm = http://mywebsite/image/index.html or http://mywebsite/forum/index.php
    Is it correct ?
    And do i have to put this code anywhere in index.php of forum page ?

    Thank you for your answer.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    (sigh)
    Code:
    <?php
    if ($_SERVER['HTTP_REFERER'] !== "http://yourwebpage.com/page.htm")
      header("Location: http://your.com/page.htm");
    ?>
    djr33, your code standard's really slipping.
    I didn't understand the difference beetwen http://yourwebpage.com/page.htm and http://your.com/page.htm so i can't try this solution.
    yourwebpage.com/page.htm is the homepage. your.com/page.htm is the page you wish to redirect from.

    This is unwise, since some firewalls strip the Referer header.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jun 2006
    Posts
    42
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    Thanks for your answer Twey

    Doesn't work

    My homepage is http:/onlinehome.fr/index.html
    There is a link inside pointing to http:/onlinehome.fr/calendrier/calendar.php
    I don't want user accessing this page directly they have to go to homepage first.So according to your solution i have modified calendar.php inside <head> tag like this:
    <?php
    if ($_SERVER['HTTP_REFERER'] !== "http://onlinehome.fr/index.html")
    header("Location: http:/onlinehome.fr/calendrier/calendar.php");
    ?>

    What's wrong ?

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    This is unwise, since some firewalls strip the Referer header.
    Ah, that would be a problem, then.

    I suppose you could try something more complex to track where their last page was... cookies, database, etc.

    Maybe try a cookie on the homepage, and if that cookie doesn't exist, then redirect there. If they've already been to the homepage and later go right to the secondary page, that's ok, right?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    There should be two slashes after the protocol.
    djr33: What about browsers without cookies enabled?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    True.

    In the end, the question is whether this is such an important thing that you would rather lose some visitors than have them see it in order to make people need to come from a certain page.

    You could do both ways, and just hope that most people have one or the other. Still wouldn't be everyone, though.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •