Jump to content


Photo

Comparing variables


  • Please log in to reply
3 replies to this topic

#1 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 09 October 2006 - 07:47 PM

Hi,
I have a form on my site where users are supposed to input the name of another user. I want to make sure that people cannot enter their own username instead of somebody elses. It also has to be case insensitive, because with the previuos piece of code i had, people were just inputting their own username in different cases to get around it.

Here's something similar to what i had before:
<?php

$other_user = $_POST['otheruser'];

if ($other_user == $_SESSION[username]) {
echo "Invalid";
exit();
}

?>

I also tried a something with eregi that somebody told me would work, but that didn't work too well, and detected similar usernames as well as matches, but i deleted it and forgot the exact setup of it.

Can someone suggest to me a solution?

Thanks in advance.

#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 09 October 2006 - 07:50 PM

you can convert both to lowercase for the comparision. strtolower($string);

http://usphp.com/strtolower

#3 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 09 October 2006 - 07:51 PM

if (strtolower($other_user) == strtolower($_SESSION[username])) {
die("Invalid");
}

Orio.
Think you're smarty?

(Gone until 20 to November)

#4 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 09 October 2006 - 07:54 PM

Wow, i didn't think of that. Thanks guys!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users