Advanced Search

Results 1 to 4 of 4

Thread: set cookie and redirect

  1. #1
    Join Date
    Oct 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default set cookie and redirect

    Hi all,

    First 2 things: im new to this so i dont know anything so please for give if i sound stuppid and sorry for my bad english..


    I have a forum www.force.com/index.php now evrybody comes on the index.php but now i have a file called acces.php with this code

    <script language="javascript">
    function setcookie()
    {
    document.cookie = "access=true";
    }
    </script>

    Click <a href="index.php" onclick="setcookie();">here</a> to enter the forum

    and i whant the visitors firs on access.php and set a cookie before they can see the index.php if the cookie is not set that they get redirect to acces.php to set the cookie

    Can some help me out please

    Kind regards
    nikki,

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by nikki
    and i whant the visitors firs on access.php and set a cookie before they can see the index.php if the cookie is not set that they get redirect to acces.php to set the cookie
    Presumably, you're trying to get users to agree to conditions before entering the forum.

    Based on your description, if a user rejects your cookie (even if they agree to the terms), they won't be able to access the forum.

    Don't use a separate file (though you can include a separate file to keep the file managable). Instead, check within index.php whether the user has access, and use either form submission or a value on the query string to determine that state.

    Mike

  3. #3
    Join Date
    Oct 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mwinter
    Presumably, you're trying to get users to agree to conditions before entering the forum.

    Based on your description, if a user rejects your cookie (even if they agree to the terms), they won't be able to access the forum.

    Don't use a separate file (though you can include a separate file to keep the file managable). Instead, check within index.php whether the user has access, and use either form submission or a value on the query string to determine that state.

    Mike
    Hi Mike,

    Yes thats is what a mean
    Can you help me maybe to get a script like that
    im just a newbie and i dont know notthing sorry

    Kind regards
    nikki,

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    A simple solution might look like:

    PHP Code:
    <?php
    ob_start
    ();
    header('Content-Type: text/html; charset=iso-8859-1');
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
     "http://www.w3.org/TR/html4/strict.dtd">

    <html lang="en" dir="ltr">
    <head>
    <?php
    if(!isset($_GET['forum'])) {
    ?>
      <link rel="stylesheet" type="text/css" href="terms.css">
      <title>MyForum — Terms &amp; Conditions Agreement</title>
    </head>

    <body>
      <form action="?forum" method="post">
      <fieldset><legend>Terms and Conditions</legend>
        <div id="terms">
          <!-- Mark-up terms and conditions normally (as
               paragraphs, headings, lists, etc.), here.
            -->
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
          eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
          minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
          ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
          voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
          sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
          mollit anim id est laborum.</p>
          <p>Nulla vel tortor sit amet pede imperdiet varius. Nullam fringilla
          consectetuer lorem. Curabitur iaculis lectus non diam. Cum sociis natoque
          penatibus et magnis dis parturient montes, nascetur ridiculus mus. Proin
          libero lacus, vestibulum tincidunt, tincidunt non, condimentum sed,
          libero. Ut tempor, lacus sit amet elementum aliquet, quam risus euismod
          wisi, ac varius purus lacus vitae nibh. Nulla fermentum velit et nulla.
          Cras non wisi ac libero posuere mattis. Nam condimentum consequat augue.
          Quisque faucibus pede vitae lectus. Duis blandit ipsum vitae nibh cursus
          lobortis.</p>
          <p>Phasellus in ante. Donec viverra luctus lectus. Integer laoreet
          pellentesque massa. Suspendisse vestibulum elementum tortor. Etiam eu
          sapien. Phasellus rutrum, tellus nec rhoncus faucibus, lorem augue
          tristique wisi, et mattis ipsum neque quis mi. Pellentesque tincidunt
          mollis nunc. Donec et elit eget ante pellentesque viverra. Sed libero
          erat, dictum at, commodo ac, tristique sed, turpis. Vivamus molestie
          tortor. Suspendisse potenti. Class aptent taciti sociosqu ad litora
          torquent per conubia nostra, per inceptos hymenaeos. Suspendisse pharetra
          mattis nibh. Curabitur dolor sem, vestibulum id, varius at, nonummy ac,
          nisl. Pellentesque eleifend magna quis ipsum. Nam malesuada, odio eu
          congue vehicula, quam dolor tempus wisi, in interdum neque risus eu
          augue. Nam eu wisi. Cras dapibus.</p>
        </div>
        <label><input name="accept" type="checkbox" value="true"> I agree to the
        above terms and conditions.</label>
        <p>If you do not agree to the terms and conditions, you will not be able to
        enter this forum.</p>
        <input id="submit" type="submit" value="Continue">
      </fieldset>
      </form>
    <?php
    } else if(isset($_POST['accept']) && ('true' == $_POST['accept'])) {
    ?>
      <link rel="stylesheet" type="text/css" href="forum.css">
      <title>MyForum — Home</title>
    </head>

    <body>
      <!-- Forum contents -->
    <?php
    } else {
    ?>
      <title>Back 'o Beyond</title>
    </head>

    <body>
      <!-- You need to decide what to do here. -->
    <?php
    }
    ?>
    </body>
    </html>
    <?php
    header
    ('Content-Length: ' . ((string) ob_get_length()));
    ob_end_flush();
    ?>
    If you look closely, you'll see PHP if..else statements dispersed amongst the HTML. Instead of including markup within those statements directly (as I have, above), you could use the include or require construct to insert the contents of another file. This means you don't have to maintain a huge, monolithic PHP file.

    You should also see, near the end, a comment that reads: "You need to decide what to do here." If the code reaches that branch, the user submitted the form but didn't agree to the conditions. There are two choices for you here. The first is that you present some HTML to the user, perhaps to explain what happened, and why. The second is to redirect the user somewhere - either another site or elsewhere in the current one.


    I should point out that the agreement you present with this particular code may not be considered binding. If a user knows of a URL beyond this check, they can go there directly and they might not be considered, legally, to have given their consent and understanding to your terms. If, for some reason, you might need legal backing, a more complex arrangement would be necessary. If not, then this should be sufficient.

    Mike

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
  •