Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21

Thread: My Login Script

  1. #16
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    updates.php should look something like this to prevent the undefined index error after login:
    PHP Code:
    <?php
    session_start
    ();
    include 
    'config.php';

    if(isset(
    $_POST['user']) && isset($_POST['pass']))
    {
        
    $user mysql_real_escape_string($_POST['user']);
        
    $pass mysql_real_escape_string($_POST['pass']); 
        
    $stat mysql_fetch_array(mysql_query("select * from members where user='$user' and pass='$pass'"));

        
    $_SESSION['stat'] = $stat;

        print 
    "Welcome {$stat['user']}";
    }
    else if(isset(
    $_SESSION['stat']['user']))
    {
        print 
    "Welcome {$_SESSION['stat']['user']}";
    }

  2. #17
    New Coder
    Join Date
    Sep 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It been a while since I checked this post as ive been very busy .Ive just made the relevant changes to updates.php and its now just giving me a blank page. I really want to get this sorted

  3. #18
    New Coder
    Join Date
    Sep 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Obviously the session still isnt carrying over. Its frustrating because I want to continue with this site im just well and truly stuck here.

  4. #19
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,352
    Thanks
    61
    Thanked 528 Times in 515 Posts
    How do you know the session isn't being carried over? - Did you not read my comment previously about you not even using the $_SESSION array? - That is where you store things. In your next script you then call session_start() and the $_SESSION array then contains all the keys and values you used previously in your last script.

    I've not seen you use $_SESSION anywhere so how can you claim it's not working? - Anything you want made available to the next script must be put into the session array like this:

    Script one
    PHP Code:
    session_start();
    $_SESSION['text'] = 'Hello'
    Script two
    PHP Code:
    session_start();
    print 
    $_SESSION['text']; 
    As for your blank page, if you're on wamp then you'll have an apache error log somewhere which will list the error with the page.
    Last edited by tangoforce; 10-04-2012 at 09:59 PM.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  5. #20
    New Coder
    Join Date
    Sep 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Let me see if I understand what you mean. In the past I would have just put the following in my header file.

    $stat = mysql_fetch_array(mysql_query("select * from members where user='$user' and pass='$pass'"));

    The session would of kept that alive and then when I wanted to show someones user name I would of just put $stat[user]. But now I have to use session variables. Is that correct?

  6. #21
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,352
    Thanks
    61
    Thanked 528 Times in 515 Posts
    Quote Originally Posted by Feerick11 View Post
    The session would of kept that alive
    No it wouldn't. $stat would be forgotten as soon as the script ended.

    To use a session, anything you want remembered between scripts must be put into the $_SESSION array. I've made this clear more than once to you yet you seem to do anything but accept it.

    Quote Originally Posted by Feerick11 View Post
    But now I have to use session variables. Is that correct?
    No it's not correct. You've ALWAYS had to use session variables it's just that you have not been doing so. If you go back and read my previous replies you will see I have been telling you this multiple times.

    Normal variables that you use (eg $User or $stat) were never remembered by sessions. They were available in other files that you might include() or require() but not between scripts on different urls and http calls.

    Anything you want remembered between two scripts that are at different urls must go into the $_SESSION array. I've given you a basic code sample above so please use it! It isn't hard, just a call to session_start() in your script and then use the $_SESSION array just like any other array. It's really easy to do
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


 
Page 2 of 2 FirstFirst 12

Posting Permissions

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