Welcome Guest ( Log In | Register )



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Small And Big Characters (a & A)
Feelay
post Mar 2 2008, 11:14 AM
Post #1


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



Hey!

Is there anyway to make the following:
Mysql don't care if the users character is small or big.


If I type Feelay instead of feelay, in my message when I want to write to myself, mysql thinks that I wrote to someone else.
I want to be able to write both Feelay and feelay and send to the same user. Is that possible?

This is the code I am using atm:

CODE
/*if($user['to_user'] != $userfinal){
die("You are trying to view another users posts! Thats impossible!");
}*/


(I have made it as a comment, because it is unusable atm).

This post has been edited by Feelay: Mar 2 2008, 11:16 AM
Go to the top of the page
 
+Quote Post
pyost
post Mar 2 2008, 11:40 AM
Post #2


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,013
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



Just convert both $user['to_user'] and $userfinal to lowercase with the strtolower() function smile.gif
Go to the top of the page
 
+Quote Post
Mordent
post Mar 2 2008, 11:43 AM
Post #3


Premium Member
Group Icon

Group: [HOSTED]
Posts: 231
Joined: 30-June 07
Member No.: 23,045



I'd say it's something to do with the character collation. From the little I know about SQL databases, some are case sensitive (the problem I think you're having) and others are case insensitive. In phpMyAdmin you can look at the collation there, and it should be one that has "_ci" (case-insensitive) on the end. Hopefully I'm not talking complete garbage and this'll help solve your problem. wink.gif

EDIT:
QUOTE(pyost @ Mar 2 2008, 11:40 AM) *
Just convert both $user['to_user'] and $userfinal to lowercase with the strtolower() function smile.gif

Or you could do what the guy who beat me to the reply said. wink.gif
After thinking about it, I'd say that one's got the disadvantage of thinking two people with differently capitalised names are the same person, but then again so would altering the case-sensitivity of the database, and you probably wouldn't want two users to have the same username except for capitalisation anyway...

This post has been edited by Mordent: Mar 2 2008, 11:46 AM
Go to the top of the page
 
+Quote Post
sparkx
post Mar 2 2008, 02:53 PM
Post #4


Sparkx
Group Icon

Group: [HOSTED]
Posts: 353
Joined: 11-October 06
From: Dana Point, CA, USA
Member No.: 16,496



I agree with Pyost. The only way to really do that is to make both lowercase before checking it. On my website I do this with both my username and password field (because md5 is changed completely on case).

As for a reply to Mordent, you could simply put all of your letters into lowercase before you insert them into the database, then when you take them out just ucfirst() and be done. However if someone wants to have caps in their name such as: JohnD it would look like Johnd (which might annoy the user).
Two ways around this (and possibly a three):
1: Slow but more secure. If you run a while MySql array for each user and strtolower on each name and check it when someone registers you can make sure there are no two users with the same name. This can be slow however if you have more then about 500 users.
2: Fast but insecure. You insert two fields into MySql one with actual name and one with lowercase name then just check the lowercase one on register. However if you want to make it so users can change their name you need to remember to update both fields in the database or you will have some serious problems.
3: Not sure but I think you can make MySql be case insensitive similar to str_replace and str_ireplace. If so just do a normal check.

Back to freelay...
Your if is quite simple to fix just type in strtolower() around both $user['to_user'] and $userfinal.
Example (unchecked)
CODE
/*if(strtolower($user['to_user']) != strtolower($userfinal)){
die("You are trying to view another users posts! Thats impossible!");
}*/


Thanks,
Sparkx
Go to the top of the page
 
+Quote Post
Feelay
post Mar 2 2008, 09:02 PM
Post #5


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



Isn't there any solution that is 50% fast, and 50% secure tongue.gif? And 100% easy tongue.gif

The thing sparkx said is right.. because maybe a user would like to be named "JohnnyD" or whatever..

This post has been edited by Feelay: Mar 2 2008, 09:03 PM
Go to the top of the page
 
+Quote Post
TavoxPeru
post Mar 3 2008, 06:10 PM
Post #6


Super Member
Group Icon

Group: [HOSTED]
Posts: 760
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



QUOTE(Feelay @ Mar 2 2008, 06:14 AM) *
Hey!

Is there anyway to make the following:
Mysql don't care if the users character is small or big.


If I type Feelay instead of feelay, in my message when I want to write to myself, mysql thinks that I wrote to someone else.
I want to be able to write both Feelay and feelay and send to the same user. Is that possible?

This is the code I am using atm:

CODE
/*if($user['to_user'] != $userfinal){
die("You are trying to view another users posts! Thats impossible!");
}*/


(I have made it as a comment, because it is unusable atm).

Yes it is possible, the most simple way is to change the character collation of your string fields, your table and database to be case insensitive, for example the following sql code use for all character fields and for the table itself to be latin general case insensitive:
CODE
CREATE TABLE `his_postlistermain` (
  `id_his` smallint(5) unsigned NOT NULL auto_increment,
  `sender` varchar(100) collate latin1_general_ci default NULL,
  `subject` varchar(100) collate latin1_general_ci default NULL,
  `message` text collate latin1_general_ci,
  PRIMARY KEY  (`id_his`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

Best regards,
Go to the top of the page
 
+Quote Post
Feelay
post Mar 5 2008, 04:01 PM
Post #7


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



I have tryed that mysql case instasetive thing. but it is still not working :S
this is the if-statement I am using:

CODE
if($userfinal == $user['to_user']){

I have also tryed:
CODE
if($userfinal = $user['to_user']){

But then, nothing happened. It didn't block the user from viewing someone elses posts.
Go to the top of the page
 
+Quote Post
Mordent
post Mar 5 2008, 05:26 PM
Post #8


Premium Member
Group Icon

Group: [HOSTED]
Posts: 231
Joined: 30-June 07
Member No.: 23,045



QUOTE(Feelay @ Mar 5 2008, 04:01 PM) *
I have tryed that mysql case instasetive thing. but it is still not working :S
this is the if-statement I am using:

CODE
if($userfinal == $user['to_user']){

I have also tryed:
CODE
if($userfinal = $user['to_user']){

But then, nothing happened. It didn't block the user from viewing someone elses posts.

Pass as to why the first one doesn't work, but the second is because "=" isn't a way of comparing two variables. It sets the first one ("$userfinal") to the second ("$user['to_user']"), which then comes back as "true" (or so I believe), so it carries on with the code you've put in the brackets. The first code segment - with the "==" in it - is the correct syntax, so it's something to do with another aspect of the code. As I'm not exactly a veteran PHP programmer, I suppose I'll let someone else field the rest of this one. wink.gif
Go to the top of the page
 
+Quote Post
TavoxPeru
post Mar 6 2008, 03:55 AM
Post #9


Super Member
Group Icon

Group: [HOSTED]
Posts: 760
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



QUOTE(Feelay @ Mar 5 2008, 11:01 AM) *
I have tryed that mysql case instasetive thing. but it is still not working :S
this is the if-statement I am using:

CODE
if($userfinal == $user['to_user']){

I have also tryed:
CODE
if($userfinal = $user['to_user']){

But then, nothing happened. It didn't block the user from viewing someone elses posts.

I'm a little confuse now because from your first post:
QUOTE
I want to be able to write both Feelay and feelay and send to the same user. Is that possible?
This is the code I am using atm:
CODE
/*if($user['to_user']!= $userfinal){
die("You are trying to view another users posts! Thats impossible!");
}*/

So, if you want that in the case that
  1. Your table and fields are case insensitive if you write Feelay, FEELAY, FeELAy or whatever, all of them always will be evaluated as the same thing.
  2. Your table and fields are case sensitive if you write Feelay, FEELAY, FeELAy or whatever, all of them always will be evaluated as different things.
The code:
  1. CODE
    if( $userfinal != $user['to_user']){
    Always will be FALSE.
  2. CODE
    if($userfinal != $user['to_user']){
    Always will be TRUE.
And the post made by Mordent is correct, you miss one equal sign in your code.

Best regards,
Go to the top of the page
 
+Quote Post
Feelay
post Mar 6 2008, 05:19 PM
Post #10


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



I have tried all theese stuff.

!=, ==, =. None of them works.

And Between tongue.gif When i used the !=, the code was like this tongue.gif

CODE
if($userfinal != $user['to_user']){
echo "error.. or whatever";
}else{
blabla
}


But as I said. none of them works :S

And btw. I am trying to make Them _ic.. but they still don't work. they are _ic already..

This post has been edited by Feelay: Mar 6 2008, 05:22 PM
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Displaying Hebrew Characters In PHP(3)


 



- Lo-Fi Version Time is now: 8th October 2008 - 05:00 AM