SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 48

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Session problems

    I start a session on checklogin.php like this:
    PHP Code:
    session_start();
        
    $data mysql_fetch_array($result);
        
    $_SESSION['uid'] = $data["uid"];
        
    $_SESSION['username'] = $data["username"];
        
    $_SESSION['password'] = $data["userpass"];
        
    $_SESSION['firstname'] = $data["firstname"];
        
    $_SESSION['lastname'] = $data["lastname"]; 
    It is setting them fine, I have checked. checklogin.php then redirects the user to member.php by using a header. In member.php I continue the session like this this:
    PHP Code:
    session_start();
        
    $uid $_SESSION['uid'];
        
    $username $_SESSION['username'];
        
    $password $_SESSION['password'];
        
    $firstname $_SESSION['firstname'];
        
    $lastname $_SESSION['lastname']; 
    But now in member.php the session variables are blank. What am I doing wrong?
    Thanks

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    long shot but, try appending: ?PHPSESSID=$PHPSESSID at the end of the URL in the header command.

  3. #3
    SitePoint Enthusiast poirot's Avatar
    Join Date
    Jun 2006
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your question is strangely familiar.

    Check my answer @ PHPFreaks

    http://www.phpfreaks.com/forums/inde...howtopic=96101

  4. #4
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can only get it to work if I use: ?PHPSESSID=$PHPSESSID method. So it only works if I put the session id the url, is this secure? Why doesn't it work the normal way?

    Thanks

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it sounds like you have output before calling session start, but maybe you dont have error reporting on. whenever your debugging code, you should turn error reporting up, it helps you.

    put this at the very top of your script
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    im thinking your going to get some errors now, post them here.

  6. #6
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get these erros in member.php:
    Code:
    Notice: Undefined index: uid in C:\Program Files\xampp\htdocs\customers\member.php on line 32
    
    Notice: Undefined index: username in C:\Program Files\xampp\htdocs\customers\member.php on line 33
    
    Notice: Undefined index: userpass in C:\Program Files\xampp\htdocs\customers\member.php on line 34
    
    Notice: Undefined index: firstname in C:\Program Files\xampp\htdocs\customers\member.php on line 35
    
    Notice: Undefined index: lastname in C:\Program Files\xampp\htdocs\customers\member.php on line 36

  7. #7
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still can't get these sessions to work without having to put the session ID in the url. How do I get around this.

  8. #8
    SitePoint Zealot
    Join Date
    Feb 2006
    Location
    East Yorkshire, UK
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    on your checkuser.php page have you put the following right at the very top

    PHP Code:

    session_start
    (); 
    I had this problem on my logout.php page .. and it was because i forgot the session_start command.
    I don't have an adictive personality! ,I just can't say no is all

  9. #9
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I have, my code is above.

  10. #10
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    view the http headers your script is sending and see if theres a set cookie header.

    http://web-sniffer.net/

    check your cookies to see if your browser stores the session cookie.

  11. #11
    SitePoint Enthusiast ro88o's Avatar
    Join Date
    Jun 2006
    Location
    Manchester, UK
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Before trying to set $uid etc. what is the result if you do an isset on your $_SESSION variables ?
    www.nubornis.com
    Web Development from Nuborn Internet Services

  12. #12
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ro88o
    Before trying to set $uid etc. what is the result if you do an isset on your $_SESSION variables ?
    they arent set in member.php, thats why he got all those undefined index notices.

  13. #13
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In checklogin.php all the session variables are set correctly and can be displayed.

  14. #14
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes clamcrusher is correct. I want to know why they aren't setting in member.php without having to put the session ID in the url, any ideas?

  15. #15
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes clamcrusher is correct. I want to know why they aren't setting in member.php without having to put the session ID in the url, any ideas?

  16. #16
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you never told us if your script is sending a set cookie header

  17. #17
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no it isn't

  18. #18
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what does this produce?
    PHP Code:
    var_dump(ini_get('session.use_cookies')); 

  19. #19
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What file should I put that line of code in. Anyway I just put it in a new file to try it and I got this:
    Code:
    string(1) "1"

  20. #20
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hm strange.

    make a new blank php file and put this in it.

    PHP Code:
    <?php
    session_start
    ();
    echo 
    '<pre>';
    print_r(apache_response_headers());
    echo ++
    $_SESSION['i'];
    ?>
    everytime you refresh that page it should increment. does it?

    please post the output here.

  21. #21
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The out put is this:
    Code:
    Array
    (
        [X-Powered-By] => PHP/5.1.4
        [Set-Cookie] => PHPSESSID=c6b8d492c4cf056ce06fecd1b6b48f2a; path=/
        [Expires] => Thu, 19 Nov 1981 08:52:00 GMT
        [Cache-Control] => no-store, no-cache, must-revalidate, post-check=0, pre-check=0
        [Pragma] => no-cache
    )
    1
    The only change when I refresh is the session ID changes.

  22. #22
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your browser is not accepting cookies.

    what browser/version are you using?

    did you change any settings which have to do with cookies/security?

  23. #23
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No I haven't. I am using Firefox/1.5.0.4, but it also does not work in IE or opera?

  24. #24
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    make another new file with the following

    PHP Code:
    <?php
    $url 
    'http://yourwebsite.com/that_script.php';
    $fp fopen($url'r');
    echo 
    '<pre>';
    print_r($http_response_header);
    ?>
    replace the url with the full url to the script i had you make in the last post.

    post the results here.

  25. #25
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what I get:
    Code:
    Array
    (
        [0] => HTTP/1.1 200 OK
        [1] => Date: Tue, 20 Jun 2006 17:31:30 GMT
        [2] => Server: Apache/2.2.2 (Win32) DAV/2 mod_ssl/2.2.2 OpenSSL/0.9.8b mod_autoindex_color PHP/5.1.4
        [3] => X-Powered-By: PHP/5.1.4
        [4] => Set-Cookie: PHPSESSID=a7810570575d387be352b5f3131b31f4; path=/
        [5] => Expires: Thu, 19 Nov 1981 08:52:00 GMT
        [6] => Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
        [7] => Pragma: no-cache
        [8] => Content-Length: 278
        [9] => Connection: close
        [10] => Content-Type: text/html
    )
    By the way I am working on this script on localhost with XAMPP, if that makes any difference. I know this script used to work, becasue I had it working before on my old host, then one day it just stopped working.

    Thanks


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
  •