SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Console Script Displays Wrong username when logged in

    Hi all this is apart of my Console script what it is doing is displaying my username is 1 and not Admin or not What the user has that is comign from hte database.

    this is what i have

    PHP Code:
    <?
    session_start
    ();
    //define $con
    include("dbconnect.php");
    //this is the file that connect to sql
    $s=$_SERVER["REMOTE_ADDR"];
    //draws IP address of visitor
    //error_reporting(E_ALL);
    $iQuery="SELECT * from banip where IP='$s'";
    //$result=mysqli_query($con,);
    $rs=mysqli_query($con,$iQuery);
    //$ipbancheck2=mysqli_query($con,$ipbancheck);
    if(!$rs)
    {
        echo 
    "Error:".mysqli_error($con);
    }
    else
    {
        while(
    $ipbancheck3=mysqli_fetch_array($rs))
        {
        
    $IPBANNED=$ipbancheck3[IP];
        }
            
    //above lines check to see if user Ip is in banned IPs
        
    if ($IPBANNED)
        {
            require(
    "clansettings.php");
            print 
    "<font color=".$fontcolor.">You have been banned</font>";
        }
        else
        {
                    
    $msg_pass="";
                    
    $msg_user="";
                    include(
    "dbconnect.php");
                    if(
    $_SESSION['user'])
                    {
                                    
    $user=TRUE;
                                    include(
    "header.inc.php");
                                    include(
    "dbconnect.php");
                                    
    $gQuery="SELECT * FROM members WHERE username='".$_SESSION['user']."'";
                                    
    //excute the query
                                    
    echo $gQuery;
                                    
    $rs=mysqli_query($con,$gQuery);
                                    if(!
    $rs)
                                    {
                                        
    $dbError="Error:Failed to executing query".mysqli_error($con);
                                    }
                                    else
                                    {
                                        
    $count=$rs->num_rows;
                                        if(
    $count>0)
                                        {
                                            
    $data=$rs->fetch_assoc();
                                            
    $username=$data['username'];
                                            
    $rank=$data['rank'];
                                            
    $email=$data['email'];
                                            
    $aim=$data['aim'];
                                            
    $msn=$data['msn'];
                                            
    $recruitedby=$data['Recruitedby'];
                                            
    $joineddate=$data['joineddate'];
                                            
    $disable=$data['disable'];
                                            
    $logindays=$data['logindays'];
                                            
    $web=$data['web'];
                                        }
                                    }
                                    require(
    "clansettings.php");
                                    echo 
    "<font color=".$fontcolor.">Logged in as".$_SESSION['user']."";
                                    
    $dQuery="SELECT * FROM members WHERE username='".$_SESSION['user']."'";
                                    
    //excute the query
                                    
    $rs=mysqli_query($con,$dQuery);
                                    if(!
    $rs)
                                    {
                                        
    $dbError="Error:Failed to executing query".mysqli_error($con);
                                    }
                                    else
                                    {
                                        
    $count=$rs->num_rows;
                                        if(
    $count>0)
                                        {
                                            
    $data=$rs->fetch_assoc();
                                            
    $username=$data['username'];
                                            
    $rank=$data['rank'];
                                            
    $email=$data['email'];
                                            
    $aim=$data['aim'];
                                            
    $msn=$data['msn'];
                                            
    $recruitedby=$data['Recruitedby'];
                                            
    $joineddate=$data['joineddate'];
                                            
    $disable=$data['disable'];
                                            
    $logindays=$data['logindays'];
                                            
    $web=$data['web'];
                                        }
                                    }
                        if(
    $data['disable']==1)
                        { 
                                    
                                    
    $lQuery="SELECT * FROM members WHERE username='".$_SESSION['user']."'";
                                    
    $rs=mysqli_query($con,$lQuery);
                                    if(!
    $rs)
                                    {
                                        
    $dbError="Error:Failed to executing query".mysqli_error($con);
                                    }
                                    else
                                    {
                                        
    $count=$rs->num_rows;
                                        if(
    $count>0)
                                        {
                                            
    $data=$rs->fetch_assoc();
                                            
    $username=$data['username'];
                                            
    $rank=$data['rank'];
                                            
    $email=$data['email'];
                                            
    $aim=$data['aim'];
                                            
    $msn=$data['msn'];
                                            
    $recruitedby=$data['Recruitedby'];
                                            
    $joineddate=$data['joineddate'];
                                            
    $disable=$data['disable'];
                                            
    $logindays=$data['logindays'];
                                            
    $web=$data['web'];
                                        }
                                    }
                                            
    $rmt $_SERVER["REMOTE_ADDR"];
                                                    if(
    $rmt)
                                                    {
                                                        
    $pQuery="update members SET ips = \"$rmt\" WHERE username='".$_SESSION['user']."'";
                                                        
    $result=mysqli_query($con,$pQuery);
                                                        if(!
    $result)
                                                        {
                                                            echo 
    "<font color=".$fontcolor.">Error:".mysqli_connect_errno();
                                                            echo 
    "<br/><font color=".$fontcolor.">Error2:".mysqli_error($con);
                                                        }
                                                        else
                                                        {
                                                                echo 
    "<font color=".$fontcolor.">Your Ip Address has been Logged!</font>";
                                                        }
                                                    } 
                                echo 
    "<br/><br/>";
                                switch(
    true){
                                case 
    date('G')<13
                                echo 
    "<font color=".$fontcolor." size=\"16px\">Good Morning $username</font>"; break;
                                case 
    date('G')<18: echo "<font color=".$fontcolor." size=\"16px\">Good Afternoon $username</font>"; break;
                                case 
    date('G')<25: echo "<font color=".$fontcolor." size=\"16px\">Good Night $username</font>"; break;
                                }
                                echo 
    "<br/><br/><font color=".$fontcolor.">The Time is:&nbsp;"
                                echo 
    date("g:i a");
                                echo 
    "</font>";
                                
    ?>
                                <table>
                                <tr><font size=\"16px\"></font><td><? echo "<font color=".$fontcolor.">Member";?></font></td>
                                <td><? echo "<font color=".$fontcolor.">".$_SESSION['user']."";?></font></td>
                                </tr>
                                <tr>
                                <td><? echo "<font color=".$fontcolor.">Rank";?></font></td>
                                <td><? echo "<font color=".$fontcolor.">".$data['rank'].""?></font></td>
                                </tr>
                                <tr>
                                <td><? echo "<font color=".$fontcolor.">Email";?></font></td>
                                <td><? echo "<font color=".$fontcolor.">".$data['email']."";?></font></td>
                                </tr>
                                <tr>
                                <td><? echo "<font color=".$fontcolor.">Recruited By:";?></font></td>
                                <td><? echo "<font color=".$fontcolor.">".$data['Recruitedby']."";?></font></td>
                                </tr>
                                <tr>
                                <td><? echo "<font color=".$fontcolor.">Date Joined";?></font></td>
                                <td><? echo "<font color=".$fontcolor.">".$data['joineddate']."";?></font></td>
                                </tr>
                                </table>
                                <fieldset>
                        <?php
                                    
    include("dbconnect.php");
                                    if(
    $data['rank']>=1)
                                    {
                                        echo 
    "<table width=\"390\" border=\"1\" align=\"center\">
                                        <tr>
                                            <th scope=\"col\" colspan=\"2\"><font color="
    .$fontcolor.">Members Console</font></th>
                                          </tr>
                                          <tr>
                                            <th scope=\"col\"><a href=\"logout.php\">logout</a></th>
                                            <th scope=\"col\"><a href=\"consolefeatuture3.php\">Change Pasword</a></th>
                                          </tr>
                                          <tr>
                                            <th scope=\"row\"><a href=\"consolefeatuture16.php\">Clan Chatroom</a></th>
                                            <th><a href=\"consolefeatuture1.php\">Change info</a></th>
                                          </tr>
                                            <tr>
                                            <th scope=\"row\"><a href=\"viewlogs.php\">View Logs</a></th>
                                            <th scope=\"row\"><a href=\"consolefeatuture17.php\">Private Message(s)</a></th>
                                          </tr>
                                        </table>"
    ;
                                    }
                                    if(
    $data['rank']>=9)
                                    {
                                        include(
    "includes/officers.inc.php"); 
                                    }
                                    
    $rQuery="SELECT * FROM members WHERE username='".$_SESSION['user']."'";
                                    
    $rs=mysqli_query($con,$rQuery);
                                    if(!
    $rs)
                                    {
                                        
    $dbError="Error:Failed to executing query".mysqli_error($con);
                                    }
                                    else
                                    {
                                        
    $count=$rs->num_rows;
                                        if(
    $count>0)
                                        {
                                            
    $data=$rs->fetch_assoc();
                                            
    $username=$data['username'];
                                            
    $rank=$data['rank'];
                                            
    $email=$data['email'];
                                            
    $aim=$data['aim'];
                                            
    $msn=$data['msn'];
                                            
    $recruitedby=$data['Recruitedby'];
                                            
    $joineddate=$data['joineddate'];
                                            
    $disable=$data['disable'];
                                            
    $logindays=$data['logindays'];
                                            
    $web=$data['web'];
                                        }
                                    }
                                    if(
    $data['rank']>=20)
                                    {
                                        include(
    "includes/generals.inc.php"); 
                                    }
                                    if(
    $data['rank']>=24)
                                    {
                                        include(
    "includes/commanders.inc.php");
                                    }
                                    
    $raQuery="SELECT * FROM members WHERE username='".$_SESSION['user']."'";
                                    
    $rs=mysqli_query($con,$raQuery);
                                    if(!
    $rs)
                                    {
                                        
    $dbError="Error:Failed to executing query".mysqli_error($con);
                                    }
                                    else
                                    {
                                        
    $count=$rs->num_rows;
                                        if(
    $count>0)
                                        {
                                            
    $data=$rs->fetch_assoc();
                                            
    $username=$data['username'];
                                            
    $rank=$data['rank'];
                                            
    $email=$data['email'];
                                            
    $aim=$data['aim'];
                                            
    $msn=$data['msn'];
                                            
    $recruitedby=$data['Recruitedby'];
                                            
    $joineddate=$data['joineddate'];
                                            
    $disable=$data['disable'];
                                            
    $logindays=$data['logindays'];
                                            
    $web=$data['web'];
                                        }
                                    }
                                    if(
    $data['rank']==25)
                                    {
                                        include(
    "includes/webmaster.inc.php");
                                    }
                                else if(
    $data['web']==1)
                                    {
                                        include(
    "includes/webmaster.inc.php");
                                    }
                                
    ?></table>
                                </fieldset>
                                <iframe src="membernews.php" name="main" width="478" height="450" frameborder=0></iframe>
                                </div><?php
                        
    }
                        if(
    $data['disable']==0)
                        {
                            require(
    "clansettings.php");
                            echo 
    "<font color=".$fontcolor.">Logged in as".$_SESSION['user']."";
                            echo 
    "<font color=".$fontcolor.">You have been disabled.<br/>
                            <a href=\"logout.php\">Logout</a></font>"
    ;
                        }
                    }
                    else
                    {
                        include(
    "header.inc.php");
                        include(
    "login.php");
                        
    //include("includes/footer.inc.php");
                    
    }
                
    ?>
                <?php
        
    }
    }
    ?>
    My Login Code in the file login.php

    PHP Code:
    <?php
        session_start
    ();
        include(
    "dbconnect.php");
        
    $msg_pass="";
        
    $msg_user="";
        if(
    $_POST['username'] && $_POST['password'])
        {    
            
    $username mysqli_real_escape_string($con,stripslashes(trim($_POST['username'])));
            
    $password mysqli_real_escape_string($con,stripslashes(trim($_POST['password']))); 
            
    $cQuery="SELECT * FROM members WHERE username='".$username."' AND Password='".$password."'"
            
    $con;
            
    $rs=mysqli_query($con,$cQuery);
            if(!
    $rs)
            {
                echo 
    "Unable to excute the query:".mysqli_error($con);
            }
            else
            {
                
    $count=mysqli_num_rows($rs);
                    if(
    $count>0)
                    {
                        
    $data=mysqli_fetch_assoc($rs);
                        if(
    $data['password']=$password)
                        {
                            
    $_SESSION['user']=$_POST['username'];
                            require(
    "clansettings.php");
                            echo 
    "<font color=".$fontcolor.">Please Wait while we log you in</font>";
                            echo 
    "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=console.php\">";
                            }
                            else
                            {
                                
    $msg_pass="Wrong Password,Please Try again<br>\n";
                                include(
    "includes/attemptloginfailed.inc.php");
                            }
                        }
                        else
                        {
                            
    $msg_user="Wrong Username,Please Try again<br>\n";
                            include(
    "includes/attemptloginfailed.inc.php");
                        }
                    }
             if(!
    $_SESSION['user'])
             {
                require(
    "clansettings.php");
                include(
    "includes/header.inc.php");?>
                <fieldset>
                <legend><?php  echo "<font color=".$fontcolor.">Please Login</font></legend>";?>
                <form name="login" method="post" action="">
                <?
                    
    echo ($msg_user)?"<br/>".$msg_user."<br/>":"";
                
                echo 
    "<font color=".$fontcolor.">Username:</font>";?><input type="text" name="username" maxlength="14"/><br/>
                <?
                    
    echo($msg_pass)?"<br/>".$msg_pass."<br/>":"";
                
                echo 
    "<font color=".$fontcolor.">Password:</font>";?><input type="password" name="password" maxlength="12"/><br/>
                <input type="submit" name="login" value="login"/>
                </form></fieldset><?php
            
    }
        }
    ?>
    Both work on my localserver but not when i upload to my website. it displays wrong username.

    What am i doing wrong?

  2. #2
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It Logs me in as username 1 when i am suppose to be logining in as username Admin.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why dont you ever make any effort to try to debug your scripts?

    i know i personally have told/shown you how to do it many times, and i know others have as well. should we repeat ourselves over and over?

  4. #4
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i do ive been trying to play around with it trying to fix my script
    even when it works on my localhost but doesnt on my server
    i upload it too my website on justyourhosting.com it seems to completely not work so how do you explain or how can i fix this?


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
  •