Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Anti-URL code not exactly perfect yet...

  1. #1
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default Anti-URL code not exactly perfect yet...

    I have been working on a code to eliminate the use of the URL to gain access to certain pages.

    Basically there is a series of pages on site that have 4 password boxes per. Based on the answer you type in the pass box you will be taken to another page. The importance of this is the sequence, we don't want people seeing step 12 if they haven't been to step 5.

    So I want to try to eliminate Joe posting the URLs to the 12 steps on his site and then Mary deciding she doesn't want to bother with step 5 skip to step 11.

    If that makes sense.

    Anyway I have this code so far:

    PHP Code:
    <?php
    if(isset($_POST['id'])) {
      
    $p = array(
        array(
    'RED''/red/index.php'),
        array(
    'BLUE''/blue/index.php'),
        array(
    'YELLOW''/yellow/index.php'),
        array(
    'GREEN''/green/index.php')
      );
      if(!isset(
    $p[$_POST['id']])) header("Location: " 'http://' $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0strrpos($_SERVER['REQUEST_URI'], '/')) . "/index.php");
      if(
    $_POST['pass'] === $p[$_POST['id']][0])
        
    header('Location: http://' $_SERVER['HTTP_HOST'] . $p[$_POST['id']][1] . '?pass=' $_POST['pass']);
      else
        
    header("Location: " 'http://' $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0strrpos($_SERVER['REQUEST_URI'], '/')) . '/cheater.php');
    } else {
    ?>
    And for each of the 4 pass boxes:

    PHP Code:
    <table>
    <tr>
    <td>
    <font size= "4">Red Answer is RED</font>
    <form action="<?=$PHP_SELF?>" method="post">
    <input type="hidden" name="id" value="0"/>
    <input type="password" name="pass"/>
    <input type= "submit" value= "Red Answer!"/></form>
    </td>
    </tr>
    </table></center>
    So, obviously if you enter RED in the passbox, you will go to mysite.com/red/index.php and if you just type "mysite.com/red/index.php" into your URL you will go to the cheater.php page.

    HOWEVER... if you type "mysite.com/red/index.php?pass=RED" into the URL you will go to the red/index.php page...

    Is there something I can do to eliminate the ?pass=RED part of the posting in the URL? I don't care if it is needed, just don't want it to show up in the actual URL for Joe, to copy and put on his site.

    I am still foggy on the Post/Get thingy, would that help?


    <EDIT>
    I forgot to mention, I have the "check" on the /red/index.php, again with the next 4 passboxes ready to go, as follows:

    PHP Code:
    <?php
    if(!isset($_GET['pass']) || $_GET['pass'] !== "RED")
      
    header('Location: http://' $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0strrpos($_SERVER['REQUEST_URI'], '/')) . '/cheater.php');
    if(isset(
    $_POST['id'])) {
      
    $p = array(
        array(
    'RED''/red/index.php'),
        array(
    'BLUE''/blue/index.php'),
        array(
    'YELLOW''/yellow/index.php'),
        array(
    'GREEN''/green/index.php')
      );
      if(!isset(
    $p[$_POST['id']])) header("Location: " 'http://' $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0strrpos($_SERVER['REQUEST_URI'], '/')) . "/index.php");
      if(
    $_POST['pass'] === $p[$_POST['id']][0])
        
    header('Location: http://' $_SERVER['HTTP_HOST'] . $p[$_POST['id']][1] . '?pass=' $_POST['pass']);
      else
        
    header("Location: " 'http://' $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0strrpos($_SERVER['REQUEST_URI'], '/')) . '/cheater.php');
    } else {
    ?>
    Last edited by BLiZZaRD; 09-22-2006 at 10:10 AM.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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

    Default

    $_GET[pass'] should be $_POST['pass']

  3. #3
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    No, that doesn't work either... If I do that it gets redirected to the cheater.php sure, but it ALSO goes there if you put the answer in the passbox.. YIKES!!
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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

    Default

    Then in the form, you must be using GET. Set method="post" on all the forms involved.
    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
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Nope, all are method="post"

    The only place GET shows up in any of them is here:

    PHP Code:
    if(!isset($_GET['pass']) || $_GET['pass'] !== "RED"
    and this on ON index.php (the page you go to with a correct answer).
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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

    Default

    Then you must have an equivalent form posting to that page using GET, or that code wouldn't work. Convert it to POST.
    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!

  7. #7
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Yes, I will eventually have 4 pages linking to each other page in the same way. I will convert ALL to POST and see what happens. Thanks!
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  8. #8
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    AHA! Okay I figured it out but I don't know how to fix it.

    WhenI originally got this script working it was on the first page at http://mysite.com/page.php

    Then (using the RED answer as example) when RED was put in the correct box, you went to http://mysite.com/red/index.php

    However, when I started making the actual pages this wasn't the case. The whole thing will be in it's own folder, so /red/ will be a sub-folder.

    Meaning the first page will be at http://mysite.com/folder/page.php and when RED is entered you will be taken to http://mysite.com/folder/red/index.php

    So the error is in the header directs somewhere in all that very confusing . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'] stuff!

    What do I need to add to the codes to allow for the folder and sub folder stuff?

    ---------------------------------------------------------------------------

    I have tried it with

    Code:
    $_SERVER['SCRIPT_FILENAME']
    as that is the closest thing I could understand from this page

    But it didn't work. What am I doing wrong???
    Last edited by BLiZZaRD; 09-27-2006 at 10:21 PM.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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

    Default

    Can you put these pages up to test?
    Too tired to figure it out right now.
    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

  10. #10
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Sorry, lost all my new post icons.

    What do you mean put them up to test? I have an example page on one of my dead sites.. you can find the page HERE but I don't see how that will help with the problem, its all php coding, so you wont get much from there.

    As you can see you can use the main page (with the multi colored image) to go to any of the four. You can also go to any of the four if you put "/red/index.php?pass=RED" (sub red and RED for any of the four colors) this is what I want to avoid...

    I am thinking of other ways to do this as well though...
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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
  •