SitePoint Sponsor

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 60
  1. #26
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Added var_dump
    PHP Code:
            $result query("UPDATE users SET hash = ? WHERE id = ?"crypt($_POST["password"]), $_SESSION["resetmemberid"]);
            unset(
    $_SESSION["resetmemberid"]); 
    var_dump($result); 
    My guess is you get back an empty array, as by default UPDATE queries return nothing, but usually you can get the affected rows and check against that (not sure how to get that info from the framework you seem to be using though)
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  2. #27
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried that, even with die() after, but it still remains the same... just keeps on showing reset.php again and again..... i've been stuck on this thing for almost 3 days now... and now i've dragged you too into it...

  3. #28
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jay93 View Post
    i tried that, even with die() after, but it still remains the same... just keeps on showing reset.php again and again..... i've been stuck on this thing for almost 3 days now... and now i've dragged you too into it...
    What was the output, was it the same as before empty?
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  4. #29
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, empty..

  5. #30
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, let's figure out what's going on.

    PHP Code:
    <?php
      
            
    // display errors, warnings, and notices
        
    ini_set("display_errors"true);
        
    error_reporting(E_ALL);
      
    // configuration
        
    require("../includes/constants.php"); 
        require(
    "../includes/functions.php");

    var_dump($_POST); // ADDED THIS LINE

        // if form was submitted
       
    if(isset($_POST["submit"]))
        {
        
             if (empty(
    $_POST["password"]))
            
    apologize("Please enter password.");
            
            
            if (
    $_POST["password"] != $_POST["confirmation"])
            
    apologize("Passwords do not match!");
            
            
            
    $result query("UPDATE users SET hash = ? WHERE id = ?"crypt($_POST["password"]), $_SESSION["resetmemberid"]);
            
    $id $_SESSION['resetmemberid']; // ADDED THIS LINE
            
    unset($_SESSION["resetmemberid"]);  
            
    var_dump($result); // ADDED THIS LINE
            
            
    if($result===false)
            {
            
    apologize("Could not register. Please retry.");
            }
            else
              {
      
    // Commented out the below two lines        
    //          $rows = query("SELECT id FROM users WHERE hash = ?", crypt($_POST["password"]));
    //          $id = $rows[0]["id"];
              
              // remember that user's now logged in by storing user's ID in session
              
    $_SESSION["id"]= $id// $rows[0]["id"]; // CHANGED THIS LINE
              // redirect to portfolio
              //redirect("index.php"); // COMMENTED OUT THIS LINE FOR NOW
             
            
    }
             die(); 
    // ADDED THIS LINE FOR NOW
           
    }
               
        
        else
        {
            
    // else render form
            
    render("reset_form.php", ["title" => "Register"]);
        }
        
    ?>
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  6. #31
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is what i got...


    array (size=2)
    'password' => string 'jay' (length=3)
    'confirmation' => string 'jay' (length=3)

  7. #32
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in addition to the displayed page reset.php

  8. #33
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jay93 View Post
    this is what i got...


    array (size=2)
    'password' => string 'jay' (length=3)
    'confirmation' => string 'jay' (length=3)
    Interesting, how is the form being submitted? As there isn't an entry for $_POST["submit"], so the following condition is never executed:
    PHP Code:
    if(isset($_POST["submit"])) 
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  9. #34
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i wish i had your eyes...you really are a guru... how did you find that error using just those array statements from var dump???

    it works perfectly now, password is reset. but one last glitch,a very minor one, i expected it to redirect to index.php as per the line

    // redirect to portfolio
    redirect("index.php");

    but it goes to the login page instead, any ideas??

  10. #35
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jay93 View Post
    i wish i had your eyes...you really are a guru... how did you find that error using just those array statements from var dump???
    Glad you asked If you look at your output
    Code:
    array (size=2)
    'password' => string 'jay' (length=3)
    'confirmation' => string 'jay' (length=3)
    First understand we asked it to dump the values found in $_POST. The dump is only listing two values, password and confirmation. Since it isn't listing submit, we know that $_POST is not receiving that value, therefore, the isset check could never work.

    Quote Originally Posted by jay93 View Post
    but one last glitch,a very minor one, i expected it to redirect to index.php as per the line

    // redirect to portfolio
    redirect("index.php");

    but it goes to the login page instead, any ideas??
    Can you post the code found in your index.php page?
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  11. #36
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, sorry for the late reply, it was actually around 2 am in my part of the world yesterday night, or should i say today morning... this is my code for index.php

    Code:
    <?php
    
        // configuration
        require("../includes/config.php"); 
        
        //defining positions
        
     
        
        $cash = query ("SELECT cash FROM users WHERE id = ?", $_SESSION["id"]);
           
        $positions = [];
        $rows = query ("SELECT symbol, shares FROM portfolio WHERE id = ?", $_SESSION["id"]);
        foreach ($rows as $row)
        {
           $stock = lookup($row["symbol"]);
           if ($stock !== false)
           {
            $positions[]=  [
            "name" => $stock["name"], 
            "price" => $stock["price"], 
            "shares" => $row["shares"], 
            "symbol" => $row["symbol"]
            ];
            
           }
           
       }
     
        // render portfolio
        render("portfolio.php", ["positions" => $positions, "title" => "Portfolio", "cash" => $cash]);
    
    ?>
    and portfolio.php basically prints all the values in $positions in a table... may be this will interest you too,the following is my config.php file included on top...


    Code:
    <?php
    
    
        // display errors, warnings, and notices
        ini_set("display_errors", true);
        error_reporting(E_ALL);
    
        // requirements
        require("constants.php");
        require("functions.php");
    
        // enable sessions
        session_start();
    
        // require authentication for most pages
        if (!preg_match("{(?:login|logout|register)\.php$}", $_SERVER["PHP_SELF"]))
        {
            if (empty($_SESSION["id"]))
            {
                redirect("login.php");
            }
        }
    
    ?>

    thank you so much, for everything... there are very few people out there who do what you've done, sharing knowledge and time...

  12. #37
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, so from your code, we can deduce that the login.php is only shown when not visiting the login, logout, or register pages and when $_SESSION['id'] is empty. You could be looking at two possible problems, 1) reset.php isn't setting $_SESSION['id'] properly with a value, or 2) Your ID is 0, which empty() treats as well ... empty

    So first we need to figure out which case it is, so inside your portfolio.php file, put the following below session_start();
    PHP Code:
    var_dump($_SESSION); die(); 
    If you see size 1 and the name of id with a value of 0, then we need to update your if statement using the following:
    PHP Code:
            if (strlen($_SESSION['id']) === || !is_int($_SESSION['id']))
            {
                
    redirect("login.php");
            } 
    If you see size 0 and empty, then we need to figure out why reset.php didn't set the ID properly, and I'll need to see your updated reset.php code to do that.
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  13. #38
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    """""so inside your portfolio.php file, put the following below session_start();""".... sorry, where you meaning inside my index.php file (whose template is portfolio.php)??

    2. and "below session_start()"" that code is actually in my config.php file which i've included atop of my code of index.php thus

    // configuration
    require("../includes/config.php");
    should i change that inside the config.php file?? if i do that, won't it affect my other pages in which i have included that config.php file/???and in fact there are many such pages...

    3. i tried copying the code in config.php instead of the include config.php statement on top of index.php, and tried adding var_dump($_SESSION); die(); where you specified, but it yells a bunch of errors when i run index.php such as... Warning: require(constants.php): failed to open stream: No such file or directory and

    Fatal error: require(): Failed opening required 'constants.php' (include_path='.:/usr/share/pear:/usr/share/php') both of which point to the boldened line in my code below...(what i currently have ofor index.php...


    Code:
    <?php
    
        
        
        
        // display errors, warnings, and notices
        ini_set("display_errors", true);
        error_reporting(E_ALL);
    
        // requirements
        require("constants.php");          //////// THIS LINE IS THE ONE IT POINTS TO IN THE ERROR MESSAGE PRINTED OUT...
        require("functions.php");
    var_dump($_SESSION); die();  
        // enable sessions
        session_start();
    
        // require authentication for most pages
        if (!preg_match("{(?:login|logout|register)\.php$}", $_SERVER["PHP_SELF"]))
        {
            if (empty($_SESSION["id"]))
            {
                redirect("login.php");
            }
        }
    
     
        
        $cash = query ("SELECT cash FROM users WHERE id = ?", $_SESSION["id"]);
         //defining positions  
        $positions = [];
        $rows = query ("SELECT symbol, shares FROM portfolio WHERE id = ?", $_SESSION["id"]);
        foreach ($rows as $row)
        {
           $stock = lookup($row["symbol"]);
           if ($stock !== false)
           {
            $positions[]=  [
            "name" => $stock["name"], 
            "price" => $stock["price"], 
            "shares" => $row["shares"], 
            "symbol" => $row["symbol"]
            ];
            
           }
           
       }
     
        // render portfolio
        render("portfolio.php", ["positions" => $positions, "title" => "Portfolio", "cash" => $cash]);
    
    ?>

  14. #39
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jay93 View Post
    """""so inside your portfolio.php file, put the following below session_start();""".... sorry, where you meaning inside my index.php file (whose template is portfolio.php)??
    Sorry, mis-read your prior post, confused config.php with portfolio.php

    Quote Originally Posted by jay93 View Post
    2. and "below session_start()"" that code is actually in my config.php file which i've included atop of my code of index.php thus

    // configuration
    require("../includes/config.php");
    should i change that inside the config.php file?? if i do that, won't it affect my other pages in which i have included that config.php file/???and in fact there are many such pages...
    Make sure you put the var_dump and die command AFTER session_start(); otherwise, the session data isn't created and you will get NULL/Empty.

    Quote Originally Posted by jay93 View Post
    3. i tried copying the code in config.php instead of the include config.php statement on top of index.php, and tried adding var_dump($_SESSION); die(); where you specified, but it yells a bunch of errors when i run index.php such as... Warning: require(constants.php): failed to open stream: No such file or directory and

    Fatal error: require(): Failed opening required 'constants.php' (include_path='.:/usr/share/pear:/usr/share/php') both of which point to the boldened line in my code below...(what i currently have ofor index.php...


    Code:
    <?php
    
        
        
        
        // display errors, warnings, and notices
        ini_set("display_errors", true);
        error_reporting(E_ALL);
    
        // requirements
        require("constants.php");          //////// THIS LINE IS THE ONE IT POINTS TO IN THE ERROR MESSAGE PRINTED OUT...
        require("functions.php");
    var_dump($_SESSION); die();  
        // enable sessions
        session_start();
    
        // require authentication for most pages
        if (!preg_match("{(?:login|logout|register)\.php$}", $_SERVER["PHP_SELF"]))
        {
            if (empty($_SESSION["id"]))
            {
                redirect("login.php");
            }
        }
    
     
        
        $cash = query ("SELECT cash FROM users WHERE id = ?", $_SESSION["id"]);
         //defining positions  
        $positions = [];
        $rows = query ("SELECT symbol, shares FROM portfolio WHERE id = ?", $_SESSION["id"]);
        foreach ($rows as $row)
        {
           $stock = lookup($row["symbol"]);
           if ($stock !== false)
           {
            $positions[]=  [
            "name" => $stock["name"], 
            "price" => $stock["price"], 
            "shares" => $row["shares"], 
            "symbol" => $row["symbol"]
            ];
            
           }
           
       }
     
        // render portfolio
        render("portfolio.php", ["positions" => $positions, "title" => "Portfolio", "cash" => $cash]);
    
    ?>
    Not sure why require("constants.php") would all of a sudden not be accessible ... (the file does exist right?) Make sure you are calling your pages like you typically do, do not try and call config.php from the browser (instead call index.php or something similar).
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  15. #40
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried adding the var _dump command after session start, but it stll remains the same....same errors... from the same line related to constants.php... and that file to exists...

  16. #41
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Looks like you used to use
    PHP Code:
        require("../includes/constants.php"); 
        require(
    "../includes/functions.php"); 
    Are you sure you have the path correct?
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  17. #42
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, i can only say you ve been blessed with very sharp eyes... this is what i got

    array (size=1)
    'id' => int 40

  18. #43
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    And to confirm, it is still showing the login page? Instead of the portfolio information?
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  19. #44
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup, i just removed the dump and die functions and checked again...

  20. #45
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Hmm... very odd.

    Try replacing
    PHP Code:
        // require authentication for most pages
        
    if (!preg_match("{(?:login|logout|register)\.php$}"$_SERVER["PHP_SELF"]))
        {
            if (empty(
    $_SESSION["id"]))
            {
                
    redirect("login.php");
            }
        } 
    With
    PHP Code:
        // require authentication for most pages
        
    if (!preg_match("{(?:login|logout|register)\.php$}"$_SERVER["PHP_SELF"]))
        {
            if (empty(
    $_SESSION["id"]))
            {
                die(
    "SESSION ID IS EMPTY");
                
    redirect("login.php");
            }
        } 
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  21. #46
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it now displays a blank page with this showing........ "SESSION ID IS EMPTY"

  22. #47
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, so the var_dump shows id being a part of $_SESSION, but it is evaluated as empty... This is weird.

    Okay, next change
    PHP Code:
        // require authentication for most pages
        
    if (!preg_match("{(?:login|logout|register)\.php$}"$_SERVER["PHP_SELF"]))
        {
            if (empty(
    $_SESSION["id"]))
            {
                
    var_dump($_SESSION);
                die(
    "SESSION ID IS EMPTY");
                
    redirect("login.php");
            }
        } 
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  23. #48
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whoa, i don't quite well understand what's going on and how you 're interperating what looks like nothing tasty to me to sensible information.. , but i did the second change, and this is what i have now

    array (size=1)
    'id' => null
    SESSION ID IS EMPTY

  24. #49
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Interesting, this time the id is null... so loading the login.php page is correct.

    Go through the login, pass, or reset pages and when it eventually redirects you back to index.php let me know what output you get.
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  25. #50
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you mean without the var_dump and die statements??


Tags for this Thread

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
  •