rofl90 Posted February 17, 2008 Share Posted February 17, 2008 $username = 'charlie, andreas'; As I've written a script of which is a user login, I now have a partner and am having troubles adding him as a user, as I was trying to code it without MySQL for fun.. if not I guess I should get converting it to mysql, it's currently held in variables with a random word md5'd for security. Link to comment https://forums.phpfreaks.com/topic/91554-is-it-possible-to-store-two-things-in-a-variable-eg/ Share on other sites More sharing options...
Chris92 Posted February 17, 2008 Share Posted February 17, 2008 Yes, you can very easily explode that to get it into an array: <?php $username = 'charlie,andreas'; $users = explode(",", $username); print_r($users); //should returrn Array( [0] = charlie [1] = andreas ) ?> Link to comment https://forums.phpfreaks.com/topic/91554-is-it-possible-to-store-two-things-in-a-variable-eg/#findComment-468955 Share on other sites More sharing options...
rofl90 Posted February 17, 2008 Author Share Posted February 17, 2008 Nice - thanks man!! Link to comment https://forums.phpfreaks.com/topic/91554-is-it-possible-to-store-two-things-in-a-variable-eg/#findComment-468969 Share on other sites More sharing options...
rofl90 Posted February 17, 2008 Author Share Posted February 17, 2008 Hmm, doesn't seem to be working it prints the correct array, but it doesn't seem to like it in the usernames. It doesn't let me login with either of the usernames. I basically want it to turn out as $username = 'charlie'; $username = 'andreas'; so when it checks to see if the username entered = the correct username it's identified as == is correct. Just echoing $username returns 'Array' Link to comment https://forums.phpfreaks.com/topic/91554-is-it-possible-to-store-two-things-in-a-variable-eg/#findComment-468974 Share on other sites More sharing options...
Chris92 Posted February 17, 2008 Share Posted February 17, 2008 Yeah, It's an array.. $username['0'] = 'charlie'; $username['1'] = 'andreas'; Link to comment https://forums.phpfreaks.com/topic/91554-is-it-possible-to-store-two-things-in-a-variable-eg/#findComment-468979 Share on other sites More sharing options...
rofl90 Posted February 17, 2008 Author Share Posted February 17, 2008 but my original system only checks $username not $username[0] $username[1] Is there anyway to get around that or do I need to recode my system ;/ lol Link to comment https://forums.phpfreaks.com/topic/91554-is-it-possible-to-store-two-things-in-a-variable-eg/#findComment-468980 Share on other sites More sharing options...
Stooney Posted February 17, 2008 Share Posted February 17, 2008 The most basic work around would probably be this. $username=array('charlie', 'andreas'); then instead of if($input==$username) use if(in_array($input, $username)){ Basically it will check if the user input username is in the array you made. Hope that makes sense. Link to comment https://forums.phpfreaks.com/topic/91554-is-it-possible-to-store-two-things-in-a-variable-eg/#findComment-468990 Share on other sites More sharing options...
rofl90 Posted February 17, 2008 Author Share Posted February 17, 2008 Thanks it worked! Link to comment https://forums.phpfreaks.com/topic/91554-is-it-possible-to-store-two-things-in-a-variable-eg/#findComment-469004 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.