Results 1 to 38 of 38

Thread: need some serious help pls ?

  1. #1

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609

    Exclamation need some serious help pls ?

    I have been workinh on the shell of this page for some time now, bits and pieces, i finally got the login script to work while substitutin the cookie aloocations with text being displayed that shoed whether you would have been logged in or not. anyway, i replaced this text with the code to assign a cookie, and all of a sudden it didnt work. i spent five and a half hours trying to geet it to work, and now, the next day it is still troubling me, can someone pleeeeeeze help me ?

    some extra info: when i just type in the code to assign the cookie on the main index (Index.php) page, it works fine and displays the user specified as being logged in, but when i run a script on a seperate page (Includes/do_log.php) then when i go back to the main page it isnt there. logouts used to work but now have stopped.

    any questions ort anything, feel free to post them

    I'v also included a ZIP containing the entire web system (pages).
    Attached Files Attached Files
    • File Type: zip x.zip (7.5 KB, 28 views)

  2. #2
    ricmitch_uk
    Guest
    index.php & backup of index.php

    1) You need to close the MySQL connection you opened for the counter:
    the code for this is: mysql_close($link); or just mysql_close(); to close all open links.
    This may be confusing links in other pages, and slowing your system down.

    2) //setcookie ("ubunreal_user", "buesr", time() + 43200); is this meant to be spelt buesr? or buser?

    do_log.php

    1) Maybe if you set the cookie when they logged in, you'd get somewhere...

    Can't find anything wrong with Backup Of do_log.php
    Possible problems:
    • your browser could be blocking the cookies
    • your version of PHP might not work with cookies
    • something could be wrong with the SQL. I wouldn't know without a MySQL dump.

    Couldn't spot anything else that was obvious.
    Just check all your cross-page variables and MySQL column & table names are the same on the pages.

    HTH

    BTW. nice neat code there

  3. #3

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    i know about msql_close();, it isnt affecting my code and i know so cos i have thoroughly tested it for that, and the reason do_log.php has the cookie commentded out is so i dont have to keep re-typing it when i am testing, so i can just run the page and the only think it will do is run the cokie script and not anything else assuming i dont add the URL string variables for the other stuff.

    2) //setcookie ("ubunreal_user", "buesr", time() + 43200); is this meant to be spelt buesr? or buser?
    no, its just a string i'm assigning to the cookie for testing purposes, i wasnt even trying to spell anything, i just kabbled something in

    [i]a bit more of an explanation:[/u] in includes/do_log.php on line 3 is the testcode to assign the cookie from anothwer page other than the main index module. when i run this page top assign the cookie and then return the the main index, the cookie doesnt appear to have been created. the code for checking if the cookie exists is in index.php lines 3 - 7, this checking code works fine, and i know this becos when i copy the setcookie code from includes/do_log.php to the beginning the main index, it works, why does it work when run in the main index module and now from 'do_log.php' ???

    BTW. nice neat code there
    if u werent being sarcuastic, then thanx i try and keep it that way cos i get confused if i dont, and try to comment stuff that isnt 100% clear iin the mind.

    anyway, any help or comment is appreciated on this situation, so thanx in advance

  4. #4
    scoutt
    Guest
    ok I am a little lost. you want to see if the cookie is set but you don't check for it.

    either one of these
    echo $TestCookie;
    echo $HTTP_COOKIE_VARS["TestCookie"];

    if the value is null or != then you can say no cookie.

    or

    Common Pitfalls:

    Cookies will not become visible until the next loading of a page that the cookie should be visible for.

    Cookies must be deleted with the same parameters as they were set with.

  5. #5
    ricmitch_uk
    Guest
    Another common pitfall is that cookies are sent in reverse order (don't ask me why). So if you want to delete a cookie and then send a new one, you have to send the new one first, and then delete the current one. Confusing I know

  6. #6

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    Originally posted by scoutt
    ok I am a little lost. you want to see if the cookie is set but you don't check for it.

    either one of these
    echo $TestCookie;
    echo $HTTP_COOKIE_VARS["TestCookie"];

    if the value is null or != then you can say no cookie.

    or

    Common Pitfalls:

    Cookies will not become visible until the next loading of a page that the cookie should be visible for.

    Cookies must be deleted with the same parameters as they were set with.
    have u had a look @ my code, i can do everything fine, except set the cookie. ok, I'll just throw you the problem straight foreward then:

    this works fine:
    PHP Code:
    IF ($action == "login"
        {
    $result mysql_query("SELECT * FROM Users WHERE uname='$u_name' AND upassword='$u_password'");
                IF (
    mysql_numrows($result) == "1") {ECHO "loggen in ok";}
                ELSE {ECHO 
    "Failed to log in, sorry";}}                
    ELSEIF (
    $action == "logout")
        {
    setcookie ("ubunreal_user"""time() - 43200);} 
    but this doesnt:
    PHP Code:
    IF ($action == "login"
        {
    $result mysql_query("SELECT * FROM Users WHERE uname='$u_name' AND upassword='$u_password'");
                IF (
    mysql_numrows($result) == "1") {setcookie ("ubunreal_user""$ubunreal_user"time() + 43200);}
                ELSE {ECHO 
    "Failed to log in, sorry";}}                
    ELSEIF (
    $action == "logout")
        {
    setcookie ("ubunreal_user"""time() - 43200);} 
    can anyone explain that ? its the code fom inside the INCLUDE file that i use for this login script.

    this is soo fustrating

    can anyone help ?

  7. #7
    scoutt
    Guest
    IF ($action == "login")
    {$result = mysql_query("SELECT * FROM Users WHERE uname='$u_name' AND upassword='$u_password'");
    IF (mysql_numrows($result) == "1") {setcookie ("ubunreal_user", "$ubunreal_user", time() + 43200);}
    ELSE {ECHO "Failed to log in, sorry";}}
    ELSEIF ($action == "logout")
    {setcookie ("ubunreal_user", "", time() - 43200);}
    I am sure it won't work becasue you forgot to add a _ after num

  8. #8

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    no, no, no, that part is correct, look @ my previous example of what the problem is. The "IF" statement works like a charm, finds whether the user exists with the password, so basically what it does in that statement is that if the user exists then do this, otherwise do this, @ the moment this is just writing words to the screen (eg. u logged in / out) but when i replace that with "setcookie ("ubunreal_user", "$ubunreal_user", time() + 43200);" then it doesnt work. look @ my code carefully and u'll see what i mean.

  9. #9
    scoutt
    Guest
    there is no such function as "mysql_numrows()"

    so which setcookie is not working. if it is the first one fix that function and then if it still doesn't work I am curious as to where $ubunreal_user is coming from. if it is from the database then you will hav to specify what row it had come from. so I would after the query is do a while statement adn get the info from the database so $ubunreal_user gets filled.

  10. #10

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    ok scoutt, i'v changed everything u have suggested btw. the "mysql_numrows" works as well as "mysql_num_rows", they both work

    i'v changed the code to as follows:
    PHP Code:
    <?PHP
    $link 
    mysql_connect("127.0.0.1""root");
    mysql_select_db("ubunreal");

    IF (
    $action == "logout")
        {
    setcookie ("ubunreal_user"""time() - 43200);
        
    header("Location: [url]http://127.0.0.1/php_learning/Ubunr3al2/index.php?page=home[/url]");}
    ELSEIF (
    $action == "login"
        {
        
    $result mysql_query("SELECT * FROM Users WHERE uname='$u_name' AND upassword='$u_password'");
            IF (
    mysql_num_rows($result) != "1")
                {ECHO 
    "Failed to log in, sorry";}
            ELSEIF (
    mysql_num_rows($result) == "1"
                {
    setcookie ("ubunreal_user""$u_name"time() + 43200);
                
    /* ECHO "loggen in ok"; */}
        }

    header("Location: ../index.php");
    mysql_close($link);    
    ?>
    "$u_name" & "$u_name" are passed from the login form, they exist, trust me.

  11. #11

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    [*]
    "$u_name" & "$u_password" are passed from the login form, they exist, trust me.

  12. #12
    scoutt
    Guest
    try this
    PHP Code:
    <?PHP
    $link 
    mysql_connect("127.0.0.1""root");
    mysql_select_db("ubunreal");

    IF (
    $action == "logout")
        {
    setcookie ("ubunreal_user"""time() - 43200);
        
    header("Location: <a href="http://127.0.0.1/php_learning/Ubunr3al2/index.php?page=home" target="_blank">[url]http://127.0.0.1/php_learning/Ubunr...x.php?page=home[/url]</a>");}
    ELSEIF ($action == "login"
        {
        
    $result mysql_query("SELECT * FROM Users WHERE uname='$u_name' AND upassword='$u_password'");
            
    $num mysql_num_rows($result)
                 while (
    $row mysql_fetch_array($result))
                  {
                  
    $name$row["u_name"];
                  }

               IF (!
    $num)
                {ECHO 
    "Failed to log in, sorry";}
            ELSE{
                   
    setcookie ("ubunreal_user""$name"time() + 43200);
                
    /* ECHO "loggen in ok"; */}
        }

    header("Location: ../index.php");
    mysql_close($link);    
    ?>

  13. #13

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    Originally posted by scoutt
    try this
    lol, my code worked sooo much better
    than that, mine works like a dream with the exception of the
    cookie problem, i dont think u understand that. my code does
    work
    , but why when i place the cookie assignments in there it
    then doesnt work ?

    maybe i should leave this problem for a while and come back to it
    when i have more experience ? anyway, i have a page that i
    can run that will log me in as an "admin" , and the "logout"
    button works like a dream

  14. #14
    scoutt
    Guest
    that doesn't make since. you say your code works so much better but once you stick the setcookie code in there it dies. well it could be that your pc doesn't update your cookies right. the setcookie is fine. the only reason it would die is that it can't get the variable it needs. did you delete all your cookies and see if it makes a new one? also I wouldn't even bother with cookies, as sessions are so much more proficient and easier.

  15. #15
    scoutt
    Guest
    and this is not better as you are doing a double talk so to speak.

    IF (mysql_num_rows($result) != "1")
    {ECHO "Failed to log in, sorry";}
    ELSEIF (mysql_num_rows($result) == "1")


    if it is not 1 then it has to be 1, so all you need is the else statement.

  16. #16

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    Originally posted by scoutt
    that doesn't make since. you say your code works so much
    better but once you stick the setcookie code in there it dies. well
    it could be that your pc doesn't update your cookies right. the
    setcookie is fine. the only reason it would die is that it can't get
    the variable it needs. did you delete all your cookies and see if it
    makes a new one? also I wouldn't even bother with cookies, as
    sessions are so much more proficient and easier.
    well, when i run the script (IF statement for login) it works fine as long as the output is just text written to the screen (ECHO "" but when the output / action is writing a cookie then it doesnt assign the cookie. but if i just assign the cookie outright from another file then then reload the main index, then it works. this is the most confusing thing i have ever come across in my life, it should work.

  17. #17

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    Originally posted by scoutt
    and this is not better as you are doing a double talk so to speak.

    IF (mysql_num_rows($result) != "1")
    {ECHO "Failed to log in, sorry";}
    ELSEIF (mysql_num_rows($result) == "1")


    if it is not 1 then it has to be 1, so all you need is the else statement.
    lol,yeh, i suppose hey

    thanx

  18. #18
    scoutt
    Guest
    let me look at it tomorrow and see if I can get it to set a cookie on my server.

  19. #19
    scoutt
    Guest
    Michael:

    this works for me adn it sets a cookie.
    PHP Code:
    <?
    $link = mysql_connect("localhost", "root", "*****");
    mysql_select_db("ubunreal");

    IF ($action == "logout"){
      setcookie("ubunreal_user", "", time() - 43200);
     ECHO "Cookie has been deleted.";
     exit;
    }
    IF ($action == "login")
        {
        $result = mysql_query("SELECT * FROM Users WHERE name='$u_name' AND pass='$u_password'");
            $check = mysql_num_rows($result);
              IF (!$check)
                {ECHO "Failed to log in, sorry";
                exit;
                }
            ELSE{
              setcookie ("ubunreal_user", "$u_name", time() + 43200);

                 echo "Welcome $u_name, you <br>";
                 ECHO "loggen in ok";
                 echo"<META HTTP-EQUIV=\"Refresh\" Content=\"1;URL=../index.php\">";
                 }
    mysql_close($link);
     }else{

    ?>
    <html>
    <head></head>
    <body>
    <form action="<?= $PHP_SELF ?>" method="post">
    Name<input type=text name=u_name>
    Pass<input type=password name=u_password>
    <input type=hidden name=action value=login>
    <input type=submit value="send">
    </form>
    <form action="<?= $PHP_SELF ?>" method="post">
    <input type=hidden name=action value=logout>
    <input type=submit value="Log Out">
    </form>
    <?
     }
     ?>
    if you want to see it in action let me know and I will send you a link.

  20. #20

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    thanx scoutt I'll give that a try as soon as i can.

  21. #21

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    hmmm, ok, I jad to modify the code slightly, to this:
    PHP Code:
    <?
    $link = mysql_connect("localhost", "root");
    mysql_select_db("ubunreal");

    IF ($action == "logout")
        {setcookie("ubunreal_user", "", time() - 43200);}    
    IF ($action == "login")
        {$result = mysql_query("SELECT * FROM Users WHERE uname='$u_name' AND upassword='$u_password'");
        $check = mysql_num_rows($result);
            IF (!$check)
                {ECHO "Failed to log in, sorry";
                exit;
                } ELSE {
                setcookie ("ubunreal_user", "$u_name", time() + 43200);
                echo "Welcome $u_name, you <br>";
                ECHO "loggen in ok";
                }
        }

    mysql_close($link);
    header("Location: ../index.php");
    ?>
    but guess what ? it will display that "Welcome user, you logged in" but will not assign the cookie which is just before it

    could yo maybe try this code on your machine and tell me if it works ?

  22. #22
    scoutt
    Guest
    did you get any errors? if so what was it. I bet if you tok out that header() it would work.

    I will check it later tonight and get back to you.

  23. #23
    scoutt
    Guest
    yup it worked for me.

  24. #24

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    ok, so you'v created a database named "ubunreal" and 2 fields called "uname" and "upassword" . When you pass 2 variables ("$u_name" & "$u_password") to the code, it searched the specified Databse and displays the relevant output as to whether the user was found or not and sets the cookie if needed.

    am i correct in saying that this works for you ?

    cos right now i am going to emptly my IE temp files and try once more, if it doesnt work I'm not going to be happy with me.

  25. #25
    scoutt
    Guest
    well kind of. I created a test table. the only thing I changed was the connection and table. and you won't be able to use the header function as it errors out. that is why I use the meta tag and reresh

  26. #26

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    I'll post all my new code when i get home this weekend, and a database structural layout. that should get us both on the same par.

  27. #27

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    i'm sure that cookies work, i'v had to create a temperory login
    thiny. ("index2.php") so i can just run it and log me in as
    someone with out having to go through the ogin screen, this is
    the code fir it:
    PHP Code:
    <?PHP
    setcookie 
    ("zeri_user""angel"time() + 43200);
    header("Location: index.php");
    ?>
    now if that workd then my login screen should, but
    when i run this other script (as above) then i have to refresh
    the index page before it picks up the cookie as being set.

  28. #28

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    here u go scoutt, the complete source. now look at "Index2.php", it logs me in fine, but "includes/do_log.php?action=logout" doesnt delete the cookie, cmon, tell me my code is wrong, i dare you

  29. #29

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    oops, forgot to post the file.
    Attached Files Attached Files
    • File Type: zip x.zip (73.6 KB, 19 views)

  30. #30
    scoutt
    Guest
    ok now I am starting to get confused. you say my code on my site didn't create a cookie for you? if that is true then you have problems on your end.

    so, your code looks ok and should create and delete the cookie. if it doesn't then I don't know what to say. the code looks fine and works for me.

  31. #31
    scoutt
    Guest
    Michael:

    I had a friend try that script (the one at my site) and he said it worked for him as well. it created a cookie and deleted it.

    so it sounds like you have problems with IE storing cookies.

  32. #32

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    hmmm, I'll get all over it this weekend, have too many assignments to do right now :'( I'll gave it another try, this is really starting to get to me cos i know that my code is correct and is surposed to work. I'm getting a new PC this afternoon (300mhz, 256mb, 3gb), I'll do fresh installs of everything on it and see how it performs. thanx a lot scoutt.

  33. #33

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    sorry, i forgot to say that i have Opera only chaching pictures, not pages, is this gonna help wit htesting instead of having the page script determine whether it chaches or not ? and does Opera handle Cookies different to IE ?

  34. #34
    scoutt
    Guest
    I don't use opera so I couldn't tell you. but I'm thinking it should be the same or close to it.

  35. #35

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    lol, scoutt, thanx a million for helping me out with this; i finally got a sample that works, and u out up with me all this time

    take a look @ the atached code, it works

  36. #36

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    shet, sorry, have a habbit of forgetting to post atachments here u go ....

  37. #37
    Lively Member
    Join Date
    Jan 2002
    Posts
    117

    opera info

    Hello ubunreal69, as far as programming php/cookies for opera you shouldnt really have any problems with the cookie aspect of things. I've been doing a lot of testing on both IE and Opera and found that Opera is a lot more lenient on coding and doesnt throw up as much as IE does.
    You will definitely want to test your code out seriously on IE for any thing it might not like.

    -Nick

  38. #38

    Thread Starter
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    thanx for your advice nick

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width