Current location: Hot Scripts Forums » Programming Languages » PHP » Help Please


Help Please

Reply
  #1 (permalink)  
Old 08-09-05, 08:05 PM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
Help Please

ok when I do this and try to login I get nothing.
PHP Code:

<?

include_once('../config.php');

//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
$username $_POST['username'];
$password md5($_POST['password']);

$sql "SELECT * FROM users WHERE username='$username'";
$q mysql_query($sql);
while(
$row mysql_fetch_array($q))
{
    if(
$row['username'] == $username && $row['password'] == $password){
        if(
$row['admin'] == "1"){
        echo 
'<script>
        function put_cookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
        document.cookie = curCookie;
        }

        var now = new Date();
        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
        put_cookie("VDoD_Mem_Data_admin", "true", now, "/", "div.conshosting.net");
        put_cookie("VDoD_Mem_Data_user", "true", now, "/", "div.conshosting.net");
        put_cookie("VDoD_Mem_Data_username", "'
.$username.'", now, "/", "div.conshosting.net");

        window.location="home.php?op=admin";
        </script>'
;
        }elseif(
$row['admin'] != "1"){
        echo 
'<script>
        function put_cookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
        document.cookie = curCookie;
        }

        var now = new Date();
        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

        put_cookie("VDoD_Mem_Data_user", "true", now, "/", "dev.conshosting.net");
        put_cookie("VDoD_Mem_Data_username", "'
.$username.'", now, "/", "dev.conshosting.net");

        window.location="home.php?op=user";
        </script>'
;
        }else{
        }
    }elseif(
$row['username'] != $username && $row['password'] != $password){
    echo 
'<script>
    window.location="../index.php";
    </script>'
;
    }else{
    }
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
Reply With Quote
  #2 (permalink)  
Old 08-09-05, 09:01 PM
Sabu Sabu is offline
Junior Code Guru
 
Join Date: Sep 2004
Posts: 458
Thanks: 0
Thanked 0 Times in 0 Posts
Your problem is here
PHP Code:

}else{

    } 
It's not doing anything because more than likely it's not matching the password. When it doesn't match the password, you're having it.. do nothing.

The two checks you have are 'both match' or 'none match', but remember you specified the username in the sql query so you don't need to check that at all.
Reply With Quote
  #3 (permalink)  
Old 08-09-05, 09:20 PM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
still not working.
PHP Code:

<?

include_once('../config.php');

//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
$username $_POST['username'];
$password md5($_POST['password']);

$sql "SELECT * FROM users WHERE username='$username'";
$q mysql_query($sql);
while(
$row mysql_fetch_array($q))
{
    if(
$row['password'] == $password){
        if(
$row['admin'] == "1"){
        echo 
'<script>
        function put_cookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
        document.cookie = curCookie;
        }

        var now = new Date();
        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
        put_cookie("VDoD_Mem_Data_admin", "true", now, "/", "div.conshosting.net");
        put_cookie("VDoD_Mem_Data_user", "true", now, "/", "div.conshosting.net");
        put_cookie("VDoD_Mem_Data_username", "'
.$username.'", now, "/", "div.conshosting.net");

        window.location="home.php?op=admin";
        </script>'
;
        }else{
        echo 
'<script>
        function put_cookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
        document.cookie = curCookie;
        }

        var now = new Date();
        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

        put_cookie("VDoD_Mem_Data_user", "true", now, "/", "dev.conshosting.net");
        put_cookie("VDoD_Mem_Data_username", "'
.$username.'", now, "/", "dev.conshosting.net");

        window.location="home.php?op=user";
        </script>'
;
        }
    }else{
    echo 
'<script>
    window.location="../index.php";
    </script>'
;
    }
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
?>
Reply With Quote
  #4 (permalink)  
Old 08-09-05, 09:41 PM
Sabu Sabu is offline
Junior Code Guru
 
Join Date: Sep 2004
Posts: 458
Thanks: 0
Thanked 0 Times in 0 Posts
You also haven't got it doing anything if it never found the row with the username in the first place
Reply With Quote
  #5 (permalink)  
Old 08-09-05, 10:04 PM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Sabu
You also haven't got it doing anything if it never found the row with the username in the first place
What do you mean?
Reply With Quote
  #6 (permalink)  
Old 08-10-05, 03:18 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
firstly whats with the
PHP Code:

//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ 

??
also this might be a better solution:
PHP Code:

<?

include_once('../config.php');

$username $_POST['username'];
$password md5($_POST['password']);

$sql "SELECT * FROM users WHERE username='$username' AND password='$password' AND admin='1'";
$q mysql_query($sql);
$check mysql_num_rows($q);

if (
$check == 1) {
setcookie ("VDoD_Mem_Data_admin""true"time()+31536000"/""div.conshosting.net");
setcookie ("VDoD_Mem_Data_user""true"time()+31536000"/""div.conshosting.net");
setcookie ("VDoD_Mem_Data_username"$usernametime()+31536000"/""div.conshosting.net");
header ("Location: home.php?op=admin");
}
else {
$query mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
$check mysql_num_rows($query);

if (
$check == 1) {
setcookie ("VDoD_Mem_Data_user""true"time()+31536000"/""div.conshosting.net");
setcookie ("VDoD_Mem_Data_username"$usernametime()+31536000"/""div.conshosting.net");
header ("Location: home.php?op=user");
}
else {
header ("Location: ../index.php");
}
}
?>
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #7 (permalink)  
Old 08-10-05, 06:28 AM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
Is there something I am missing on that because It doesn't work eather
Reply With Quote
  #8 (permalink)  
Old 08-10-05, 06:57 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, are you sure the username and password are correct?
What is the error message your getting?
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #9 (permalink)  
Old 08-10-05, 07:39 AM
aussietogo aussietogo is offline
Newbie Coder
 
Join Date: Mar 2005
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
What's error message you receive.

also worth to check if your host server turn on the global register on htaccess.




Quote:
Originally Posted by connor
ok when I do this and try to login I get nothing.
PHP Code:

<?

include_once('../config.php');

//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
$username $_POST['username'];
$password md5($_POST['password']);

$sql "SELECT * FROM users WHERE username='$username'";
$q mysql_query($sql);
while(
$row mysql_fetch_array($q))
{
    if(
$row['username'] == $username && $row['password'] == $password){
        if(
$row['admin'] == "1"){
        echo 
'<script>
        function put_cookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
        document.cookie = curCookie;
        }

        var now = new Date();
        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
        put_cookie("VDoD_Mem_Data_admin", "true", now, "/", "div.conshosting.net");
        put_cookie("VDoD_Mem_Data_user", "true", now, "/", "div.conshosting.net");
        put_cookie("VDoD_Mem_Data_username", "'
.$username.'", now, "/", "div.conshosting.net");

        window.location="home.php?op=admin";
        </script>'
;
        }elseif(
$row['admin'] != "1"){
        echo 
'<script>
        function put_cookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
        document.cookie = curCookie;
        }

        var now = new Date();
        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

        put_cookie("VDoD_Mem_Data_user", "true", now, "/", "dev.conshosting.net");
        put_cookie("VDoD_Mem_Data_username", "'
.$username.'", now, "/", "dev.conshosting.net");

        window.location="home.php?op=user";
        </script>'
;
        }else{
        }
    }elseif(
$row['username'] != $username && $row['password'] != $password){
    echo 
'<script>
    window.location="../index.php";
    </script>'
;
    }else{
    }
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
Reply With Quote
  #10 (permalink)  
Old 08-10-05, 04:18 PM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by FiRe
Yes, are you sure the username and password are correct?
What is the error message your getting?
It just redirects me back to the login page.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 07:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.