php help needed

  • ikhwanhafidz
  • Born
  • Born
  • ikhwanhafidz
  • Posts: 2

Post 3+ Months Ago

hi. im trying to set up a simple basic page, and having some hard times with php. the case is like this
im setting up the page where the username and password will be required.
if the username is abc, the password is 123. it'll redirect to 'url1'
else, it will redirect to 'url2'
and this page is meant to have only 1 username and 1 password to accept.
thanks in advance
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6245
  • Loc: Seattle, WA

Post 3+ Months Ago

Post what you've done so far so we can help.
  • ikhwanhafidz
  • Born
  • Born
  • ikhwanhafidz
  • Posts: 2

Post 3+ Months Ago

im not sure. but here's what i've done. please help. im so new with php :(


PHP Code: [ Select ]
<?php
//
if($_POST['submit']){
   $username = $_POST['user'];
   $password = $_POST['password'];
   
   
   //If username is 'abc' and password is '123', then login is successfull
   //You may connect this to database
   <span class="posthilit">if($username == 'abc' && $password == '123';
     
   }<span class="posthilit">else{
   Header
     
   }
   
   ?> <a href="">Go Back</a><?php
}else{ //not submitted yet, display the form
   ?>
      <form name="loginPage" action="<?php echo $PHP_SELF; ?>" method="POST">
         Username: <input type="text" name="user" /><br />
         Password: <input type="password" name="password" /><br />
         <input type="submit" value="Login" name="submit"/>
      </form>
   <?php
}
  1. <?php
  2. //
  3. if($_POST['submit']){
  4.    $username = $_POST['user'];
  5.    $password = $_POST['password'];
  6.    
  7.    
  8.    //If username is 'abc' and password is '123', then login is successfull
  9.    //You may connect this to database
  10.    <span class="posthilit">if($username == 'abc' && $password == '123';
  11.      
  12.    }<span class="posthilit">else{
  13.    Header
  14.      
  15.    }
  16.    
  17.    ?> <a href="">Go Back</a><?php
  18. }else{ //not submitted yet, display the form
  19.    ?>
  20.       <form name="loginPage" action="<?php echo $PHP_SELF; ?>" method="POST">
  21.          Username: <input type="text" name="user" /><br />
  22.          Password: <input type="password" name="password" /><br />
  23.          <input type="submit" value="Login" name="submit"/>
  24.       </form>
  25.    <?php
  26. }
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Code: [ Select ]
<?php
//
if($_POST['submit']){
$username = $_POST['user'];
$password = $_POST['password'];
 
 
//If username is 'abc' and password is '123', then login is successfull
//You may connect this to database
if($username == 'abc' && $password == '123'){?>
  <span class="posthilit">
   Logged in
  <?php }else{ ?><span class="posthilit">
  invalid username <a href="">Go Back</a>
   
  <?php }
}else{ //not submitted yet, display the form
?>
   <form name="loginPage" action="<?php echo $PHP_SELF; ?>" method="POST">
     Username: <input type="text" name="user" /><br />
     Password: <input type="password" name="password" /><br />
     <input type="submit" value="Login" name="submit"/>
   </form>
  <?php
}
?>
  1. <?php
  2. //
  3. if($_POST['submit']){
  4. $username = $_POST['user'];
  5. $password = $_POST['password'];
  6.  
  7.  
  8. //If username is 'abc' and password is '123', then login is successfull
  9. //You may connect this to database
  10. if($username == 'abc' && $password == '123'){?>
  11.   <span class="posthilit">
  12.    Logged in
  13.   <?php }else{ ?><span class="posthilit">
  14.   invalid username <a href="">Go Back</a>
  15.    
  16.   <?php }
  17. }else{ //not submitted yet, display the form
  18. ?>
  19.    <form name="loginPage" action="<?php echo $PHP_SELF; ?>" method="POST">
  20.      Username: <input type="text" name="user" /><br />
  21.      Password: <input type="password" name="password" /><br />
  22.      <input type="submit" value="Login" name="submit"/>
  23.    </form>
  24.   <?php
  25. }
  26. ?>


Nasty but it should work
  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1240
  • Loc: Sydney

Post 3+ Months Ago

hhmm just looking over the code, would there be a way to add additional logins
Code: [ Select ]
<form name="loginPage" action="<?php echo $PHP_SELF; ?>" method="POST">
   Username: <input type="text" name="user" /><br />
   Password: <input type="password" name="password" /><br />
  or_else
   Username: <input type="text" name="user2" /><br />
   Password: <input type="password" name="password2" /><br />
   <input type="submit" value="Login" name="submit"/>
  </form>
  1. <form name="loginPage" action="<?php echo $PHP_SELF; ?>" method="POST">
  2.    Username: <input type="text" name="user" /><br />
  3.    Password: <input type="password" name="password" /><br />
  4.   or_else
  5.    Username: <input type="text" name="user2" /><br />
  6.    Password: <input type="password" name="password2" /><br />
  7.    <input type="submit" value="Login" name="submit"/>
  8.   </form>
  • baligena
  • Novice
  • Novice
  • baligena
  • Posts: 25

Post 3+ Months Ago

remember to sanitize and filter the user input for security. This prevents malicious injections. Study the function----> filter_var($variable, $filter)


-baligena
  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Posts: 214
  • Loc: Sweden

Post 3+ Months Ago

Zealous wrote:
hhmm just looking over the code, would there be a way to add additional logins
Code: [ Select ]
<form name="loginPage" action="<?php echo $PHP_SELF; ?>" method="POST">
   Username: <input type="text" name="user" /><br />
   Password: <input type="password" name="password" /><br />
  or_else
   Username: <input type="text" name="user2" /><br />
   Password: <input type="password" name="password2" /><br />
   <input type="submit" value="Login" name="submit"/>
  </form>
  1. <form name="loginPage" action="<?php echo $PHP_SELF; ?>" method="POST">
  2.    Username: <input type="text" name="user" /><br />
  3.    Password: <input type="password" name="password" /><br />
  4.   or_else
  5.    Username: <input type="text" name="user2" /><br />
  6.    Password: <input type="password" name="password2" /><br />
  7.    <input type="submit" value="Login" name="submit"/>
  8.   </form>


I think you are messing with the code in the wrong end. That should add more fields, but you only need two submit fields (one to submit user name the other to submit password). I think its the "backend/serverside checking" you would like to mess with.

If you take rabid_dog's example:

Code: [ Select ]
if($username == 'abc' && $password == '123')


That checks if password is 123 and user name is abc. Could be altered to:
Code: [ Select ]
if(($username == 'abc' && $password == '123') || ($username == 'user2' && $password == '456'))


That should make it a two user login. One being "abc" pass: "123", the other being "user2" with password "456".
  • Usmandon
  • Born
  • Born
  • Usmandon
  • Posts: 2

Post 3+ Months Ago

please i need help getting this on php
here is my html

</select>
<select name="birthmonth" id="birthmonth">
<option value="-1">Month:</option><option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
<option value="4">Apr</option>
<option value="5">May</option>
<option value="6">Jun</option>
<option value="7">Jul</option>
<option value="8">Aug</option>
<option value="9">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
  • natas
  • PHP Ninja
  • Proficient
  • natas
  • Posts: 308
  • Loc: AFK

Post 3+ Months Ago

Code: [ Select ]
Month:
<select name="birthmonth" id="birthmonth">
  <option value="1">Jan</option>
  <option value="2">Feb</option>
  <option value="3">Mar</option>
  <option value="4">Apr</option>
  <option value="5">May</option>
  <option value="6">Jun</option>
  <option value="7">Jul</option>
  <option value="8">Aug</option>
  <option value="9">Sep</option>
  <option value="10">Oct</option>
  <option value="11">Nov</option>
  <option value="12">Dec</option>
</select>
  1. Month:
  2. <select name="birthmonth" id="birthmonth">
  3.   <option value="1">Jan</option>
  4.   <option value="2">Feb</option>
  5.   <option value="3">Mar</option>
  6.   <option value="4">Apr</option>
  7.   <option value="5">May</option>
  8.   <option value="6">Jun</option>
  9.   <option value="7">Jul</option>
  10.   <option value="8">Aug</option>
  11.   <option value="9">Sep</option>
  12.   <option value="10">Oct</option>
  13.   <option value="11">Nov</option>
  14.   <option value="12">Dec</option>
  15. </select>

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 58 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.