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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.