dandi8 Posted January 18, 2009 Share Posted January 18, 2009 Hi! I hope this hasn't been answered before, I know I couldn't find it anywhere. But if it has been, sorry. The problem is I'm making a primitive login system based on txt files. It works perfectly on my xampp server but when I try to log in on a 100webspace server, I get this: Warning: fopen(nicklist/Dandi8/info.txt) [function.fopen]: failed to open stream: No such file or directory in /home/www/haloportable.100webspace.net/new/editblog.php on line 47 Warning: fgets(): supplied argument is not a valid stream resource in /home/www/haloportable.100webspace.net/new/editblog.php on line 48 It can't find nicklist/Dandi8/info.txt even though nicklist/dandi8/info.txt exists. I figured the fopen function on the server is somehow case-sensitive, as when I use a lower-case login while registering and then logging in, it works OK. But I want to be able to have a mixed-case nick (like Dandi8 or The_Maw or anything for that matter) and still be able to log in while typing in a lower-case version of it. Here's the part of my code where there are problems, starting from line 46: if (strtoupper($folder) == strtoupper($nick)){ $plik=fopen("nicklist/".$nick."/info.txt", 'r'); $passreal=fgets($plik,40960); So is there a way to make the fopen function case-insensitive? Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/ Share on other sites More sharing options...
Mark Baker Posted January 18, 2009 Share Posted January 18, 2009 If your 100webspace server is running Linux, then it will be case-sensitive. You either have to enforce case-sensitivity in your login system; or read through all the directories available under your nicklist directory (which will retrieve the case-sensitive name), and do a case-insensitive match of each against your value; or you force your directory names to be a consistent case using strtolower() or strtoupper() when you create them, then always force your value to be the same case. What you'd need to watch out for in the second case would be a directory called Dandi8 and another called dandi8: how would you know which was the right one? Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-739687 Share on other sites More sharing options...
dandi8 Posted January 18, 2009 Author Share Posted January 18, 2009 As I said, I want to make FOPEN case-insensitive, not the folder checking. So that's not helping me at all. I need an example of code where FOPEN is made case-insensitive. Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-739766 Share on other sites More sharing options...
Mark Baker Posted January 18, 2009 Share Posted January 18, 2009 As I said, I want to make FOPEN case-insensitive, not the folder checking. So that's not helping me at all. I need an example of code where FOPEN is made case-insensitive. I'll rephrase my previous answer. You can't, not unless you're running your code on an operating platform that isn't case-sensitive Now perhaps you'll consider the alternatives that I suggested Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-739783 Share on other sites More sharing options...
beyzad Posted January 18, 2009 Share Posted January 18, 2009 May be you can create a function that creates from "sample.ext" to "SAMPLE.EXT" an test them 1 by 1. but that's not recommended. Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-739787 Share on other sites More sharing options...
revraz Posted January 18, 2009 Share Posted January 18, 2009 Why don't you just keep all your folder names in lower case and avoid the issue? Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-739816 Share on other sites More sharing options...
dandi8 Posted January 19, 2009 Author Share Posted January 19, 2009 Why don't you just keep all your folder names in lower case and avoid the issue? Because I want to allow users to have their nicknames written with mixed-case letters. I guess I'll just have to stick the nick to my info.txt file... Although I'm SURE there is a way for case-insensitive fopen, there's always a way... Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-740119 Share on other sites More sharing options...
Mark Baker Posted January 19, 2009 Share Posted January 19, 2009 Because I want to allow users to have their nicknames written with mixed-case letters. In which case, you need to ensure that they are consistent when using their nicknames. Otherwise, what do you do when a user decides they want to use the nickname dandi8 instead of Dandi8? Although I'm SURE there is a way for case-insensitive fopen, there's always a way... $nick = 'DaNdI8'; $nicknames = scandir('nicklist'); $found = False; foreach($nicknames as $nickname) { if (strtolower($nickname) == strtolower($nick)) { $found = True; break; } } if ($found) { $plik=fopen("nicklist/".$nickname."/info.txt", 'r'); $passreal=fgets($plik,40960); } Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-740128 Share on other sites More sharing options...
dandi8 Posted January 19, 2009 Author Share Posted January 19, 2009 I think you don't understand, it's: $plik=fopen("nicklist/".$nickname."/info.txt", 'r'); that poses the problem. Or am I interpreting the code wrong? Edit: Oh, wait. I AM interpreting it wrong right? Although you forgot to change $nickname to strtolower($nickname) and that would mean they'd still get lowercase nicknames, just they could log in using whatever they wanted. Or am I STILL thinking wrong? Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-740153 Share on other sites More sharing options...
btherl Posted January 19, 2009 Share Posted January 19, 2009 $nickname comes from the list of actual directories, not from the user's nickname. So it doesn't need further processing before going into fopen(). Mark's initial suggestion is still better though, from the POV of an experienced programmer. Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-740183 Share on other sites More sharing options...
dandi8 Posted January 19, 2009 Author Share Posted January 19, 2009 So basicaly, there is no solution to my "case-insensitive fopen" hopes. I can live with that I guess, I'm gonna find me some good SQL tutorial in a few minutes Extra question: Why is there SQL and MySQL? What's the difference? Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-740351 Share on other sites More sharing options...
Mark Baker Posted January 19, 2009 Share Posted January 19, 2009 Why is there SQL and MySQL? What's the difference? SQL is a generic term (Structured Query Language) which is used to define the queries that are used to access data within a database. MySQL is a specific implementation of a relational database, other examples are MS SQL Server, Oracle, Postgres, Firebird, etc. While all of these allow queries that use the SQL language for creating tables, selecting/inserting/updating/deleting records, etc... the connection to the database differs from one company's database to another... and high-level languages like PHP need an interface to allow them to make that connection and execute queries that has to be written for each different database. Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-740357 Share on other sites More sharing options...
Mark Baker Posted January 19, 2009 Share Posted January 19, 2009 So basicaly, there is no solution to my "case-insensitive fopen" hopes.Correct, there is no solution because there is no problem with the way fopen() works. But problems would arise with the reverse, case-insensitivity on an operating system that is case-sensitive. Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-740358 Share on other sites More sharing options...
dandi8 Posted January 19, 2009 Author Share Posted January 19, 2009 Ok then, let me ask you another question that's a little off-topic: Do you know any good MySQL tutorials (that you know yourself) that a noob like me could use to learn? All I find are some tuts explaining theory, or when it's practice it's all mysql console. I wanna integrate my SQL with PHP to be able to make a good website (I also want to use phpmyadmin to edit the tables) and I can't seem to find any good tutorials around :-( Right now I *think* I set up a sample table and I got to some sample PHP code for pulling up stuff from an SQL db, but it wants a login and a password? What the hell, I didn't set up any passwords for my mysql (I use XAMPP btw.) o.O Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-740376 Share on other sites More sharing options...
trq Posted January 19, 2009 Share Posted January 19, 2009 Theres a good free book in my sig (Hudzilla), it has a chapter devoted to the subject. Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-740386 Share on other sites More sharing options...
revraz Posted January 19, 2009 Share Posted January 19, 2009 Switch to a Windows server. So basicaly, there is no solution to my "case-insensitive fopen" hopes. I can live with that I guess, I'm gonna find me some good SQL tutorial in a few minutes Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-740406 Share on other sites More sharing options...
dandi8 Posted January 20, 2009 Author Share Posted January 20, 2009 I am blind XD It took me 30 seconds to notice "databases" in the book's index. Thanks! It looks like a good read. Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-741115 Share on other sites More sharing options...
dandi8 Posted January 20, 2009 Author Share Posted January 20, 2009 Sorry for the double post but... I Couldn't find the "Edit" button XD Anyways, the e-book is awesome! But I have yet another question - is SQL's case-sensitivity also host-dependent? I would assume no, because that would make the whole database thing very difficult. But if it is, is there a way to enforce case-insensitivity in SQL? Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-741216 Share on other sites More sharing options...
trq Posted January 20, 2009 Share Posted January 20, 2009 is SQL's case-sensitivity also host-dependent? No. Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-741220 Share on other sites More sharing options...
dandi8 Posted January 20, 2009 Author Share Posted January 20, 2009 Thanks guys! I finally wrote my first login system compatible with SMF's member database! AND it has working sessions, too! Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-741597 Share on other sites More sharing options...
btherl Posted January 21, 2009 Share Posted January 21, 2009 Congratulations It's always nice when a program finally works. Link to comment https://forums.phpfreaks.com/topic/141324-case-insensitive-fopen/#findComment-741734 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.