Help Help :-! PHP session warning?

Discussion in 'PHP' started by ccommon26, Jun 14, 2008.

  1. #1
    I'm trying to log into a admin area and after input the right user/pass, I'm getting the followin error message:

    "
    Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0
    "

    Here is the code of the php

    ***********************************
    <? session_start();
    session_register("ADMIN");
    include'../config.php';
    $title="$CONFIG->sitename ADMIN Login ";
    include("$CONFIG->templatedir/header.php");
    if(isset($ADMIN["admin"]["username"])){redirect("adminarea.php","",0);}
    $frm=$HTTP_POST_VARS;;
    if(!$frm){
    $page_content="
    <table width=100% border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"
    bgcolor=white>
    <tr>
    <td ><br><br><table width=\"30%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\" align=center>
    <tr valign=\"top\">
    <td>
    <form name=\"form1\" method=\"post\" action=\"$CONFIG->siteurl/radmin/index.php\">
    <table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" >
    <tr>
    <td>
    <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\" class=\"text\" bgcolor=\"$CONFIG->lightcolor\">
    <tr id=heading>
    <td colspan=\"2\" align=center class=text><strong>ADMIN Login</strong></td>
    </tr>
    <tr>
    <td align=\"right\" class=\"text_mic\">
    <div align=\"right\" class=text>Username:</div>
    </td>
    <td>
    <input type=\"text\" name=\"username\" size=\"10\" maxlength=\"30\" class=\"input\">
    </td>
    </tr>
    <tr>
    <td align=\"right\" class=\"text_mic\">
    <div align=\"right\" class=text>Password:</div>
    </td>
    <td class=\"barreclair\"><span class=\"barreclair\">
    <input type=\"password\" name=\"password\" size=\"10\" maxlength=\"30\" class=\"input\">
    </span></td>
    </tr>
    <tr>
    <td></td>
    <td align=\"center\">
    <input type=\"submit\" name=\"Submit\" value=\"Login\" class=\"button\">
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table><div align=center><a class=link1 href=forgot_password.php>Forgot your password?</a><br><br></div></td>
    </tr>
    </table>";}
    if (match_referer() && isset($frm["username"])) {
    $err=0;
    $msg = "<p class=text align=center>The following error(s) occured:<br><ul class=text>";

    if(!$frm["username"])
    {$err=1;
    $msg.="<li>Please enter the username</li>";
    }
    if(!$frm["password"])
    {$err=1;
    $msg.="<li>Please enter the password</li>";
    }

    $msg.="</ul><br><p class=text align=center>
    Please go <a href=\"javascript:history.back();\" class=link1>Back </a> and correct this.</p>";
    if($err==1)$page_content=$msg;

    }

    function verify_login($username, $password) {
    $q= db_query("
    SELECT username, firstname, lastname, email, lastlogin,last_ip
    FROM users
    WHERE username = '$username' AND password = '$password' and id='1'
    ");

    return db_fetch_array($q);}

    IF($frm["username"]&&$frm["password"]){
    $user = verify_login($frm["username"], $frm["password"]);
    if ($user) {
    $ADMIN["admin"] = $user;
    $ADMIN["ip"] = $REMOTE_ADDR;

    db_query("update users set lastlogin=now(),last_ip='$REMOTE_ADDR' where username='$frm[username]'");
    $goto = $CONFIG->siteurl."/radmin/adminarea.php" ;
    redirect( $goto,"",0);
    die;

    } else {
    $page_content = "<br><br><br><p align=center class=text>Invalid login, please try <a href=\"javascript:history.back();\" class=link1>again</a><br><br><br><br><br><br><br></p>";
    $frm["username"] =$HTTP_POST_VARS["username"];
    }
    }
    include("$CONFIG->templatedir/admin.content.php");
    include("$CONFIG->templatedir/footer.php");?>
    ***********************************

    My hosting provider use PHP 5.xx

    Help! :)


    Thanks in advanced

    <CG>
     
    ccommon26, Jun 14, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Don't use session_register(). Do things like this instead: $_SESSION['ADMIN'] = "whatever"; which will automatically register them. This is what's causing your errors.

    Also, to destroy session vars, do unset($_SESSION['varname'])
     
    zerxer, Jun 14, 2008 IP