1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Okay, I have 2 or 3 things I need help with

Discussion in 'PHP' started by Kyoneko Rose, Jun 4, 2005.

  1. #1
    Okay, I'm still pretty new to PHP...I can do about as much...simple php includes and skinning, which all in all isn't that hard and I have a tutorial to go off of for the skinning, haha...

    Anyway, I have a few differnet things I want to do with the website of mine I'm working on, and I'd like for someone here to help me with the coding if they could take the time to do so, I'd very much apperciate it^.^

    Anyway, onto the problems then!
    SEMrush
    --------------------------PROBLEM NUMBER 1------------------
    Okay, you know how some sites have games like "Guess that character" or "Guess the song title" or other things? Well, usually they'll have javascript passwording or what not where people put in a username they give and the password is the answer. Well, if you think about it, this isn't that safe cause people can just view source and see what the coder put in for the password in the source coding.

    So what I'm wondering if this is possible. Have it so there is just one input box where the user puts the answer to whatever question it it, and then if they are right they are redirected to a page with their award on it or what not and if they are wrong they are redirected to a page that says they were wrong and to try again. Sounds simple enough to do, but I don't know how. So can you help me out with that?

    -------------------------PROBLEM NUMBER 2-------------------
    http://puret.org

    Warning, this is the site I am getting all this help for, and it isn't really up and ready for "public showing" just yet and some pages aren't complete, but I decided I might as well show it so people can see what I'm getting at. You see how I Have my navigation? Is there a way to do that in php that isn't completely impossible for a newbie like me to understand and when they click on the link the menu stays dropped down and doesn't collapse again (I've had many complaints about this fact so far). If it's possible for me to get help with this, then you can skip reading the next Number cause it's the alternative solution I've though to this problem.

    -------------------------PROBLEM NUMBER 3------------------
    Alright, how about this. You see the right box with all the content and what not. Let's say I just put that content in a file (let's say...defualt.php for the main page's text and any other pages other then that just keep the file name but lose the include header and footer tags so it's just the content in the file) and just have a simple include code for that file inside of having it on the page as well. So it looks the same, but is actually in an include code instead of just there. (Am I making any sense?)

    Well, alright, when you click on a link in the left navigation area, it just changes the coding on the include code I just made above and switches whatever the include has to something else (like say, it switches "default.php" to "desc.php" instead).

    Is this possible? It should be, I've seen some things similiar to this, but they weren't exactly what I have in mind or they confused me to much.

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

    Anyway, there are my problems. Any help on any of them would be HIGHLY apperciated and someday in the future if I will try and repay your kindness in helping me in some way.

    Well, thank you in advance. Feel free to ask any questions of me about this problems that will help you figure them out better. Also, be patient with me, I may be a quick study, but even I get confused sometimes. I'm only human, lol.
     
    Kyoneko Rose, Jun 4, 2005 IP
    SEMrush
  2. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    64
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Asking one question at a time will always get you further :)

    You need server-side processing for this. That is, you will have some kind of input in your HTML and the result of this input will be received by the server, which will actually do the evaluation. Because this evaluation is done on the server side, users won't be able to see the right answer in the source. You can also do some client-side preprocessing to prevent others (e.g. eavesdroppers) from seeing the answer (e.g. a password).

    Here's a little example:

    HTML:
    <form action="login.php"><p><input type="text" name="password"></p></form>

    PHP:
    if(!strcmp($_GET["password"], $password))
    header("Location: http://" . $urlpath . "/right.php");
    else
    header("Location: http://". $urlpath . "/wrong.php");

    An example of client-side preprocessing would be calculating MD5 hash of a password before sending it to the server.

    J.D.
     
    J.D., Jun 4, 2005 IP
  3. Kyoneko Rose

    Kyoneko Rose Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hmmm, yea it probably would. But I thoguht it'd be easier to put them all in one page instead of making 3 seperate posts, but if you think I should, I will make another post (since both 2 and 3 are solutions to the same problem, and either would work for me, lol)

    hmmm, that seems easy enough to understand, I think, lol. Is that all the coding involved, or is there more I'll need to have?

    Sorry, sometimes big words can confuse me if they aren't explained properly when I'm being taught new coding things, lol.
     
    Kyoneko Rose, Jun 4, 2005 IP
  4. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    64
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You will need a bit more code on the actual page (both, PHP and HTML). There are certain rules you will need to follow. For example, the Location header must be a fully-qualified URL (i.e. begin with http//:, followed by a domain name and the path to the file) - you will need to form it in your code (you'll find an example here: http://ca.php.net/manual/en/function.header.php).

    You will also need to obtain $password from somewhere - it can come from a database or from a local file (you can also hard-code it right there on the page, but this is only good for simple pages).

    Here's a couple of more useful resources:

    http://www.php-csl.com/snippets/
    http://www.php-scripts.com/php_diary/php_scripts.html

    J.D.
     
    J.D., Jun 5, 2005 IP
  5. Kyoneko Rose

    Kyoneko Rose Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hmmm, I think this may take me a while >.< I'm already confused, lol. Well, thanks, I guess. I'll try and figure it out.

    *wonders if she could find someone to just do it for her, cause she's lazy like that* I'm more a graphic designer then hard coder, truthfully. I'm going to go to college for graphic design, and maybe minor in web design, but I'm not sure about that yet..

    *tries and goes to figure out what she's gonna need to do*
     
    Kyoneko Rose, Jun 5, 2005 IP
  6. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    64
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I have a soft spot for those who likes anime :) Here's something to get you started:

    <?php
    
    session_start();     // associate this request with the session
    
    $password = "1234";  // hard-coded password
    $urlpath = $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
    
    //
    // If there is a guess and the guess is right, redirect the 
    // client to right.php. Otherwise, increment the failed guess
    // count.
    //
    if(strlen(($guess = $_GET["password"]))) {
    	if(!strcmp($guess, $password)) {
       		header("Location: http://". $urlpath . "right.php");
    		exit();
    	}
    
    	$count = ++$_SESSION["count"];
    }
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    
    <html>
    <head>
    <title>Password Sample</title>
    <style type="text/css">
    body {margin: 0; padding: 20px; font: 10pt Verdana, sans-serif;}
    h1 {font-size: 12pt;}
    input {margin: 2px auto; vertical-align: middle;}
    p.warning {color: red; font-weight: bold;}
    </style>
    </head>
    
    <body>
    
    <h1>Guess the password!</h1>
    
    <form method="GET" action="">
    <p>
        <input type="text" name="password" style="width: 200px; background-color: #FFFFEE;" value="<?= htmlspecialchars($guess) ?>">
        <input type="submit" value="Submit">
    </p>
    
    <?php if($count > 0) { ?>
    <p class="warning">Failed <?= $count ?> times</p>
    <?php } ?>
    
    </body>
    </html>
    PHP:
    J.D.
     
    J.D., Jun 5, 2005 IP
    Homer likes this.
  7. Kyoneko Rose

    Kyoneko Rose Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Oh wow, who would have known my love of the japanese animated film would have actually led to something, haha.

    Anyway, thank you so much, I tested this out and for what I want, it's perfect. So really, I apperciate it^.^

    I shall take that problem off the list now and change the title, maybe someone can help me with the other thing now >.>

    Or wait, I would, but it seems I can't edit my first post :confused:

    Oh well, lol.

    Thanks again, J.D. You really are a great person *bows a couple times, lol* I didn't think I'd ever figure it out myself :confused:

    EDIT: One more question, is there a way to clear the count of who failed? If not, that's fine, I have an idea that'll work, but if there is, I'd like to know, lol.
     
    Kyoneko Rose, Jun 6, 2005 IP
  8. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    64
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Think of a condition (e.g. the count reaches a certain number) and once this condition is true, assign the count a zero. For example, replace the line that assigns $count with this and the browser will be redirected to wrong.php after three failed attempts and $count will be reset to zero:

    if(($count = ++$_SESSION["count"]) == 3) {
       $_SESSION["count"] = 0;
       header("Location: http://". $urlpath . "failed.php");
       exit();
    }
    PHP:
    J.D.
     
    J.D., Jun 6, 2005 IP
  9. Kyoneko Rose

    Kyoneko Rose Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    ahh, that's helpful. Thank you very much^.^
     
    Kyoneko Rose, Jun 6, 2005 IP