RE: [PHP] Approximate Comparison [resend]

From: Date: Tue, 06 May 2003 22:14:59 +0000
Subject: RE: [PHP] Approximate Comparison [resend]
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-146577@lists.php.net to get a copy of this message
> I'm attempting to see if $_SERVER["REQUEST_URI"] includes part of a url. > Here's an example with the real URL of my script removed: > <!-- For people with HTML-enabled e-mail readers, this is enclosed in > <pre> tags --> > <pre> > if ($_POST["posted"]){ > // If so, echo the following > echo "<h1>* $slapper slaps $slapee with a $size $mode</h1><br>"; > echo "You can link to this file with " . "<a href=\"$link\">this > link</a>"; > } > elseif ($_POST != posted){ > // Wasn't working before, let's see if this does it > echo ""; > } > elseif ($_SERVER["REQUEST_URI"] == > > "http://myurl.com/my/path/myscript.php?thepartiwanttotestfor=";){ > // Check and see if someone did a direct request > echo "<h1>* $slapper slaps $slapee with a $size $mode</h1><br>"; > echo "You can link to this file with " . "<a href=\"$link\">this > link</a>"; > } > else { > // If not, echo nothing > echo ""; > } > > It works okay when someone uses the form below all this code, but when > someone uses the link > (myscript.com/my/path/myscript.php?slapper=whatever&slapee=whatever&size =w > hatever&mode=whatever) > it doesn't see $_POST includes posted (which is an input type=hidden > thing in the form) so it displays nothing. Use $_REQUEST['posted'] instead of $_POST['posted'] and add the "posted" variable to your URL. myscript.com/my/path/myscript.php?slapper=whatever&slapee=whatever&size= whatever&mode=whatever&posted=something $_REQUEST contains GET, POST, and COOKIE data, so using a form or URL with "posted" in it will create that variable within $_REQUEST. > So my question is, is there any way I can look for part of a string, or > do an approximate comparison? Use strpos() for this. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#146577) next »