SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php=$_SERVER['REQUEST_URI'] In forms

    I got this code off another forum(yes it was posted) and I am not really sure what the $_SERVER['REQUEST_URI'] means. It's part of a membership system

    Here is code(its called register.php):

    <?php
    include ("config.php");
    # include the config file

    if ($_POST['Submit']){
    # check to see if the form was submitted
    # if so...

    $username = clean($_POST['username']);
    # post the form fields and clean the strings

    $password = clean($_POST['password']);

    $password_con = clean($_POST['password_con']);

    $email = clean($_POST['email']);

    $ip = clean($_SERVER['REMOTE_ADDR']);
    # get the IP of the browsing computer

    $signup = time();
    # get the timestamp of the signup

    if (!$username | !$password | !$password_con | !$email){
    # if any of the strings form the form are empty
    echo 'You must fill in every field. <a href="'.$_SERVER['REQUEST_URI'].'">Back</a>.';
    }
    else {

    if ($password != $password_con){
    # if the passwords do not match
    echo 'Password fields did not match. <a href="'.$_SERVER['REQUEST_URI'].'">Back</a>.';
    }
    else {

    $username_test = "SELECT * FROM `users` WHERE username = '$username'";
    $username_test = mysql_query($username_test);
    # check if the username is already in use

    if (mysql_num_rows($username_test) == 1){
    # if the username is being used
    echo 'Username is already being used. <a href="'.$_SERVER['REQUEST_URI'].'">Back</a>.';
    }
    else {

    $md5pass = md5($password);
    # change the password to an md5 hash

    $add = "INSERT INTO `users` VALUES ('', '$username', '$md5pass', '$email', '$ip', '$signup')";
    # setup a query to insert the data into the table.

    if ( mysql_query($add) ){
    # run the query

    echo 'Success. You are now registered.<br />';
    echo 'Login using the following informationbr />';
    echo 'Username: '.$username.'<br />';
    echo 'Password: '.$password;
    }
    else {
    echo 'Error, user not added.';
    }

    }

    }

    }

    }
    else {
    # else the form was not submitted
    ?>
    <form method="post" action="<?php=$_SERVER['REQUEST_URI']?>">
    Usernamebr />
    <input type="text" name="username">
    <br />
    Passwordbr />
    <input type="password" name="password">
    <br />
    Confirm Passwordbr />
    <input type="password" name="password_con">
    <br />
    E-mailbr />
    <input type="text" name="email">
    <br />
    <input type="submit" name="Submit" value="Register">
    </form>
    <?php
    }
    ?>

    when I try and sign-up with the apache server it gives me a 403 Forbidden Error.
    I'm kinda new at php anyway.

    If you can tell me what the $_SERVER['REQUEST_URI'] means in somewhat detail, I would appreciate that too.

    smileys are colon then <

    Thanks in advance,
    W3C

  2. #2
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    right click>view source to see the value.

    its the uri of the current http request.

    for example, the request uri of this thread is:
    /forums/showthread.php?t=439854

  4. #4
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So would it take you to the current page that your at after you hit submit or what?

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    depends how you use it.

    you are able to view the output of your script.
    you should do that, and see.

  6. #6
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But the only thing I get when I hit submit is the 403 forbidden error.
    I'm using apache. Will it only work when the pages are hosted?

    The error says:

    You don't have permission to access /"file name"/< on this server.

    Any suggestions?

    So would this code be for when like you justed registered and the screen comes up that says something like "click here to return to where you previously were"?
    Just Curious. Thanks
    Last edited by W3C; Nov 23, 2006 at 18:06.


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
  •