PHP Password And Redirect Script...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eragon
    Contributor
    • Mar 2007
    • 431

    #16
    So, do i make a change here?

    you didnt tell me that... lol

    so if i change your script to look like so:

    [PHP]<?php

    session_start() ;

    ?>
    <html>
    <head><title>Mo toma Rocks My Homework</title></head>
    <body>
    <?php


    if(!isset($_SES SION['userid']))
    {
    if(!isset($_POS T['username']) || !isset($_POST['password']))
    {
    echo '<form method="POST">< input type="text" name="username" /><input type="password" name="password" /><input type="submit" /></form>';
    }
    else if(authenticate ($_POST['username'], $_POST['password']))
    {
    $_SESSION['userid'] = $_POST['username'];
    header('Locatio n: thispage.php');
    }
    }
    else
    {
    if(!isset($_POS T['data1']) || !isset($_POST['data2'])) //fill with all question data objects
    {
    echo '<form method="POST">< select name="data1"><o ption value="q1a">Lor em</option><option value="q1b">Ips um</option>
    </select><select name="data2"><o ption value="q1a">Lor em</option><option value="q1b">Ips um</option></select></form>';
    }
    else
    {
    AppendDataToFil e($_SESSION['userid'], $_POST['data1'], $_POST['data2']);
    echo 'Thank you for your submission '.$_SESSION['userid'].'!';
    }
    }

    function authenticate($u , $p)
    {
    if($u == 'admin' && $p == 'password') return true; //replace with the actual authentication.
    return false;
    }
    ?>
    </body>
    </html>[/PHP]

    i just might get it working?
    Last edited by eragon; Jun 14 '07, 01:48 AM. Reason: added the change (so i dont double post)

    Comment

    • eragon
      Contributor
      • Mar 2007
      • 431

      #17
      could you split the script up into the different pages please? like i origionally intended... because the actual file requires this. please??

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #18
        Why don't you just split it up? All of the pieces are there, just take from the example I gave each section of the system. PHP.net is a great resource as well.

        Comment

        • eragon
          Contributor
          • Mar 2007
          • 431

          #19
          hmmm.... html is my second language. php is foreign (sp?). ill see what i can do and ill post it here.

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #20
            Originally posted by eragon
            hmmm.... html is my second language. php is foreign (sp?). ill see what i can do and ill post it here.
            Well, you know what they say about languages: the first seven are the hardest to learn.

            Comment

            • eragon
              Contributor
              • Mar 2007
              • 431

              #21
              Originally posted by Motoma
              Well, you know what they say about languages: the first seven are the hardest to learn.
              i only know 6: English, Spanish, Japenese, HTML, Javascript, and CSS.

              most of them i only know bits and pieces...

              ayways, back to the subject:

              i modified it a little so that it looks the way i want it to. theres still one problem. if i split it into pages, i cant pass the varaibles unless i put them into the value of a hidden form feild. so ill leave it on one page. i might just do includes with inc files. but now i have a script, a page, a style sheet, and i ran out of doughnuts. how do i get the style sheet linked properly with PHP? putting it into the head of this page is useless... it dosnt read untill... wait... at the beginning of the script i tell it to echo my head information. at the end i tell it to echo my foot information. well dont, thanks man! heres my finished script, and my stupid little error:

              Error upon voting:
              Code:
              Fatal error: Call to undefined function appenddatatofile() in /www/110mb.com/p/l/a/y/e/r/-/k/player-killer-clan/htdocs/votealt.php on line 53
              And my code:
              [PHP]<?php

              session_start() ;

              echo('<html><he ad><title>Motom a Rocks My Homework</title><link href="basic-1.css" rel="stylesheet " type="text/css"><link href="css/poll.css" rel="stylesheet " type="text/css"></head><body><div id="body">') ;

              if(!isset($_SES SION['userid']))
              {
              if(!isset($_POS T['username']) || !isset($_POST['password']))
              {
              echo '<div class="frame wide_e">
              <span style="float:ri ght;"><a href="index.php ">Main Page</a></span><div>You are not logged in.</div>
              </div> <div style="text-align:center;">
              <div class="polltitl ebground">
              <div class="polltitl eframe">
              <b>Poll Page</b><br>
              <a href="index.php ">Main Menu</a>
              </div>
              </div>
              </div><div class="frame wide_e">
              <center><b>Plea se log in to access this feature.</b><br />
              <form method="post">U sername:<input type="text" name="username" /><br />
              Password:<input type="password" name="password" /><br />
              <input type="submit" value="Login" /></form></center></div>';
              }
              else if(authenticate ($_POST['username'], $_POST['password']))
              {
              $_SESSION['userid'] = $_POST['username'];
              header('Locatio n: thispage.php');
              }
              }
              else
              {
              if(!isset($_POS T['data1']) || !isset($_POST['data2'])) //fill with all question data objects
              {
              echo '<div class="frame wide_e">
              <span style="float:ri ght;"><a href="voteli.ph p">Main Page (Logout)</a></span><div>You are logged in as <span style="color:#F FBB22">'.$_SESS ION['userid'].'.</span></div>
              </div> <div style="text-align:center;">
              <div class="polltitl ebground">
              <div class="polltitl eframe">
              <b>Poll Page</b><br>
              <a href="index.php ">Main Menu</a>
              </div>
              </div>
              </div><div class="frame wide_e">
              <center><b>Plac e write your responses below:</b><br />
              <form method="post">L orem?<input type="text" name="data1" /><br />
              Ipsum?<input type="text" name="data2" /><br />
              <input type="submit" value="Vote!" /></form></center></div>';
              }
              else
              {
              AppendDataToFil e($_SESSION['userid'], $_POST['data1'], $_POST['data2']);
              echo '<div class="frame wide_e">
              <span style="float:ri ght;"><a href="voteli.ph p">Main Page (Logout)</a></span><div>You are logged in as <span style="color:#F FBB22">'.$_SESS ION['userid'].'.</span></div>
              </div> <div style="text-align:center;">
              <div class="polltitl ebground">
              <div class="polltitl eframe">
              <b>Poll Page</b><br>
              <a href="index.php ">Main Menu</a>
              </div>
              </div>
              </div><div class="frame wide_e">
              <center>Thank you for your submission '.$_SESSION['userid'].'!<br />
              Your vote wil be tallied as soon as the week is over.</center></div>';
              }
              }

              function authenticate($u , $p)
              {
              if($u == 'admin' && $p == 'password') return true; //replace with the actual authentication.
              return false;
              }

              echo '<?php include(\'inc/foot.inc\'); ?></div></body></html>'

              ?>[/PHP]

              It only partially works. Does this have persistency? Meaning, how come it always stays logged in when i load the page? please debug. also, i stripped the HTML you put in because this script writes it in now. im quick to learn PHP. thanks for all your help Motoma!

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #22
                Hey, wait: this is your assignment not mine. I gave you the basis for getting the system rolling, but you are going to have to implement appenddatatofil e() yourself! I never wrote that function, I merely placed it there to show you the logic behind the page you are trying to create.

                If you want to keep data between pages, (such as values from the previous post) just chuck them in the $_SESSION variable (hint: take a look at the userid).

                Comment

                • eragon
                  Contributor
                  • Mar 2007
                  • 431

                  #23
                  i see, well, ill check out php.net to solve that error. or ill just use my origoinal write script.

                  Comment

                  • eragon
                    Contributor
                    • Mar 2007
                    • 431

                    #24
                    all right mate, i got it working. thanks for your help. now, i have another concern. i want to use .inc files for another thing, using the login script (which after some time i now understand). how would i make it so that the .inc files only load on a ceratin file, say, user.php? meaning if somebody links directly to a inc file, it wont load or iw will be blank,, but if they load it using an include in user.php it will show?

                    Comment

                    • Motoma
                      Recognized Expert Specialist
                      • Jan 2007
                      • 3236

                      #25
                      Originally posted by eragon
                      all right mate, i got it working. thanks for your help. now, i have another concern. i want to use .inc files for another thing, using the login script (which after some time i now understand). how would i make it so that the .inc files only load on a ceratin file, say, user.php? meaning if somebody links directly to a inc file, it wont load or iw will be blank,, but if they load it using an include in user.php it will show?
                      Well, if your .inc file contains only function definitions (as it should) then you don't have to do anything to have them display blank.

                      Comment

                      • eragon
                        Contributor
                        • Mar 2007
                        • 431

                        #26
                        Originally posted by Motoma
                        Well, if your .inc file contains only function definitions (as it should) then you don't have to do anything to have them display blank.

                        umm... ya, my .inc files contain portions of html pages (EX foot.ing just has the footer information...) i found that this is an easy way to update all the files on my site at once.

                        Comment

                        • Motoma
                          Recognized Expert Specialist
                          • Jan 2007
                          • 3236

                          #27
                          Put them outside of your webroot.

                          Comment

                          Working...