Only use first 6 charcters in submitted field when parsing php
I have an input field that posts to this bit of php and works fine but i'd like users to be able to enter more than 6 characters into the input form and the开发者_Go百科n have the following only use the first 6 characters:
example: user enters: 1234567890 PHP (or javascript before the post) uses only "123456" and disregards "7890"
Here is the bit of php that's working as long as a user only enters 6 characters:
?php function getCode() {
if (isset($_GET["code"])) {
if ($_GET["code"] == "example1" || $_GET["code"] == "example1") {
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.example.com">';
} else if ($_GET["code"] == "example2" || $_GET["code"] == "example2") {
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.example2.com">';
} else if ($_GET["code"] != "example1" || $_GET["code"] != "example2") {
//Looks like your lot number didn't work.
$message = '<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.example.com/noworky">';
};
return $message;
};
Use the substr
function to chop the input $_GET['code']
down to 6 characters, then compare that.
Why do you have all these redundantly duplicated conditions? And why the ;
after the }
s? I really recommend getting yourself a good book. Programming by guessing does not work [well].
$_GET["code"] = substr($_GET["code"],0,6);
精彩评论