LemonInflux Posted August 30, 2007 Share Posted August 30, 2007 I am making an file uploader, and I have got everything done except the register form. You see, this hoster, unlike other codes, offers users individual galleries and directories so they can organize their own set of images. However, there are 2 problems I need sorting out. Before we begin, here is the code that processes the registration: <?php $username = $_POST['username']; $password = $_POST['password']; $username = strtolower($username); $password = strtolower($password); $all_users = file("user.db.txt"); foreach($all_users as $user_line) { $user_arr = explode(" | ", $user_line); if($user_arr[0] == $username){ echo 'This username has already been taken! <a href="register.php">Try again</a>' } } $File = "user.db.txt"; $Handle = fopen($File, 'a'); $Data = $username; fwrite($Handle, $Data); $Data = ' | '; fwrite($Handle, $Data); $Data = md5($password); fwrite($Handle, $Data); $Data = ' | '; fwrite($Handle, $Data); $Data = "4\n"; fwrite($Handle, $Data); print "You have registered successfully! click <a href=index.htm>here</a> to return to the login screen"; fclose($Handle); mkdir("$username", 0700); ?> So what this basically does is convert their username and password to lowercase, write it to user.db.txt, and create them a directory. Now, the first of my two problems: How do you write to a .php file, not a .txt? I've tried the code above and just replacing .txt with .php, but it doesn't seem to work. The second is, the code isn't functioning because of this code: $all_users = file("user.db.txt"); foreach($all_users as $user_line) { $user_arr = explode(" | ", $user_line); if($user_arr[0] == $username){ echo 'This username has already been taken! <a href="register.php">Try again</a>' } } this was my attempt at a code that would stop users from signing up with someone else's username, thus making it possible for them to access the other user's gallery. So my question is simply, what's wrong with it? NOTE: it is meant to explode ' | ' not '|'. Opinions? Tom. Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/ Share on other sites More sharing options...
LemonInflux Posted August 30, 2007 Author Share Posted August 30, 2007 bump Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-337771 Share on other sites More sharing options...
MadTechie Posted August 30, 2007 Share Posted August 30, 2007 1. its the same as a text file, just need to make it executale 2. if thats codes at fault then wheres the fault /problem? Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-337785 Share on other sites More sharing options...
LemonInflux Posted August 30, 2007 Author Share Posted August 30, 2007 1) CHMOD? It's 777 2) It's in that code, I just don't know where. But it worked fine (apart from the registering already made users issue) before I added it in, and now it doesn't. Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-337788 Share on other sites More sharing options...
ToonMariner Posted August 30, 2007 Share Posted August 30, 2007 make sure you use umask when using chmod Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-337791 Share on other sites More sharing options...
LemonInflux Posted August 30, 2007 Author Share Posted August 30, 2007 it's a windows server, it doesn't use CHMOD o_O Besides, host automatically 777's everything online, linux or windows. Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-337793 Share on other sites More sharing options...
ToonMariner Posted August 30, 2007 Share Posted August 30, 2007 chmod id a php function that works on all platforms - even windows has the permissions system!!!! Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-337796 Share on other sites More sharing options...
LemonInflux Posted August 30, 2007 Author Share Posted August 30, 2007 I'll try it. Any ideas for question 2? Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-337807 Share on other sites More sharing options...
LemonInflux Posted August 30, 2007 Author Share Posted August 30, 2007 It appears I owe you an apology. Strange, everything else auto 777'd o_O. Thanks a bunch So yeah, question 2. <?php $username = $_POST['username']; $password = $_POST['password']; $username = strtolower($username); $password = strtolower($password); $all_users = file("users.db.php"); foreach($all_users as $user_line) { $user_arr = explode(" | ", $user_line); if($user_arr[0] == $username){ echo 'This username has already been taken! <a href="register.php">Try again</a>' } } $File = "users.db.php"; $Handle = fopen($File, 'a'); $Data = $username; fwrite($Handle, $Data); $Data = ' | '; fwrite($Handle, $Data); $Data = md5($password); fwrite($Handle, $Data); $Data = ' | '; fwrite($Handle, $Data); $Data = "4\n"; fwrite($Handle, $Data); print "You have registered successfully! click <a href=index.htm>here</a> to return to the login screen"; fclose($Handle); mkdir("$username", 0700); ?> I think the problem is that $user_line is still undefined. But I can't think how I'd define it o_O how do you say 'array[0] on every line' in PHP? Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-337809 Share on other sites More sharing options...
LemonInflux Posted August 30, 2007 Author Share Posted August 30, 2007 Bump.. Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-337819 Share on other sites More sharing options...
LemonInflux Posted August 30, 2007 Author Share Posted August 30, 2007 And again... Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-337834 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 bump Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338391 Share on other sites More sharing options...
btherl Posted August 31, 2007 Share Posted August 31, 2007 A better topic name might help to bring attention to your questions. As for your question 2, try printout out your variables to check their values. Use var_dump() rather than print if possible, as it is more detailed. In your code there is no need to define $user_line, as it is defined by the foreach loop. Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338394 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 ah, ok. thanks. Trying now. Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338396 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 it didn't work :\ you did mean to just have 'foreach($all_users)', right? Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338398 Share on other sites More sharing options...
darkfreaks Posted August 31, 2007 Share Posted August 31, 2007 look it up on php.net Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338400 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 I did -.- They're not much help though if you want a block of text sorting. I've found them only helpful whilst writing, not checking. But maybe it's just me.. Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338402 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 bump Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338410 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 bump again. Someone must know the answer Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338423 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 *sigh* anyone? Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338440 Share on other sites More sharing options...
MadTechie Posted August 31, 2007 Share Posted August 31, 2007 try reading the logic....! Sighs.. <?php $username = $_POST['username']; $password = $_POST['password']; $username = strtolower($username); $password = strtolower($password); $all_users = file("users.db.php"); $freeuser = true; foreach($all_users as $user_line) { $user_arr = explode(" | ", $user_line); if($user_arr[0] == $username) { echo 'This username has already been taken! <a href="register.php">Try again</a>'; $freeuser = false; break; } } if($freeuser) { $File = "users.db.php"; $Handle = fopen($File, 'a'); $Data = $username; fwrite($Handle, $Data); $Data = ' | '; fwrite($Handle, $Data); $Data = md5($password); fwrite($Handle, $Data); $Data = ' | '; fwrite($Handle, $Data); $Data = "4\n"; fwrite($Handle, $Data); print "You have registered successfully! click <a href=index.htm>here</a> to return to the login screen"; fclose($Handle); mkdir("$username", 0700); } ?> Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338442 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 It worked! Thanks ever so much for your help, there was no way I was going to get that Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338443 Share on other sites More sharing options...
leela Posted August 31, 2007 Share Posted August 31, 2007 Hai ..i really dont know how to post a question.. i am in need of this ...Plz help me 1) How to count the no of downloads of a particular file/doc/image in PHP. Thanks in advance.....Looking for your help Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338460 Share on other sites More sharing options...
MadTechie Posted August 31, 2007 Share Posted August 31, 2007 You need to click new topic from here you would need to create either a FlatFile storage or MySQL to store the downloads MySQL would be better.. please start the new thread.. Link to comment https://forums.phpfreaks.com/topic/67324-solved-2-easyish-questions/#findComment-338486 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.