我正在用preg_match检查用户名,但我做错了,只是我不知道我做错了什么,我尝试了很多次,但没有成功,所以如果你能帮助我,非常感谢你,这也是一个很好的给我上一课。这是我正在做的事情的来源:
<?php
if(isset($_POST['submit']))
{
?>
<html>
<head>
<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" type="text/javascript"></script>
<script language="javascript" src="config.php?name=<?php echo $_POST['name']; ?>&gender=<?php echo $_POST['gender']; ?>&color=<?php echo $_POST['color']; ?>" type="text/javascript"></script>
</head>
<body>
<!-- Applet Start -->
<br /><div style="text-align: center;">
<div id="lightIRC" style="height:500px; text-align:center;"><p><a href="http://www.adobe.com/go/getflashplayer" title="Get flash player"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p></div>
<script type="text/javascript">swfobject.embedSWF("http://www.futurechat.nl/chat/lightIRC.swf", "lightIRC", "100%", "500", "10.0.0", "http://www.futurechat.nl/chat/expressInstall.swf", params);</script>
</div>
</body>
</html>
<?php
}
else {
print_form();
}
function print_form() {
// MAKE SURE USERNAME IS ALPHANUMERIC
$name = $_POST['name'];
if(preg_match('/[^A-Za-z0-9_-]/', $_POST['name']))
echo "Invalid Username";
?>
<html>
<head>
<title>Login</title>
<style>
body {font-family: Verdana;}
</style>
</head>
<body>
<form action="chatlogin.php" method="post">
<table cellspacing="0" cellpadding="0" align="center" style="background: #cccccc;text-align: center;font-size: 13px;">
<tr valign="top">
<td>
Nickname:
<input type="text" name="name">
<br /><br />
Gender:
<input type="radio" name="gender" value="Male">Male <input type="radio" name="gender" value="Female">Female
<br /><br />
Applet Color:
<select name="color">
<option value="lightblue">Lightblue</option>
<option value="blue">Blue</option>
<option value="darkorange">Dark Orange</option>
<option value="black">Black</option>
<option value="yellow">Yellow</option>
<option value="green">Green</option>
<option value="pink">Pink</option>
<option value="white">White</option>
</select>
<br /><br />
<input type="submit" name="submit" value="Chat now!">
</td>
</tr></table>
</form>
</body>
</html>
<?php
}
?>