SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 43 of 43
  1. #26
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well said Gib!

    The ceil() function can also round up

    http://uk.php.net/manual/en/function.ceil.php

  2. #27
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also check out 'number_format'...

    http://au.php.net/number_format
    Lats...

  3. #28
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And all that...... just from the PHP manual!

  4. #29
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gibb you showed us how to find a string name. Is there a way you can give the line nuber to tell what the line is and set it too a string. What I want to do is make a text file where the user puts his name in the one text file. When he goes to login I will use the code to search for his name. Then in another text file I will have the passwords on the same line as the last text file. So when he puts his username in (if the name exists) it will go to the same line in the password file that was the same line where the username was and then check if it is correct and allow them access to the page. I know you're going to say start using a MySql database, but I want to learn these very basic scripts, so I dont really need a big database.

  5. #30
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Forgive me if I ask stupid questions, or wound annoying. I'm just a sixteen year old kid trying to figure out what most sixteen year old kids could care less about. What the best way to learn about mysql and php. I've been looking at these sites, but I have no idea what I am looking at.

  6. #31
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Get Kevin Yank's book. And if you don't have the money, put a bug in Santa's ear so you can get it for a Christmas present!
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  7. #32
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing I cant seem to find in the manual is "\n\r" that was in one of the codes but I can't figure out what they mean.

  8. #33
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    \n means new line.

    \r means a carriage return.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  9. #34
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does carriage return mean?

  10. #35
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, you're too young to remember the old days of typewriters.

    Actually, for the purposes of your code, carriage return and line feed are just different ways of representing a new line.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  11. #36
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone know how to specify a line number and then get that line into a variable?

  12. #37
    SitePoint Member
    Join Date
    May 2002
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Steven Vant
    Gibb you showed us how to find a string name. Is there a way you can give the line nuber to tell what the line is and set it too a string. What I want to do is make a text file where the user puts his name in the one text file. When he goes to login I will use the code to search for his name. Then in another text file I will have the passwords on the same line as the last text file. So when he puts his username in (if the name exists) it will go to the same line in the password file that was the same line where the username was and then check if it is correct and allow them access to the page. I know you're going to say start using a MySql database, but I want to learn these very basic scripts, so I dont really need a big database.
    Put both the username and password in the same file. Store both pieces of information on the same line and separate them using a delimiter character.

    There are many functions that would be useful for solving this problem. These are the ones that immediately came to mind.
    file_get_contents()
    file()
    explode()
    str_replace()
    trim()
    foreach construct

    A line from the username / password file would look like this (I used a colon to separate the two fields, you could use something else):
    Code:
    username:password
    You could read the user file with the file() function which would give you an array of username / password combinations. At this point you would iterate through the array using foreach and check for the desired username after using explode() to split the username and password into separate variables.

    Post if you want a more in depth explanation.

  13. #38
    If it aint Dutch it aint much Kilroy's Avatar
    Join Date
    Oct 2003
    Location
    The Netherlands
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would also recommend looking at file_put_contents()

  14. #39
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know how to do all of that. The reason I say 2 different files is because I dont want the search ssearching the other site of the array. I don't want it to search the password side. Thats why I can use 'strstr' to give me the line of the username and then use that line number to go to that same line on the password file. I actually think this is a little easier with having 2 files and if would make the search flawless because now you have eliminated the password side of the file. Now what would I use to specify a line number and get that line into a string?

  15. #40
    SitePoint Enthusiast JoJoNAloha's Avatar
    Join Date
    Nov 2004
    Location
    Oregon
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey Gibb, i am messing with the little script you gave us to search for a string in a file and i got it to work, except i was wondering why an else command won't work here.

    PHP Code:
    <?php $username=$_POST["username"];
    $password=$_POST["password"];
    $srchstr=$username ." - "$password ." -";
    ?>

    <?php
    $fp
    =fopen("unpw.txt","rb");
    while(!
    feof ($fp))
    {
    $line fgets($fp1024);
    if (
    strstr($line$srchstr))
        {
        echo 
    "Search string found on this line: <br />";
        echo 
    $line ."<br />";
        };
    }; 
    ?>
    that is what works, but eventually i'm going to just forward it to one page if the username and password are correct and another if they are incorrect, so i tried the else here

    PHP Code:
    if (strstr($line$srchstr))
        {
        echo 
    "Search string found on this line: <br />";
        echo 
    $line ."<br />";
        };
    else echo 
    "Invalid Username and/or Password";
    }; 
    ?> 
    and i get this error:
    Parse error: parse error, unexpected T_ELSE in /home/freehost/t35.com/j/o/jojonaloha/login.php on line 22


    Thanks!
    Jonathan

  16. #41
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This }; should just be } for one thing. Then you forgot a { after else.

    PHP Code:
      <?php
      
    if (strstr($line$srchstr))
      {
          echo 
    "Search string found on this line: <br />";
          echo 
    $line ."<br />";
      }
      else
      {
          echo 
    "Invalid Username and/or Password";
      }
    The whole thing would look like this. Always indent to make your code easier to read and easier to debug.

    PHP Code:
     while(!feof ($fp))
     {
         
    $line fgets($fp1024);
         if (
    strstr($line$srchstr))
         {
             echo 
    "Search string found on this line: <br />";
             echo 
    $line ."<br />";
         }
         else
         {
             echo 
    "Invalid Username and/or Password";
         }
     } 


  17. #42
    SitePoint Enthusiast JoJoNAloha's Avatar
    Join Date
    Nov 2004
    Location
    Oregon
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, that worked, but it repeats it each time until the end of the document... how would i check the entire file and if it doesn't find any matches then echo the "invalid..."

  18. #43
    SitePoint Enthusiast JoJoNAloha's Avatar
    Join Date
    Nov 2004
    Location
    Oregon
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, so i was trying to be creative and solve this problem so i came up with this... ok, i just looked at it and realized i was being stupid, so i played with it more and now i think it WORKS! tell me what you think...

    PHP Code:
    <?php
    $fp
    =fopen("unpw.txt","rb");
    while(!
    feof ($fp))
    {
    $line fgets($fp1024);
    if (
    $x==0)
        {
        if (
    strstr($line$srchstr))
            {
            
    $x++;
            echo 
    "Welcome "$username;
            };
        }
    };
    if (
    feof ($fp) && $x==0)
    {
    echo 
    "Invalid Username and/or Password";
    }; 
    ?>
    Jonathan


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
  •