•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 428,634 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,968 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1346 | Replies: 9 | Solved
![]() |
•
•
Join Date: Sep 2007
Posts: 31
Reputation:
Rep Power: 2
Solved Threads: 1
Below if part of my login script. I am trying to get it to redirect if the users account status is 'not verified' or 'suspended' (not verified is the field 'verified' = 0 and suspended is 'verified' = 2)
I'm sure it could be coded a little more eloquently, but this is what I have...anyone see why its not redirecting for non-verified/suspended users? (It does, however, redirect to the other pages(change.php and my.php) without a problem.)
I'm sure it could be coded a little more eloquently, but this is what I have...anyone see why its not redirecting for non-verified/suspended users? (It does, however, redirect to the other pages(change.php and my.php) without a problem.)
php Syntax (Toggle Plain Text)
$sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); $info = mysql_fetch_array($result, MYSQL_ASSOC); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ if ($info['verified'] == 0) { $url = "notverified.php"; $redirect = "other"; } if ($info['verified'] == 2){ $url = "suspended.php"; $redirect = "other"; } if ($myusername == "10001" && !($redirect == "other")) {$url = "change.php"; } if (!($myusername == "10001") && !($redirect == "other")) {$url = "my.php"; } session_register("myusername"); session_register("mypassword"); }else {$url = "login.php";} echo("<script> <!-- location.replace(\"".$url."\"); --> </script>");
•
•
Join Date: Dec 2007
Posts: 75
Reputation:
Rep Power: 1
Solved Threads: 10
Try this:
$sql="SELECT * FROM users WHERE username='" . $myusername . "' and password='" . $mypassword . "'";
$result=mysql_query($sql);
$info = mysql_fetch_array($result, MYSQL_ASSOC);
// If result matched $myusername and $mypassword, table row must be 1 row
if(count($info)==1){
if ((int)$info['verified'] == 0) {
$url = "notverified.php";
$redirect = "other";
}
elseif ((int)$info['verified'] == 2){
$url = "suspended.php";
$redirect = "other";
}
elseif ($myusername == "10001" && !($redirect == "other"))
{$url = "change.php";
}
elseif (!($myusername == "10001") && !($redirect == "other"))
{$url = "my.php";
}
session_register("myusername");
session_register("mypassword");
}else
{$url = "login.php";}
echo("<script>
<!--
location.replace(\"".$url."\");
-->
</script>");•
•
Join Date: Sep 2007
Posts: 31
Reputation:
Rep Power: 2
Solved Threads: 1
I appreciate the input. Thanks.
Tried it and its a no-go though(it just redirects EVERY user back to the login screen).
In the original code, the records are being retrieved from the database properly as it redirects to the other 2 pages fine(registered user page and the admin page) meaning it validates the login successfuly.
I assume the glitch is somewhere in the "IF" statements...multiple If/Else's give me a headache LOL
Tried it and its a no-go though(it just redirects EVERY user back to the login screen).
In the original code, the records are being retrieved from the database properly as it redirects to the other 2 pages fine(registered user page and the admin page) meaning it validates the login successfuly.
I assume the glitch is somewhere in the "IF" statements...multiple If/Else's give me a headache LOL
Last edited by verbob : Dec 22nd, 2007 at 2:36 pm.
•
•
Join Date: Sep 2007
Posts: 31
Reputation:
Rep Power: 2
Solved Threads: 1
AHA!
This worked though:
This worked though:
php Syntax (Toggle Plain Text)
// username and password sent from signup form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); $redirect = "allowed"; $info = mysql_fetch_array($result, MYSQL_ASSOC); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ switch ($info['verified']){ case 0: $url = "notverified.php"; $redirect = "not_allowed"; break; case 2: $url = "suspended.php"; $redirect = "not_allowed"; break; } if ($redirect == "allowed"){ switch ($myusername){ case '10001': $url = "change.php"; break; default: $url = "my.php"; break; } } session_register("myusername"); session_register("mypassword"); } if (!($count==1)){ $url = "login.php";} echo("<script> <!-- location.replace(\"".$url."\"); --> </script>");
•
•
Join Date: Dec 2007
Posts: 16
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
Although I thought PHP(atleast in newer versions) allowed variables to be defined 'on-the-fly'. (as an example - $url variable is not previously defined)..or perhaps its just tempermental lol
However, you still need to be sure of a variable's scope. Since you are setting the value of $redirect inside an IF statement scope (i.e., between the curly braces {}), the third and fourth IF statement conditions will fail, as they are not in the same scope where $redirect is given a value.
If you define $redirect before the start of your group of IF statements, they will share the same scope, and your code will pass.
From orig. code:
php Syntax (Toggle Plain Text)
if ($info['verified'] == 0) { $url = "notverified.php"; $redirect = "other"; } if ($info['verified'] == 2){ $url = "suspended.php"; $redirect = "other"; } if ($myusername == "10001" && !($redirect == "other")){ $url = "change.php" } if (!($myusername == "10001") && !($redirect == "other")){ $url = "my.php"; }
if ($myusername == "10001" && !($redirect == "other")). Even though you are setting $redirect = "other" above, it is defined in a scope which is unaccessible at this point, and this line fails as a result. In other words, $redirect in this scope is undefined.You can get PHP to tell you when you are using uninitialized variables.
http://ca3.php.net/error_reporting
Hope this clears it up.
•
•
Join Date: Dec 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
hi dont really knw anything abt comps but if u could help me in simple words plz
i triend logging into punjabijanta and i got this
Notice: Undefined variable: sourcedir in /home/.tinkertoy/jatt4chat/punjabijanta.com/index.php on line 49
Warning: require_once(/QueryString.php) [function.require-once]: failed to open stream: No such file or directory in /home/.tinkertoy/jatt4chat/punjabijanta.com/index.php on line 49
Fatal error: require_once() [function.require]: Failed opening required '/QueryString.php' (include_path='.:/usr/local/php5/lib/php:/usr/local/lib/php') in /home/.tinkertoy/jatt4chat/punjabijanta.com/index.php on line 49
plz help
i triend logging into punjabijanta and i got this
Notice: Undefined variable: sourcedir in /home/.tinkertoy/jatt4chat/punjabijanta.com/index.php on line 49
Warning: require_once(/QueryString.php) [function.require-once]: failed to open stream: No such file or directory in /home/.tinkertoy/jatt4chat/punjabijanta.com/index.php on line 49
Fatal error: require_once() [function.require]: Failed opening required '/QueryString.php' (include_path='.:/usr/local/php5/lib/php:/usr/local/lib/php') in /home/.tinkertoy/jatt4chat/punjabijanta.com/index.php on line 49
plz help
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- can not browse using url's only ip's work (Viruses, Spyware and other Nasties)
- PHP Warning: Cannot modify header information - headers already sent by (output ..... (PHP)
- IF Conditions (PHP)
- Php Syntax Error (PHP)
- Concept to fruition - the chronicle of a new site (Growing an Online Community)
- Greeting Your Members & Guests (PHP)
- Need help with craps program (C++)
- Help: Outputting Up and down arrows in C++ (C++)
- RewriteCond and RewriteRule (Linux Servers and Apache)
Other Threads in the PHP Forum
- Previous Thread: formatting textarea text
- Next Thread: Help



Linear Mode