Jump to content

[SOLVED] strlen() not working :/


LooieENG

Recommended Posts

strlen() returns an integer, and when you pass an integer inside the exit() function, rather than echoing it, the integer acts as a "status". Certain integers have error codes with them, and so by passing the error code # into the exit, it will display the error associated with it.

 

Just use die(strlen($username)); instead.

And checking php.net confirms what I've said:

 

 

Description

void exit ([ string $status ] )

void exit ( int $status )

 

Terminates execution of the script.

Parameters

 

status

 

    If status is a string, this function prints the status just before exiting.

 

    If status is an integer, that value will also be used as the exit status. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully.

 

        Note: PHP >= 4.2.0 does NOT print the status if it is an integer.

 

Thanks for the reply, the reason I'm using it in exit is because when I enter test this code always returns

 

Username must have between 4 and 30 characters.

 

This is my code

 

<?php

require('includes/config.php');

if ($_POST['register']) {
$username = mysql_real_escape_string(trim($_POST['username']));
exit(strlen($username));
$password = trim($_POST['password']);
$password2 = trim($_POST['password2']);
if ((strlen($username) > 4) && (strlen($username) < 30)) {
	if ($password == $password2) {
		if (strlen($password) >  {
			$password = md5($salt . $_POST['password']);
			mysql_query("INSERT INTO users ('username', 'password') VALUES ('$username', '$password')");
			$info = 'Your account has been registered, you may now log in.';
			include('includes/info.php');
			exit;
		} else {
			$info = 'Your password must contain at least 8 characters.';
			include('includes/info.php');
			exit;
		}
	} else {
		$info = 'Your passwords didn\'t match, please try again.';
		include('includes/info.php');
		exit;
	}
} else {
	$info = 'Username must have between 4 and 30 characters.';
	include('includes/info.php');
	exit;
}
} else {
include('includes/register.php');
}

?>

 

Edit: Just figured out 4 isn't more than 4 :P

 

Thanks for the reply and explanation kratsg

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.