PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 13th, 2005, 01:28 PM
Malek Malek is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 8 Malek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 10 m 18 sec
Reputation Power: 0
What's wrong with this code?

PHP Code:
<?php 
$code1 
file_get_contents("password.php");
 
if (
$pass == $code1) {
print (
"Correct password");
} else {
print (
"Error: Invalid password");
}
?>


I don't understand why this won't work.
I type in the correct password but I only get the "Invalid password" response.

Reply With Quote
  #2  
Old March 13th, 2005, 05:34 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 5
Well, $pass must not equal $code1 -- and I don't mean that as glibly as it sounds. An important step in debugging (and not always an easy one) is narrowing the problem.

So the next thing to do is find out what the values of $pass and $code actually are, because they must not be what you think.

Before your if check, echo $pass and $code and see which one isn't being set correctly. Then we'll know what piece of code to examine.

Reply With Quote
  #3  
Old March 14th, 2005, 04:58 AM
Malek Malek is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 8 Malek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 10 m 18 sec
Reputation Power: 0
Thanks for your reply Madpawn. Ok I echoed $pass and $code1 but they both return the same value "24" (my test password).

The code works when I replace:

PHP Code:
 $code1 file_get_contents("password.php"); 


with:

PHP Code:
 $code1 "24"


I don't understand, it's supposed to work but it doesn't lol.

Reply With Quote
  #4  
Old March 14th, 2005, 10:33 AM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 5
I can't test this, 'coz I'm not on 4.3, but my guess is you're getting a newline or some such character along with your password from file_get_contents. Try

PHP Code:
 $code1 file_get_contents("password.php");  
  
$code1 trim($code1); 


before running it through your if.

Reply With Quote
  #5  
Old March 14th, 2005, 12:36 PM
Malek Malek is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 8 Malek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 10 m 18 sec
Reputation Power: 0
Hey, I tried the trim command you suggested and it WORKS!
Thanks a bunch Madpawn.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > What's wrong with this code?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT