Nexy Posted July 1, 2008 Share Posted July 1, 2008 Why Hello There! Just wondering on how to do this: How do I check if a number inside an if statement == a certain number and if it does: make it sha1(number). I have these if statements around several pages, so I was wondering if I could do it this way instead of writing sha1(number) everywhere. Example: if($_SESSION['id'] == 495) I want some code to catch that 495 and turn it into: if($_SESSION['id'] == sha1(495)) Any help would be appreciated! Thank You!! Link to comment https://forums.phpfreaks.com/topic/112781-convert-a-number-to-sha1-in-if-statement/ Share on other sites More sharing options...
Jabop Posted July 1, 2008 Share Posted July 1, 2008 You seem to know the proper way to do this. If you want to sha1() something, sha1() is going to have to be everywhere you want it to be done. Link to comment https://forums.phpfreaks.com/topic/112781-convert-a-number-to-sha1-in-if-statement/#findComment-579220 Share on other sites More sharing options...
LooieENG Posted July 1, 2008 Share Posted July 1, 2008 <?php if ( $_SESSION['id'] == 495 ) { $_SESSION['id'] = sha1($_SESSION['id']); } ?> Dunno if that's right, I don't understand what you mean ??? Link to comment https://forums.phpfreaks.com/topic/112781-convert-a-number-to-sha1-in-if-statement/#findComment-579225 Share on other sites More sharing options...
Wuhtzu Posted July 1, 2008 Share Posted July 1, 2008 You will need your "certain number" to be a variable <?php $number = 495; if($_session['id'] == $number) { // Make the sha1 hash $hash = sha1($number); // Or run the other if statement, I'm not sure what you wanna do ? if($_session['id'] == sha1($number)) { // Do something else } } ?> Link to comment https://forums.phpfreaks.com/topic/112781-convert-a-number-to-sha1-in-if-statement/#findComment-579227 Share on other sites More sharing options...
Nexy Posted July 1, 2008 Author Share Posted July 1, 2008 I'm using this for moderation levels, since I use cookies and sessions, I made random numbers to represent a certain level. Since I also use cookies, I didn't want anyone changing the value so easily. Basically, I have 4 diff random numbers and I sha1 them at the creation once the user logs in. On different pages I have something like: if($_SESSION['id'] == 658 || $_COOKIE['id'] == 658), depending if they are using cookies or not. I'll try those 2 ways. Thank You! Link to comment https://forums.phpfreaks.com/topic/112781-convert-a-number-to-sha1-in-if-statement/#findComment-579228 Share on other sites More sharing options...
Nexy Posted July 1, 2008 Author Share Posted July 1, 2008 None of those 2 ways worked Maybe Jabop is right D:!! Link to comment https://forums.phpfreaks.com/topic/112781-convert-a-number-to-sha1-in-if-statement/#findComment-579234 Share on other sites More sharing options...
Wuhtzu Posted July 1, 2008 Share Posted July 1, 2008 None of the two ways worked because we don't know what "works" is... you need to be more specific Link to comment https://forums.phpfreaks.com/topic/112781-convert-a-number-to-sha1-in-if-statement/#findComment-579255 Share on other sites More sharing options...
Nexy Posted July 1, 2008 Author Share Posted July 1, 2008 Well, with your way, could a hacker manipulate the variables? As in change them? If I had: $member = sha1(392); $admin = sha1(333); if($_SESSION['id'] == $member) Could a hacker be able to change the variables? If so, any way to protect from that? Thank You! Link to comment https://forums.phpfreaks.com/topic/112781-convert-a-number-to-sha1-in-if-statement/#findComment-579562 Share on other sites More sharing options...
LooieENG Posted July 1, 2008 Share Posted July 1, 2008 You can't change sessions client-side as far as I know Link to comment https://forums.phpfreaks.com/topic/112781-convert-a-number-to-sha1-in-if-statement/#findComment-579652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.