yay my first working script

  • pureone_36
  • Novice
  • Novice
  • pureone_36
  • Posts: 24
  • Loc: earth

Post 3+ Months Ago

well im please to say my first step towards finishing off my site has happen and i would like to share my finished script.
theres 4

the 2 html scripts
the 2 php scripts
they are there basic because ive jus finished them and its taken me a week to get up and running ive been doing php for 2 weeks or maybe 3 not sure but i love it.

well here is the sign up script
by the way i do not really intend to use this on a remote host so the txt files can be put some were else on the computer to be located

Code: [ Select ]
<html>
<body><center>
<form name="overfile" method="submit"
action="over.php"><input name="username" type="text" value="create a user name" /><br/><input name="password" type="password" value=""/><input type="submit"></form></center></body>
</html>
  1. <html>
  2. <body><center>
  3. <form name="overfile" method="submit"
  4. action="over.php"><input name="username" type="text" value="create a user name" /><br/><input name="password" type="password" value=""/><input type="submit"></form></center></body>
  5. </html>


Code: [ Select ]
<?php
{
$filename = 'database.txt';
$user = $_REQUEST["username"];
$somecontent = $_REQUEST["password"];
$testline = md5($user) . ";" . md5($somecontent) . "\n";
}
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

  // In our example we're opening $filename in append mode.
  // The file pointer is at the bottom of the file hence
  // that's where $somecontent will go when we fwrite() it.
  if (!$handle = fopen($filename, 'a')) {
     echo "Cannot open file ($filename)";
     exit;
  }

  // Write $somecontent to our opened file.
  if (fwrite($handle, $testline) === FALSE) {
    echo "Cannot write to file ($filename)";
    exit;
  }
 
  echo "Success, wrote ($user,) to file ($filename)";
 
  fclose($handle);
         
} else {
  echo "The file $filename is not writable";
}
?>
  1. <?php
  2. {
  3. $filename = 'database.txt';
  4. $user = $_REQUEST["username"];
  5. $somecontent = $_REQUEST["password"];
  6. $testline = md5($user) . ";" . md5($somecontent) . "\n";
  7. }
  8. // Let's make sure the file exists and is writable first.
  9. if (is_writable($filename)) {
  10.   // In our example we're opening $filename in append mode.
  11.   // The file pointer is at the bottom of the file hence
  12.   // that's where $somecontent will go when we fwrite() it.
  13.   if (!$handle = fopen($filename, 'a')) {
  14.      echo "Cannot open file ($filename)";
  15.      exit;
  16.   }
  17.   // Write $somecontent to our opened file.
  18.   if (fwrite($handle, $testline) === FALSE) {
  19.     echo "Cannot write to file ($filename)";
  20.     exit;
  21.   }
  22.  
  23.   echo "Success, wrote ($user,) to file ($filename)";
  24.  
  25.   fclose($handle);
  26.          
  27. } else {
  28.   echo "The file $filename is not writable";
  29. }
  30. ?>



and once they have signed up they can then log in

Code: [ Select ]
<table width="20%" border="3" cellspacing="3" cellpadding="5" align="center">
 <tr><td width="5%"><BR><CENTER><h3>login here submit a username and password</h3>
<center><form name="logme" method="post" action="checkmd5.php"> <input name="username" type="text" value="" /><br /><input name="password" type="password" value="" /><center><input type="submit"></form></center></center>
  1. <table width="20%" border="3" cellspacing="3" cellpadding="5" align="center">
  2.  <tr><td width="5%"><BR><CENTER><h3>login here submit a username and password</h3>
  3. <center><form name="logme" method="post" action="checkmd5.php"> <input name="username" type="text" value="" /><br /><input name="password" type="password" value="" /><center><input type="submit"></form></center></center>



Code: [ Select ]
<?php
// This script is intended to accept a username and password and then
// check that against a database file
// First define the name of the database file here, so it is easy to change
$databasefile = "database.txt";
// Here we define the target locations for success and failure
$successurl    =    "http://www.google.com";
$failedurl    =    "http://www.yahoo.com";
// Here we set a variable that controls if error messages will be shown
$showerrors    =    TRUE;

// Then set a control variable that will signal failure or success
// We will assume failure so only when there is a match access is allowed
$match    =    FALSE;


// Now we start doing a whole bunch of checks, before we start the real work

// First check if the username and password parameters are available at all.
// These parameters are expected to be POSTED from an html form, so we will
// look in the $_POST array for them.
$username = $_REQUEST["username"];
$password = $_REQUEST["password"];


if ($username    ==    ""    || $password    ==    "")
    {
    // The username or password was not provided, show error message
    if ($showerrors)    print("Username or password were not provided.<br />");
    }
else
    {
    // The username and password were provided, now check if the database
    // file actually exists.
    if (!file_exists($databasefile))
        {
        // The database file does not exist, show error message
        if ($showerrors)    print("Database file " . $databasefile . " not found.<br />");
        }
    else
        {
        // The database file does exist, so read it
        $lines    =    file($databasefile);
        // Count the number of lines in the lines array
        $linecount    =    count($lines);
        // Check if there is at least one line
        if ($linecount    <    1)
            {
            // No lines were found in the lines array, show error message
            if ($showerrors)    print("No lines found in database file " . $databasefile . ".<br />");
            }
        else
            {
            // At least one line was found in the lines array, go through them
            for ($i = 0; $i < $linecount; $i++)
                {
                // Split the current line into parts on the semicolon
                $parts    =    explode(";",$lines[$i]);
                // There are supposed to be TWO parts, the username and password
                $partcount    =    count($parts);
                if ($partcount    !=    2)
                    {
                    // The number of parts was NOT two, show error message
                    if ($showerrors)    print("The number of parts in line " . $i . " is " . $partcount . ".<br />");
                    }
                else
                    {
                    // The number of parts IS two, strip spaces from the parts
                    $parts[0]    =    trim($parts[0]);
                    $parts[1]    =    trim($parts[1]);

                    // Now we finally can compare the input to these parts
                    
if ($parts[0]    ==    md5($username)    &&    $parts[1]    ==    md5($password))
{
                        
$match = TRUE;
                        // Break out of the for loop to stop going through the lines
                        break;
                        }
                    }
                } // The for loop ends here
                
            // Check if there was a match
            if ($match    ==    FALSE)
                {
                // There was no match, go to failed url
                header("Location: " . $failedurl);
                }
            else
                {
                // There was a match, go to the success url
                header("Location: " . $successurl);
                }
            }
        }
    }


?>
  1. <?php
  2. // This script is intended to accept a username and password and then
  3. // check that against a database file
  4. // First define the name of the database file here, so it is easy to change
  5. $databasefile = "database.txt";
  6. // Here we define the target locations for success and failure
  7. $successurl    =    "http://www.google.com";
  8. $failedurl    =    "http://www.yahoo.com";
  9. // Here we set a variable that controls if error messages will be shown
  10. $showerrors    =    TRUE;
  11. // Then set a control variable that will signal failure or success
  12. // We will assume failure so only when there is a match access is allowed
  13. $match    =    FALSE;
  14. // Now we start doing a whole bunch of checks, before we start the real work
  15. // First check if the username and password parameters are available at all.
  16. // These parameters are expected to be POSTED from an html form, so we will
  17. // look in the $_POST array for them.
  18. $username = $_REQUEST["username"];
  19. $password = $_REQUEST["password"];
  20. if ($username    ==    ""    || $password    ==    "")
  21.     {
  22.     // The username or password was not provided, show error message
  23.     if ($showerrors)    print("Username or password were not provided.<br />");
  24.     }
  25. else
  26.     {
  27.     // The username and password were provided, now check if the database
  28.     // file actually exists.
  29.     if (!file_exists($databasefile))
  30.         {
  31.         // The database file does not exist, show error message
  32.         if ($showerrors)    print("Database file " . $databasefile . " not found.<br />");
  33.         }
  34.     else
  35.         {
  36.         // The database file does exist, so read it
  37.         $lines    =    file($databasefile);
  38.         // Count the number of lines in the lines array
  39.         $linecount    =    count($lines);
  40.         // Check if there is at least one line
  41.         if ($linecount    <    1)
  42.             {
  43.             // No lines were found in the lines array, show error message
  44.             if ($showerrors)    print("No lines found in database file " . $databasefile . ".<br />");
  45.             }
  46.         else
  47.             {
  48.             // At least one line was found in the lines array, go through them
  49.             for ($i = 0; $i < $linecount; $i++)
  50.                 {
  51.                 // Split the current line into parts on the semicolon
  52.                 $parts    =    explode(";",$lines[$i]);
  53.                 // There are supposed to be TWO parts, the username and password
  54.                 $partcount    =    count($parts);
  55.                 if ($partcount    !=    2)
  56.                     {
  57.                     // The number of parts was NOT two, show error message
  58.                     if ($showerrors)    print("The number of parts in line " . $i . " is " . $partcount . ".<br />");
  59.                     }
  60.                 else
  61.                     {
  62.                     // The number of parts IS two, strip spaces from the parts
  63.                     $parts[0]    =    trim($parts[0]);
  64.                     $parts[1]    =    trim($parts[1]);
  65.                     // Now we finally can compare the input to these parts
  66.                     
  67. if ($parts[0]    ==    md5($username)    &&    $parts[1]    ==    md5($password))
  68. {
  69.                         
  70. $match = TRUE;
  71.                         // Break out of the for loop to stop going through the lines
  72.                         break;
  73.                         }
  74.                     }
  75.                 } // The for loop ends here
  76.                 
  77.             // Check if there was a match
  78.             if ($match    ==    FALSE)
  79.                 {
  80.                 // There was no match, go to failed url
  81.                 header("Location: " . $failedurl);
  82.                 }
  83.             else
  84.                 {
  85.                 // There was a match, go to the success url
  86.                 header("Location: " . $successurl);
  87.                 }
  88.             }
  89.         }
  90.     }
  91. ?>



im happy so hopefully some people can learn from this


tell me what you think
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • veedee
  • Graduate
  • Graduate
  • User avatar
  • Posts: 110

Post 3+ Months Ago

wowww..!
That's your first ever PHP script?
mine just :

<?php
echo "hello ozzu, great forum here !!";
?>

Good job buddy,.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

mine was

[php]
<?
echo "Hello World!";
?>
  • pureone_36
  • Novice
  • Novice
  • pureone_36
  • Posts: 24
  • Loc: earth

Post 3+ Months Ago

im not going to change the title


but jus for the record this is my first useful working script

everyone has bloody done a simple script but this is my first complex

maybe i should of stated that

my first real simple script was

<?php
if $remote_addr == <myip>
header("location : http://youraregay.com")
else
print("welcome who ever")
  • veedee
  • Graduate
  • Graduate
  • User avatar
  • Posts: 110

Post 3+ Months Ago

second script :

<?php
$no="female can't be a gay";
echo $no;
?>
  • pureone_36
  • Novice
  • Novice
  • pureone_36
  • Posts: 24
  • Loc: earth

Post 3+ Months Ago

bah


i tell you my second script was a cookie one but it never worked!

so heres another script i made last night




Code: [ Select ]
<?php
$no1 = $_POST["no1"];
$no2 = $_POST["no2"];
$no3 = $_POST["no3"];
$no4 = $_POST["no4"];
{
if (($no1 == "") && ($no2 == "")
&& ($no3 == "") && ($no4 == ""))
print(" duh! ");
else
{
print(" the ip you submited in binary form is :") ."\n";
echo decbin($no1) ."\n";
echo decbin($no2) ."\n";
echo decbin($no3) ."\n";
echo decbin($no4) ."\n";
}
}
?>
  1. <?php
  2. $no1 = $_POST["no1"];
  3. $no2 = $_POST["no2"];
  4. $no3 = $_POST["no3"];
  5. $no4 = $_POST["no4"];
  6. {
  7. if (($no1 == "") && ($no2 == "")
  8. && ($no3 == "") && ($no4 == ""))
  9. print(" duh! ");
  10. else
  11. {
  12. print(" the ip you submited in binary form is :") ."\n";
  13. echo decbin($no1) ."\n";
  14. echo decbin($no2) ."\n";
  15. echo decbin($no3) ."\n";
  16. echo decbin($no4) ."\n";
  17. }
  18. }
  19. ?>



changes ip to binary

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 124 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.