If you want to ensure a password contains at least one non-alphabetic non-numeric character I think ctype_alnum could work until you understand regex better.
if (strlen($password) < 5 || strlen($password) > 20) {
// password must be between 5 and 20 characters long
header("Location: ../signup.php?signup=invvalidlength");
exit();
} else if (!ctype_alnum ($password)) {
// password does not consist of all letters or digits
header ("Location: ../signup.php?signup=notalphanumeric");
exit();
}
<off-topic> @piano0011, when you post code in the forum, you need to format it. To do so you can either select all the code and click the </> button, or type 3 backticks ``` on a separate line both before and after the code block. </off-topic>
But in what way? Does it redirect when it should not, or not redirect when it should, or give the wrong error message. Tell us how it doesn’t work. And/or show the rest of the code so we can see if something prior to this is stopping it from doing what you expect it to.
and tell us error or post whole script it will be easier.
Or you can user preg_match if you are better with that
<?php
error_reporting(E_ALL);
if (strlen($password) < 5 || strlen($password) > 20) {
// password must be between 5 and 20 characters long
header("Location: ../signup.php?signup=invvalidlength");
exit();
} else if (!preg_match('/^[a-zA-Z0-9]+$/', $password)) {
// password does not consist of all letters or digits
header ("Location: ../signup.php?signup=notalphanumeric");
exit();
}
Though I think most browsers can handle relative urls. But as quite a few people have already mentioned, “does not work” really “does not help”.
ctype_slum returns a boolean, not a number. Yes php supports mixing types. Does that mean you should do so? A most emphatic no. If a function returns a boolean then check for true or false. It will save you a huge amount of trouble. Especially before you understand how to organize your code.