Page 1 of 2

Error: PHP Warning: rand() expects parameter 1 to be long

Posted: Tue Aug 08, 2006 7:57 pm
by koolheaven
Hey,
Now I;m getting this error:

PHP Warning: rand() expects parameter 1 to be long, string given in /hermes/web06/b932/hy.agl01/captcha/class.captcha.php on line 78


Here is the class.captcha.php File:

Code: Select all

<?php
######
## VeriWord
## A PHP CAPTCHA System
## Version 2
#######
require_once("class.noisegenerator.php");
require_once("class.wordart.php");
require_once("class.wordgenerator.php");

class Captcha {

	var $width;
	var $height;
	var $image;
	var $word;

	var	$randomword 	= array();
	var	$noise			= array();
	var	$wordart 		= array();
	var $capctha		= array();


	function Captcha() {


	}

	function setConfiguration ($captchas, $randomwords,$noises,$wordarts) {
        $this->captcha = $captchas;
        $this->randomword = $randomwords;
        $this->noise = $noises;
        $this->wordart = $wordarts;
	}

	function getRandomWord() {
		$word = new  $this->randomword['type'];
		$word->setDictionary($this->randomword['dict']);
		$word->setLength($this->randomword['length']);
		$word->pickWord();
		return $word->getWord();
	}


	function getNoise() {
		$imnoise = new $this->noise['type'];
		$imnoise->pickRandomBackground($this->noise['dir']);
		return $imnoise->getNoise();
	}

	function getWordArt($word) {
		$imword = new WordArt($this->width,$this->height);
		$imword->setFontDirectory($this->wordart['dir']);
		$imword->setWord($word);
		$imword->setCapital($this->wordart['capital']);
		$imword->setTextAngle(rand($this->wordart['angle'],5));
		$imword->setFontColor($this->wordart['color']);
		$imword->drawText();
		$imword->applyFilter($this->wordart['filter']);
		return $imword->getWordArt();
	}


	function getCaptcha() {
		$this->width  = $this->captcha['width'];
		$this->height = $this->captcha['height'];

		$this->word = $this->getRandomWord();
		$noise      = $this->getNoise();
		$wordart    = $this->getWordArt($this->word);

		$noise_width 	= imagesx($noise);
		$noise_height 	= imagesy($noise);

			/* resize the background image to fit the size of image output */
		$imcaptcha 		= @imagecreatetruecolor($this->width,$this->height);
		imagecopyresampled ($imcaptcha,
							$noise,
							0, 0, 0, 0,
							$this->width,
							$this->height,
							$noise_width,
							$noise_height);

		/* put text image into background image   */

		imagecopymerge ( 	$imcaptcha,
							$wordart,
							0, 0, 0, 0,
							$this->width,
							$this->height,
							80 );

		return $imcaptcha;

	}

}

?>

Posted: Tue Aug 08, 2006 8:02 pm
by RobertGonzalez
Dude, post lines 75 - 80. Rand() expects to be passed a number, not a string. The error is telling you that you are passing a string to the rand() function somewhere on or about line 78.

EDIT | I should clarify that statement. If you choose to pass it a value, it needs to be numeric.

Posted: Tue Aug 08, 2006 8:10 pm
by koolheaven

Code: Select all

function getWordArt($word) {
		$imword = new WordArt($this->width,$this->height);
		$imword->setFontDirectory($this->wordart['dir']);
		$imword->setWord($word);
		$imword->setCapital($this->wordart['capital']);
		$imword->setTextAngle(rand($this->wordart['angle'],5));
		$imword->setFontColor($this->wordart['color']);
		$imword->drawText();
		$imword->applyFilter($this->wordart['filter']);
		return $imword->getWordArt();
	}

Posted: Tue Aug 08, 2006 8:11 pm
by koolheaven
Everah wrote:Dude, post lines 75 - 80. Rand() expects to be passed a number, not a string. The error is telling you that you are passing a string to the rand() function somewhere on or about line 78.

EDIT | I should clarify that statement. If you choose to pass it a value, it needs to be numeric.
I am new at PHP, so please write the full line! :-)

Thanks!

Posted: Tue Aug 08, 2006 8:11 pm
by Jenk

Code: Select all

$imword->setTextAngle(rand($this->wordart['angle'],5));
What is the value of $this->wirdart['angle'] ? var_dump() it to see..

Posted: Tue Aug 08, 2006 8:14 pm
by koolheaven
Jenk wrote:

Code: Select all

$imword->setTextAngle(rand($this->wordart['angle'],5));
What is the value of $this->wirdart['angle'] ? var_dump() it to see..

Um..

It was edited, cuz I get the error:
Rand() expects parameter 2 to be long


Privious was:

Code: Select all

$imword->setTextAngle(rand(-$this->wordart['angle'],$this->wordart['angle']));

Posted: Tue Aug 08, 2006 8:17 pm
by Jenk
hint:

Code: Select all

function getWordArt($word) {
                $imword = new WordArt($this->width,$this->height);
                $imword->setFontDirectory($this->wordart['dir']);
                $imword->setWord($word);
                $imword->setCapital($this->wordart['capital']);
                var_dump($this->wordart['angle']);
                $imword->setTextAngle(rand($this->wordart['angle'],5));
                $imword->setFontColor($this->wordart['color']);
                $imword->drawText();
                $imword->applyFilter($this->wordart['filter']);
                return $imword->getWordArt();
        }

Posted: Tue Aug 08, 2006 8:22 pm
by koolheaven
Jenk wrote:hint:

Code: Select all

function getWordArt($word) {
                $imword = new WordArt($this->width,$this->height);
                $imword->setFontDirectory($this->wordart['dir']);
                $imword->setWord($word);
                $imword->setCapital($this->wordart['capital']);
                var_dump($this->wordart['angle']);
                $imword->setTextAngle(rand($this->wordart['angle'],5));
                $imword->setFontColor($this->wordart['color']);
                $imword->drawText();
                $imword->applyFilter($this->wordart['filter']);
                return $imword->getWordArt();
        }
Now I got a big error list !!!!


Code: Select all

PHP Warning:  Cannot modify header information - headers already sent by (output started at /hermes/web06/b932/hy.agl01/captcha/class.captcha.php:78) in /hermes/web06/b932/hy.agl01/captcha/class.veriword.php on line 135
PHP Warning:  rand() expects parameter 1 to be long, string given in /hermes/web06/b932/hy.agl01/captcha/class.captcha.php on line 79
PHP Warning:  Cannot modify header information - headers already sent by (output started at /hermes/web06/b932/hy.agl01/captcha/class.captcha.php:78) in /hermes/web06/b932/hy.agl01/captcha/class.veriword.php on line 135
PHP Warning:  rand() expects parameter 1 to be long, string given in /hermes/web06/b932/hy.agl01/captcha/class.captcha.php on line 79

Posted: Tue Aug 08, 2006 8:24 pm
by Jenk
any other output?

Posted: Tue Aug 08, 2006 8:25 pm
by Luke

Code: Select all

var_dump($this->wordart['angle']);
IS this line 78?

Posted: Tue Aug 08, 2006 8:32 pm
by koolheaven
yah line 78!

Posted: Tue Aug 08, 2006 8:34 pm
by koolheaven
Jenk wrote:any other output?
At 1st I was getting rand() expects parameter 2 to be long, but after putting the value 5, It turns to parameter 1 !! :o
:evil:

Posted: Tue Aug 08, 2006 8:38 pm
by Jenk
so the var_dump() isn't outputting anything?

nothing like:

Code: Select all

string (9) "something."

Posted: Tue Aug 08, 2006 8:41 pm
by Luke
1) have you read the manual corresponding to this function?

http://us3.php.net/manual/en/function.rand.php

2) The reason for the extra errors is because you are sending output before headers (var_dump outputs information about a variable)

Posted: Tue Aug 08, 2006 8:42 pm
by koolheaven
Jenk wrote:so the var_dump() isn't outputting anything?

nothing like:

Code: Select all

string (9) "something."
Nope, its not! 8O