Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Case Sensitive Comparisons With Strcmp?


I've written a mod for phpBB to give the forum admin more control over
the smilies. Part of the mod checks to make sure that no two smilies
have the same code.

code = :), :-), :D, :P, :lol:, :happy:, etc.

For some reason my mySQL code is finding a match between :D and :d, :P
and :p, :cool: and :COOL:, etc. Other than that it works fine.

$sql = "SELECT smilies_id FROM " . SMILIES_TABLE . " WHERE
smilies_id!='" . $smilies_id . "' AND code=STRCMP(code, '" .
addslashes($code) . "')";

I've just noticed that I can get around this (sort of) by comparing the
filenames as well, ie. :D and :d would be linked to the same smiley.
But I'd still like to know why STRCMP (which is case sensitive) is
finding a match between D and d.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Case Sensitive, Case Sensitivity, $_GET
IF, inside the address-bar, the link appears as:
index.php?CITY=Raleigh+NC
or
index.php?City=Raleigh+NC

$_GET['city'] displays behaves like a stubborn mule and refuses
to get the get and returns empty ("").

Is there a way to turn off the case sensitivity ?

Non Case Sensitive?
i was wondering how i would go about making something non-case sensitive i have a users column in a database which i don't want to be case sensitive..... becuase if people log-in and use some silly capslock it messes the whole thing up.

PHP Case Sensitive
How to set the case sensitive problem in PHP? for example, the data already have jim (j in small capital letter), we cannot have another Jim (J in big capital letter) so that no duplicate data can be created, any idea? I want to detect the J to be same as j.

Glob() Is Case Sensitive
I have a search script on my site that uses glob(), how can I make it
NON-Case Sensitive?

Pls Help A Greenhorn With Not Case Sensitive
I have this:
preg_match('#^(ab[0-9]+)(?:/([0-9]+))*$#', $_SERVER['QUERY_STRING'],
$matches);

And this seems to only work with queries containing 'ab' lower case, I need
it to allow for 'AB' as well.
I'd be greatful if someone could offer a solution to this.

Case Sensitive Issue!?
I am creating a very simple site to be able to sell just one product.  On the checkout screen I have a input box for the user to be able to enter any promotional code they may have been given.  The user can recalculate their purchase total using the entered code but at present when the script checks the code it is comparing it case sensitively but I want it to be case insensitive.

I am using:

if ($entered_code == $required_code) {...

How can I can alter this so that it is not checking the case of the letters entered?

Php Ignore Case Sensitive
is there a way to make php ignore case? my thumbnails names are lowercase, and my main images name are uppercase,

Case Sensitive Comparison
I designed a login form and when the user logs in with his username and password I want to make sure that they are identical to the ones in the database (case sensitive), so I tried this code but it did not work; if you login with (jack) or (JACK) both are accepted. Code:

Case Sensitive Strpos
Im searchina string for the characters ' PIN='. It works and pulls up the what I have searched for.

The only problem is that it is also pulling up ' pin=' -notice the non caps

Why is this? Can I force the function to be case sensitive?

$findme22 = ' PIN=';
$pinfinder = strpos($line, $findme22);

Case Sensitive Linux And Windows.
I have 2 php setup, one 'live' and one windows for testing.
But as you no windows is not case sensitive, whereas Linux is.

Is there a way, (apart from switching to Linux), that i could set windows to
be a bit more strict?

Sometimes when developing i forget and only realize when i run the install.

How Can I Access A Case Sensitive Host Name?
Is there a way to echo back a case sensitive $HTTP_HOST in PHP? For
example if I type HostName.domain.com in my browser I want to return it
exactly as it appears in the location part of the browser
"HostName.domain.com" but it keeps returning a case insensitive result
"hostname.domain.com".

Login Case Sensitive Issue
My problem is that with this simple Login script, username seems to be case sensitive.....and consequently would give lots of problems for users. So, I want the search of the DB to case insensitive. I am currently using LDAP authentication, but I need to return to Mysql authentication for a short while. Here's the code:

Case Sensitive Database Lookup
my script uses this code to check if a user name exist, how would I make it case sensitive, so John and JOHN will be check as well as any variations?

//username exists?
$result = sql_query("SELECT `m_user` FROM $membtable WHERE m_user='{$en['user']}'");
        if (sql_num_rows($result) > 0) $err .= _reg_member_exists.'<br>';

Is Php Case Sensitive With Functions/classes
I was just wondering because i have in the past done $db->getall() where it really is $db->getAll(); but get not error.  I just want to know because i want to include a different database class that i have created that has some more functionality than the current database class and the current database class is named Database and mine is named database, would that cause a conflict?

Performance Comparisons?
Has anyone done any performance comparisons between what one might
call the 'program' vs 'interjection' models?

What I'm calling the 'program' model is putting a '<?php' invocation
at the top of the page, a '?>' exit at the bottom, and doing all the
html output via echo statements.

The 'interjection' model, in contrast, repeatedly invokes php for
minimal periods instead, so instead of one mass of php code, the same
amount of code is in smaller pieces and laced in and out of the html.

The interpreter must look at everything regardless, but I'm wondering
whether there's significantly more overhead one way than the other.
From the fact that 'echo' isn't actually a function, my guess is that
the overhead might be a wash, but does anyone know of any actual
performance tests?

Ping Comparisons
I would love to compare two servers (or more) and have my script decide which one is working best, then pass that to my video player so it knows which one to use. Pinging makes sense in this. However, the only way I see to do it is with the system command, and I can't figure out how to get a usable result from this instead of a printed output.

Besides continuing to mess with that, any other way to accomplish the same thing (mirror comparisons) would be nice. Or suggestions on a low priced, reliable, somewhat fast server to host these videos on, which would probably be better.

Coding Tip To Prevent Comparisons Becoming Assignments
This is a simple coding tip I learned to prevent comparisons from becoming
assignments (and this becoming a hair-pulling session during debugging):

in comparisons, try to put your constants on the left hand side of the
operator and variables on the right hand side.
example
if (3==$x) {
//do something
}

if ($x=3) {
//do something
}
if this were intended as a comparison, it would never be flagged as an error
by the interpreter or compiler (in PHP's case, interpreter).
With this line, I missed an = and the interpreter won't complain. it simply
assigns 3 to $x and does something every time. With the top line, you can
fix your code quickly because of the error message generated if you miss an
=.
Consider it a good coding habit? Then again there are books on this (if
they are still published).

Strcmp Problem
I done a program to read text file, where content is

#Header#
name: Juicy
age: 25
@Header@
#Text#
user text here
@Text@
#End#
tel
fax
@End@
eof

And I read the text file

$filename = "/usr/local/file/rpt.txt";
$fp = fopen($filename, 'r');

$content = fgets($fp);
while(strcmp($content,"@End@")<>0) {

$content = fgets($fp);

if(strcmp($content, "#Text#")==0){ //not match
$strPretext .= $content;
}//end if
//end while


I should get the data from #Text# until one line before @End@, but I get
nothing, I found that the strcmp for #Text# always not match when it read
through whole file.

Strcmp Vs Equal
I noticed in some examples to the encrypt functions of the PHP manual a
syntax was used for password checks such as

if (strcmp($userpassword, md5($_POST['password'])) == 0) {
// do login
}

What is the advantage of this compared to

if ($userpassword == md5($_POST['password'])) {
// do login
}

?

Use Strcmp To Edit A Dynamically Generated Dropdown...
I've written a code that runs a 'SHOW DATABASES' query on my mysql server and lists the results(the names of the databases on my server) in a dynamically generated dropdown box, and it works just fine, using the following code:

echo "<select name='databaseselect'>";
$dblist = mysql_query('SHOW DATABASES');
while ($row = mysql_fetch_row($dblist)) {
echo "<option value='$row2[0]'>$row2[0]</option>";
}
echo "</select>";

The problem is that it lists ALL of the databases on my server - that's two of my own user-created databases, and the two default databases that come with the mysql server - 'information_schema' and 'mysql'.  What I want to do is to, after running the 'SHOW DATABASES' query, eliminate those two databases from appearing in the dropdown box, because I don't want anyone to see them, as they're useless to anybody else. Code:

Question On Using "strcmp" To Compare Unicode Strings
I am confused by the rule of comparing two unicode string using
function "strcmp". For exmaple, using "strcmp" to compare two Chinese uincode string, depending on what rule can "PHP" decide one string is greater or less
than the other string?

Proper Way Of Sending Sensitive Info
Since the info pool in PHP/mysql areas are so big I feel really lost. If anybody can give me some hint what is THE PROPER way of sending sensitive info using PHP from user side form to server side mySQL. Is there any way we can use secure channels and how. How to use the power of 128 bit encryption/decryption siting in the user browser to send for example credit card info. Or patient info.

Passing Sensitive Information Using GET Or POST
Basically, we have two websites which I need to pass information securely from one to the other.  It is basically, login parameters and then conduct a search.  I do not need to create a web service or any type of middleware solution at this time, I just need a quick and secure method of passing username/pass and the search parameters.  I read a nice article (although old) that stated I could pass the data as follows, in either a cookie or a form variable.

$encrypteddata = mcrypt_ecb(MCRYPT_TripleDES, "Secret key", serialize($data), MCRYPT_ENCRYPT);
$encrypteddata = bin2hex($encrypteddata);

$encrypteddata = hex2bin($encrypteddata);
$data = unserialize(mcrypt_ecb(MCRYPT_TripleDES, "Secret key”,$encrypteddata, MCRYPT_DECRYPT));

(And yes, I do realize the mcrypt_ecb function is depreciated)

However, I believe that with this solution, if I pass it in the URL, I could potentially use up the 2,000+ character limit. My question is, is there a better way to do this?  Or different approach I could use?

PHP/MySQL Encryption/protection Of Sensitive Info
I'm currently working on a new site that encompasses the registration
of members. The registration is taking place through PHP interaction
with MySQL. The site is just going to be for my friends and I, but I
have run into an issue that I have often wondered about before. Any
insight would be appreciated.

The database contains semi-sensitive information. Not CC numbers, but
think more like usernames/passwords to other sites. I've done sites
before in which I would create user accounts/passwords. In that case,
I would just to straight encryption, and then decipher the input
password against the db encrypted one to verify login credentials. No
problem. But, what about the case in which my underlying programs
will need to use the usernames/passwords that are in the database
(exactly as they appear) to POST logins to other sites using that
information?

Ideally, I want to keep the info as secure and protected as possible
in the database. I can't really encrypt() the passwords because I
need to decrypt them again in order to POST them on respective sites
for respective users. I don't think that's how it works when you
encrypt since the idea is not to be able to decrypt with ease.

Do I need to write my own encryption function? The idea of storing
unencrypted semi-sensitive information makes both me and my friends
nervous.

Any thoughts on how to tackle this?

Sending Sensitive Information To An HTTPS Page
I am trying to emulate sort of a Payment Gateway.
A user makes an order and then when he checks out he gets transfered
to the HTTPS page to enter his details.

At the moment I am storing the order in a temporary cart DB Table and
as a reference I use the Customer's ID
so I have

TABLE
Order_Temp
customerId | orderDateTime | ItemID

Once the order gets stored I redirect them using
header('Location:https://'.$url);
Now I have to pass some how in the HTTPS page the reference for the
order so my $url looks like:
https://www.paymentgateway.com/chec...?customerId=123

The problem with that is that I expose the Customer Id wich can easily
be changed to anything else.

What alternatives do i have ?
I though using post might be a sollution, BUT is it safe ? Can you
fake an id of a user when you post a form by injecting code? And how
easy is that ?

I was thinking of storing in the Temp_Order table the session_id and
then passing it thru the URL ? Is that safe ?

I just want to know if there is a standard practice of doing something
like that.

Thank you, and I really appreciate anyones times that is spend reading
my post :)

Case Statements
I am fairly new to php and I was wondering if there was something similar to case statements in C++.

It would be a lot easier than writing about 20 if statements.

Lower Case?
Is lc($var) available in PHP?

Unexpected T CASE
I converted an ASP script using the ASP Translator that I found on the web. Of course it couldn't be that easy (copy, paste and press a button). The PHP script doesn't work.

I'm know a little php but not enough to figure out why I get this error message.

Parse error: syntax error, unexpected T_CASE in /home/slnlibrary/public_html/scripts/Search.php on line 8

Case Syntax
I've no Mysql NG access from my ISP, so let me ask here.

I've a case statement in mysql.

Here is the code:

select ....,
case myvalue
when 'X' then valueX
when 'Y' then valueY
when 'A' then valueY
when 'B' then valueY

In my case, Y,A and B gave the same value.

I'm trying to do something like:

case myvalue
when 'X' then valueX
when in('Y','A','B') then valueY

But I can't get it to work with IN statement. What's the syntax ?

Switch My Case
I haven't used switch before, so I thought I'd give it a go. But I ran into some trouble. The case is like this: I have a search results page where, depending on the no of hits, different texts should be printed. Perfect for switch I thought, but I need to use a different range for each case.

Some code:
// connect and query code not included...
$numrows=mysql_num_rows($result);

switch ($numrows) {
case $numrows==0:
$traff='Do it again...'
break;
case $numrows==1:
$traff='Great!!'
break;
case $numrows<=25:
$traff='Should be here somewhere...'
break;
case $numrows<=50:
$traff='a little too many...'
break;
case $numrows>51:
$traff='Whoa!!!'
break;
default:
$traff='OK!'}

echo "$numrows $traff"; So I always know how many hits I get and this works except when I get no hits. The value of $numrows shows 0, but $traff shows 'Great!!'Why? Or am I doing this wrong?

Change Case
I want to change the case of the first letter in a word. How would i do this via php? I've looked through the php manual and even searched this forum and i have come up with nothing. I'm sure there's a function.

$_GET And Case.
I want to allow users to get the article directly by inserting the announce
ID on the URL such
www.mysite.com?AnnID=xxx
where xxx is the code of the announce.

The problem is :
$_GET['AnnID']

if the user uses lowercase:
www.mysite.com?annid=xxx

It's there any way to get the AnnID, annid, ANNID, and so on ? without
testing everything ?

Using The Case Switch
What i'm looking for is an example of what a link coming from some page to a form page holding a variable that i can use in a switch function after the form is submitted would look like. The action on the form takes me to a script where i will need this variable.

switch ($var)
{
case "1"
use this $var1; //came from this page
break;
case "2"
use this $var2; //came from this page
default:
print "error";
}

Case And Break
can someone give me a brief explanation or code example of what case and break do in php? and what about classes?

Title Case
I haven't found a way to set title case in PHP... IE:

test tItle => Test Title

Is there a way to achieve this?

Php Case Switch
I'm implemening an update profile section on my site and I'd like to use switch/case method. e.g. page.com?update=success or page.com?update=failure, when I use the $_GET['update'] it works fine, however what of someone changes the url manually to .com?update=somethingelse ?

How can I stop people getting access to other pages/cases manually.

Problem With Switch/case, Want It Instead Of If
I have this code that fetches a nationID from my table.
Depending on what ID it is... it displays a country flag.

Switch And Case Problem
Can anyone give me a helping hand with this code

I want the script to verify a username and password using a switch and case statement.

if the username and password is matched I want to move on to the next section of the site. If there is no match I want it to ask for the username and password again.


The trouble is Im not getting the desired results with the switch and case


<?php
echo "
<html><head><title>Aventis</title></head>
<body>";
require "./config.inc.php";
$db_connect = mysql_connect ($host,$user,$passwd);
mysql_select_db($database, $db_connect);
$failure=0;
if ( $rep_name )
{
switch ($page) {
case "login":
$result=mysql_query("select * from rep where rep_name='$rep_name'",$db_connect) or die ("cant do it");
while ($row=mysql_fetch_array($result)) {
if ($row["rep_passwd"] != $rep_passwd) {
$failure = 1; break;
echo "successful login";
}
//default:
//echo "Wrong username";
//break;
}}
if ($failure == 1)
{ echo "Wrong details"; }
else { echo"
<form method='post' action='$PHP_SELF?page=login'>
Username: <input type='text' name='rep_name'><br>
Password: <input type='password' name='rep_passwd'><br>
<input type='submit' value='Submit'>
";
}
echo "
</body>
</html>";
?>

Case Sensitivity - Mysql_fetch_array()
I'm retrieving some results from a mysql database and i'm using mysql_fetch_array() everything works fine..

Apart from the results are not case sensitive, i've checked the database using phpMyAdmin and the values stored ARE case sensitive what am i doing wrong?

here's a peice of code as an example

<?
$sql = "SELECT * FROM table ORDER BY signup_date DESC LIMIT 5";
$result = mysql_query($sql) or die ("ERROR: ".mysql_error()." with query: $sql");
while($row = mysql_fetch_array($result)){
echo "<tr>
<td class='profile_name'>
<p><a href='user-profile.php?username=$row[username]'>$row[username]</a></p>
</td>";
// Format date
$signup_date = date('d-m-y', strtotime($row[signup_date]));
echo "<td class='signup_date'>
<p>$signup_date</p>
</td>
</tr>";
}
?>

Case Insensitive Srt_replace
is there a case insensitive string replace?

Case Conversion Of Variables
Is anyone aware of a method of converting the case of a variable. I am taking data in the format of JOHN SMITH that I wish to display as John Smith. I am using a mySQL database and using PHP to display the results.

SQL 'LIKE" Case Sensitivity
Does anyone know of how I can disable case sensitivity for the LIKE
function in SQL?

Currently the SQL statement looks like:

$query = "SELECT * FROM itrader_games WHERE console='$console' AND
genre='$genre' AND title LIKE '%$title%' ";

Also, I have tried to make it so that if 'any' is selected for the
hardcoded variables (errmm does that make sense?) the valeu of Any is *
and put into the SQL statement - sorry i dont know how to explain this
but this is the HTML used

<option value="*">Any</option>

Mysql Question : CASE
I have searched but have not yet found how I can resolve the following
problem :

SELECT adId,
CASE
WHEN adId =1 THEN cityId
WHEN adId =2 THEN regionId
END AS extraField
FROM ad
WHERE extraField <> 0

The problem is "extraField" cannot be used in the WHERE clause... I am using
mySQL 4.1

Ereg, Case Insensitive?
I am checking a directory for jpeg images. In order to list them, I do a check like this:

[PHP]while (false !== ($file = readdir($handle))) {
if (is_file("$path/$file") && (ereg ("(.*).jpg", "$path/$file")) ) {
$array = @array_merge($array, $file);
$array_count = @count($array);} }
if ($array_count > 0) {
do something here}

but now I found that I also have files where the extension is in upper case i.e. ".JPG". how can I make the above expession case insensitive? Or can anyone suggest a different approach?

Case-insensitive Str_replace
I'm trying to replace strings in a body of html. These strings may
contain spaces. str_replace works perfectly, except that it is
case-sensitive. I've tried using eregi_replace, but I think there is
something wrong with my regex's. Here is my current code:

$bword may contain something like: "testing testing 123"

$bword = trim ($bword); //Remove trailing newlines
str_replace (' ', '[s]', $bword); //Change spaces to [s]
$urlhtml = eregi_replace ("[s]($bword)[s]", $replacecode, $urlhtml);

It seems to pick up some words, but not all......

Multiple (OR ||) Case Usage
Having trouble wrapping this up into a viable statement

I want to check on a users status before allowing a script to be run.
$myzone can only be 1 variable, but it can be here, there or where.

if ($myzone !== ("here") or ("there") or ("where")) { die: }

This does not work however, it will kill the script regardless if one
of the statments is actually true.

However, this WILL work if only one operator is checked:

if ($myzone !== "here") { die: }

If $myzone is "here" the script is allowed to run. If it's anything
else, it dies, as it is supposed to. However, I want to check if
$myzone is several options. That is my delima.

Switch / Case Errors
For some reason I can never get the "Switch / Case" functions to work for me. Can some one tell me whats wrong with this: PHP Code:

How To Query Using Case Sensativity?
This is essentially a MySQL question but no one over there seemed to know, nor can I find any example in the MySQL docs. All I want to do is query for a word/name and have the query be case sensative. so a SELECT query would find BOB, and not BoB, or bob, or boB, just BOB. Is this possible in a MySQL query? I'm starting to think maybe not.


Copyright © 2005-08 www.BigResource.com, All rights reserved