Jump to content

case-insensitive fopen?


dandi8

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

$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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.