dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: php and sessions

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    171
    Hello,
    Having a few problems with sessions. For some reason on one computer it works and on another it doesn't...that is when i try to login.
    When it doesn't work it stays on the form page upon submitting.
    Does anyone have any advice or suggestions...do i need to use session_destroy????
    This is the script for the form:
    Code:
    <FORM METHOD="POST" ACTION="validate.php">
    <TABLE BORDER="0" WIDTH="350" CELLSPACING="0" BGCOLOR="#FF9900">
    <TR>
    <TD WIDTH="100%">
    <TABLE BORDER="0" WIDTH="350" BGCOLOR="#003366" CELLSPACING="0" CELLPADDING="5">
    <TR>
    <TD WIDTH="50%" ALIGN="right"><FONT COLOR="#FFFFFF">Login</FONT></TD>
    <TD WIDTH="50%"><INPUT NAME="userid" TYPE="text" id="userid" SIZE="31"></TD>
    </TR>
    <TR>
    <TD WIDTH="50%" ALIGN="right"><FONT COLOR="#FFFFFF">Password</FONT></TD>
    <TD WIDTH="50%"><INPUT TYPE="password" NAME="password" SIZE="31"></TD>
    </TR>
    <TR>
    <TD WIDTH="100%" ALIGN="right" COLSPAN="2">
    <P ALIGN="center"><INPUT TYPE="submit" VALUE=" Login "></TD>
    </TR>
    </TABLE>
    </FORM>
    The validate.php page looks like the following:
    Code:
    <?
    session_start();
    
    if ($userid && $password)
    {
     // if the user has just tried to log in
     
     mysql_connect('localhost', 'user', 'pass');
    
     mysql_select_db("resinet");
     $query = "SELECT * FROM admin WHERE login_name='$userid' AND password='$password'";
     $result = mysql_query($query);
     if (mysql_num_rows($result) >0 )
     {
       // if they are in the database register the user id
       $user = mysql_fetch_array($result);
       session_register("valid_user");
       $valid_user = $user["member_id"]; 
       
       
     }
    }
    
     if (session_is_registered("valid_user"))
     {
       // logged in successfully to membership area
       header ("Location: intranet.php"); 
    
    
     
      
     }
     else
     {
       if (isset($userid))
       {
         // if they've tried and failed to log in
    	 header ("Location: warning.php");
       }
       else
       {
         // they have not tried to log in yet or have logged out
    	header ("Location: warning.php");
     
    	 
       }
     
      }
    ?>
    ...and the intranet.php is:
    Code:
    <?
    session_start();
    //check session variable
      
     if (session_is_registered("valid_user"))
      {
    
    ?>
    
    Contents of page here.....
    
    <?
    }
     else
      {
        // You are not logged in.
        //Only logged in members may see this page.    
        require("login.htm");
     }
      
      
    ?>

  2. #2
    Junior Member
    Join Date
    Sep 2002
    Posts
    28
    check my good simple login @

    http://members.lycos.nl/phpfreak

  3. #3
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    your script starts with
    if($userid ....)
    Are you sure that the script is running on php 4.0 or with register_globals enabled on this system?

    Musicman

  4. #4
    Junior Member
    Join Date
    Sep 2002
    Posts
    28
    ifnot $_SESSION instead of session_register, that's all you need to know

    and for commandline things $strings that come from .php?blaat=bla etc you need to change to $_GET['']

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

HTML5 Development Center