Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: I have a new code... now what?

  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 I have a new code... now what?

    I was in another forum and was given the following code:

    Code:
    <?php
    if($_POST['user']) {
    if(($_POST['user'] == "john") && ($_POST['pass'] == "travolta")) header("Location: johntravolta.php");
    else if(($_POST['user'] == "john") && ($_POST['pass'] == "cusak")) header("Location: johncusak.php");
    } else {
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title>Log in</title>
    </head>
    <body>
    <form action="<?=$PHP_SELF?>" method="post">
    <p>Username: </p><input type="text" name="user"/>
    <p>Password: </p><input type="password" name="pass"/>
    </form>
    </body>
    </html>
    <?php } ?>
    Thank you to Twey for the code and advice...

    Now by reading this you can see what I want to accomplish, to seperate destinations from one password box, with two different passwords and one common username (john/travolta & john/cusak in the above example).

    Now due to the nature of my site, this is why I am afraid this code wont work. My site is a riddle site where players have to use all availiable resources to find the hidden hints, and manipulate sounds, text and pitctures etc to find the correct word(s) to get to the next level. One of the most common places to hide these clues is the source code.

    Obviously I can't have the answers in the source code.

    Can anyone tell me where I might find a way to do this code with HTML, using the .htaccess and .password files, OR even some way to disable completely the access to the source code (must be applicable for ALL browsers, and include right clicking, as well as view--souce).

    Thank you again to Twey for the original code, and for the help.
    (I am playing around with this code to try and make it work)
    BLiZZ
    {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
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    PHP source code is invisible. Only the HTML the PHP outputs is actually sent to the browser; the PHP itself (with the username and password) is totally invisible to the browser and user.
    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!

  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

    YAY!


    Learning new things about computer languages is daunting, but I am doing it!

    Anyone know where I can go online for a good php recource guide or e-book, or tutorials or lessons, anything? I can't afford schools, and I am better at learning by doing.

    Thanks again Twey,


    BLiZZ
    {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

    The php.net tutorial is a little confusing for beginners. Try the W3Schools one.

    There is, by the way, no way to totally hide the source from users. If the browser can see it, the user can see it. The only way to hide code is to execute it server-side (which is what PHP does) so it is never sent to the browser.
    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

    Much THANKS again. I will start studying immediatley.


    You're a genius Twey.



    BLiZZ
    {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

    Why thankyou.
    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

    Okay, color me stupid..... I prefer orange!


    anyway, I have the code, I have it set up with my paramaters, header tags lead to my real pages, etc..

    I saved it (as a test of course ) as a .php file and uploaded it to my server. Great! I pointed the URL to the page and sure enough, there was a user name box and a password box.

    So I tested it out, I entered john in the user field and travolta in the pass field. Then I found my problem. There is no submit button. I have started the w3schools tutorial, and am on page 3

    but I fear this request is too advanced for where I am in the tutorials. so I am asking the almighty minds here for some advice and guidance while I continue my learning...

    What exactly I want to accomplish is this:

    On my web page lets say, www.mypage.com/level1/page1.htm, is a picture. now I have image mapped this picture and the hot spot is what I want to lead to the password box mentioned in the coding above. Now, once again, if the user enters john/travolta I want them to go to www.mysite.com/level2/page2.htm likewise, if they enter john/cusak I want them to go to: www.mysite/level3/page3.htm

    So, knowing what I know about .htaccess, what I want isn't easily obtained, so I turned to the php gods... Using the code above, is what I want possible, and if so, where do I place the code? For example, I have to make the hotspot on the image go SOMEWHERE, but the password box will redirect them to the separate pages, right? So do I need to input the code into a .htaccess page, and the code will handle itself? or do I need to forget the hotspot and make a link, etc.

    Also, what do I need to do to make a submit button for the password code above? and, ( I am picky huh? ) if at all possible, can this code come into view as a pop up password box, instead of a page on the website?

    I hope I have clarified enough, if not ask what you need and I will do my best.

    For now... on to page 4 of my lesson!
    {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
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Whoops, I did it again
    <input type="submit" value="Go"/>
    will add a submit button. Put it wherever you like (inside the form).
    Code:
    <form action="<?=$PHP_SELF?>" method="post">
    <p>Username: <input type="text" name="user"/><br/>
    Password: <input type="password" name="pass"/><br/>
    <input type="submit" value="Log in"/></p>
    </form>
    Probably isn't valid, I can't remember the rules for form and paragraph nesting.
    So, knowing what I know about .htaccess, what I want isn't easily obtained, so I turned to the php gods... Using the code above, is what I want possible, and if so, where do I place the code? For example, I have to make the hotspot on the image go SOMEWHERE, but the password box will redirect them to the separate pages, right? So do I need to input the code into a .htaccess page, and the code will handle itself? or do I need to forget the hotspot and make a link, etc.
    No, what you need to forget about is .htaccess. There's no need to manhandle the webserver in the scenario you describe, and, if you're using PHP, there usually never is. What you want, however, can be done in plain old HTML. It works like so:
    Code:
    <map name="tre" id="tring">
    <area href="pass.php" shape="rect" coords="40,159,82,176" alt="" style="cursor:default;"/>
    <!-- You should never usually use a blank alt, but in this case an alt
    would give away the location of the area. cursor:default stops the
    cursor changing to a hand when it moves over the area. coords= is
    the location of the rectangle, top-left-x, top-left-y, bottom-right-x, bottom-right-y. -->
    </map>
    <img src="imgmap.jpg" alt="Image Map" usemap="#tre" style="border:0;"/>
    You can also do server-side image maps, but they're evil little beggars.
    Last edited by Twey; 08-07-2005 at 02:58 PM.
    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!

  9. #9
    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

    Twey, you are the man!

    Everything works perfectly. I did have to adjust the <p> </p> and made them <br>'s instead, but other than that its a gem!


    THANK YOU SO MUCH!

    Now, back to my studies... php tutorial page 5!

    WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
    {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

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

    Default

    Quote Originally Posted by Twey
    Code:
    <form action="<?=$PHP_SELF?>" method="post">
    <p>Username: <input type="text" name="user"/><br/>
    Password: <input type="password" name="pass"/><br/>
    <input type="submit" value="Log in"/></p>
    </form>
    Probably isn't valid, I can't remember the rules for form and paragraph nesting.
    It's valid XHTML, parsable HTML from the point of view of modern browsers, but not what you may expect from the perspective of HTML itself.

    I'd write that as:

    HTML Code:
    <form ...>
    <div>
      <label>Username: <input type="text" name="user"></label>
      <label>Password: <input type="password" name="user"></label>
      <input type="submit" value="Log in">
    </div>
    </form>
    In more complicated forms, I might use a fieldset element instead of a div. In either case, the style sheet would then make those label elements block level, perhaps add margins for a little spacing, and align the child input elements, if desired.

    Code:
    label {
      display: block;
      margin-bottom: 1ex;
      position: relative;
    }
    label input {
      left: 7em;
      position: absolute;
    }
    I haven't checked how that would look; it might need (a lot of ) tweaking.

    You should never usually use a blank alt,
    An empty alt attribute is fine for decorative images.

    but in this case an alt would give away the location of the area.
    If you're worried about tooltips (which shouldn't result from the use of alt, but does in some browsers), then add an empty title attribute.

    You can also do server-side image maps, but they're evil little beggars.
    They're also less accessible as only users that can see the image can know where they're clicking, and where they might be taken.

    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
  •