title: Execute $_SERVER['PHP_SELF'] without removing my $_GET variables
body: <p>I'm having trouble with <code>&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;</code>. For some reason this line in my HTML form removes my $_GET variables (that I manually put into place) from the URL.   </p>
  
  <p>To understand my problem here is my register.php code:</p>
  
  <pre><code>&lt;?php
  session_start();
  // IF USER NOT REMEMBERED(DID NOT CLICK REMEBER ME BUTTON) OR NO SESSION IS FOUND THEN THROW HIM OUT TO LOGIN
  //SECURITY SO THAT USERS CANT ACCESS WEB URL DIRECTLY
  $host="localhost"; // Host name
  $username="user"; // Mysql username
  $password="password"; // Mysql password
  $db_name="database"; // Database name
  $tbl_name="temp_table"; // Table name
  
  // Connect to server and select databse.
  $link_temp = mysql_connect("$host", "$username", "$password") or die("cannot connect");
  mysql_select_db($db_name, $link_temp);
  $results=mysql_query("SELECT temporary_password, temporary_username FROM $tbl_name WHERE temporary_username = '".$_GET['temp_username']."'");
  $row = mysql_fetch_array($results);
  if($_GET['temp_password'] != $row['temporary_password'] || $_GET['temp_username'] != $row['temporary_username']){
  mysql_close();
  header("Location: index.php?invalid_user=1");
  }
  elseif (empty($_GET['temp_password']) || empty($_GET['temp_username']) || empty($_GET)) {
  mysql_close();
  header("Location: index.php?invalid_user=1");
  }
  
  if(isset($_POST['submit']))
  {
  //retrieve our data from POST
  $firstname = $_POST['firstname'];
  $lastname = $_POST['lastname'];
  $username = $_POST['username'];
  $pass1 = $_POST['pass1'];
  $pass2 = $_POST['pass2'];
  if($pass1 != $pass2){
  echo '&lt;div class="alert"&gt;Passwords do not match!&lt;/div&gt;';
  die();
  }
  
  $encrypted_mypassword = md5($pass1);
  $dbhost = "localhost";
  $dbname = "dbname";
  $dbuser = "user";
  $dbpass = "password"; //not really
  $link_users = mysql_connect($dbhost, $dbuser, $dbpass);
  mysql_select_db($dbname, $link_users);
  //sanitize values before entering into database
  $firstname = mysql_real_escape_string($firstname);
  $lastname = mysql_real_escape_string($lastname);
  $username = mysql_real_escape_string($username);
  $password = mysql_real_escape_string($password);
  $firstname = ucfirst(strtolower($firstname));
  $lastname = ucfirst(strtolower($lastname));
  $query = "INSERT INTO users ( firstname, lastname, username, password)
          VALUES ('$firstname' , '$lastname' , '$username' , '$encrypted_mypassword');";
  mysql_query($query);
  mysql_close();
  echo '&lt;div class="info"&gt;User Successfully Created!&lt;/div&gt;';
  }
  ?&gt;
  &lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Secure Customer Login&lt;/title&gt;
    &lt;meta charset="UTF-8" /&gt;
    &lt;meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" /&gt;
    &lt;meta name="apple-mobile-web-app-capable" content="yes" /&gt;
    &lt;meta name="apple-mobile-web-app-status-bar-style" content="black" /&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/reset.css"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/structure_register.css"&gt;
    &lt;link href='https://fonts.googleapis.com/css?family=Nothing+You+Could+Do' rel='stylesheet' type='text/css'&gt;
    &lt;script&gt;document.createElement('footer');&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class="img"&gt;
  &lt;img src="images/logo.png" /&gt;
  &lt;/div&gt;
  &lt;form class="box login" style="max-width:334px;" name="register" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
    &lt;fieldset class="boxBody"&gt;
      &lt;label&gt;First Name&lt;/label&gt;
      &lt;input type="text" name="firstname" maxlength="50" tabindex="1" placeholder="First Name" required /&gt;
      &lt;label&gt;Last Name&lt;/label&gt;
      &lt;input type="text" name="lastname" maxlength="50" tabindex="2" placeholder="Last Name" required /&gt;
      &lt;label&gt;Username&lt;/label&gt;
      &lt;input type="email" name="username" maxlength="50" tabindex="3" placeholder="Email" required/&gt;
      &lt;label&gt;Password&lt;/label&gt;
      &lt;input type="password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Password must contain at least 6 characters, including UPPER and lowercase and numbers' : ''); if(this.checkValidity()) form.pass2.pattern = this.value;" placeholder="Password" name="pass1" tabindex="4" /&gt;
      &lt;label&gt;Repeat Password&lt;/label&gt;
      &lt;input type="password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Please enter the same Password as above' : '');" placeholder="Repeat Password" name="pass2" tabindex="5" /&gt;
  &lt;/fieldset&gt;
    &lt;footer&gt;
      &lt;center&gt;&lt;input type="submit" name="submit" value="Register" class="btnLogin" /&gt;&lt;/center&gt;
    &lt;/footer&gt;
  &lt;/form&gt;
  &lt;footer id="main"&gt;
    &amp;copy; 2014 Rye High Group.  All rights reserved.&lt;/a&gt;
  &lt;/footer&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Basically the register.php page on my website gets an input from a link that contains two get variables: temp_username and temp_password. So the link that is used to access the site looks like this: my_domin.ca/register.php?temp_username=SomeUser1&amp;temp_password=Somepassword1 </p>
  
  <p>The get variables are compared to entries in the database and if they return true the user is granted access to register.php, otherwise he will be forwarded to index.php. Accessing register.php is no problem, but as soon as the form is submitted the $_GET variables are removed from the URL thus forwarding the user to index.php</p>
  
  <p>My question is: How can I modify <code>&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;</code> to stop removing GET variables</p>
  
  <p>P.S. I will transition to mysqli as soon as I get basic functionality working on my site (since I know mysql_* the best and want to reduce errors in the transition period)</p>