Page 1 of 1

Error: rand() expects parameter 2 to be long

Posted: Tue Aug 08, 2006 4:12 pm
by koolheaven
Hey,

Help needed!!

I have got this two error!

PHP Warning: rand() expects parameter 2 to be long, string given in /hermes/web06/b932/hy.agl01/captcha/class.captcha.php on line 78
PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /hermes/web06/b932/hy.agl01/contact_us.php:12) in /hermes/web06/b932/hy.agl01/captcha/class.verificator.php on line 35

Please help me if you know the way to solve it!

Thanks in advance!

class.captcha.php:

Code: Select all

<?php
######
## VeriWord
## A PHP CAPTCHA System
## Version 2
#######
## Author: Huda M Elmatsani
## Email: 	justhuda ## netscape ## net
##
## 25/07/2004
#######
## Copyright (c) 2004 Huda M Elmatsani All rights reserved.
## This program is free for any purpose use.
########
##
## PACKAGE OF VERIWORD V2
## sample.php
## image.veriword.php
## class.veriword.php
## class.captcha.php
## class.noisegenerator.php
## class.wordgenerator.php
## class.wordart.php
## class.filefinder.php
## class.configreader.php
## veriword.ini
##
#######
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'],$this->wordart['angle']));
		$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;

	}

}

?>

Class.verificator.php:

Code: Select all

<?php
######
## VeriWord
## A PHP CAPTCHA System
## Version 2
#######
## Author: Huda M Elmatsani
## Email: 	justhuda ## netscape ## net
##
## 25/07/2004
#######
## Copyright (c) 2004 Huda M Elmatsani All rights reserved.
## This program is free for any purpose use.
########
##
## PACKAGE OF VERIWORD V2
## sample.php
## image.veriword.php
## class.veriword.php
## class.captcha.php
## class.noisegenerator.php
## class.wordgenerator.php
## class.wordart.php
## class.filefinder.php
## class.configreader.php
## veriword.ini
##
#######
class VeriFicator {

	var $postvar;

	function VeriFicator($postvar) {
		/* create session  */
		session_start();
		$this->postvar = $postvar;
	}

	function verifyWord() {

		$submittedveriword = strtolower($this->postvar);

		if (md5($submittedveriword) == $_SESSION['veriword'])
			return true;
		else
			return false;
	}

	function verified() {
		if($this->verifyWord()) return true;
		else return false;

	}

}


?>

Posted: Tue Aug 08, 2006 4:23 pm
by nincha
PHP Warning: session_start(): Cannot send session cache limiter - headers already sent

occures when somethign has been outputed to the browser, html, strings including spaces.
Check before your <?php see if theres any spaces and remove it.


check the rand() parameters.. echo them and see if they're numbers.

Posted: Tue Aug 08, 2006 4:26 pm
by Ollie Saunders

Code: Select all

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

Code: Select all

$imword->setTextAngle(rand(-$this->wordart['angle'],$this->wordart['angle']));
...PHP is saying that $this->wordart['angle'] is a string

Posted: Tue Aug 08, 2006 4:44 pm
by koolheaven
Main problem is PHP page was edited by Frontpage and added hyml tags. (A new Web designer did it) After that Its not working!

Posted: Tue Aug 08, 2006 4:49 pm
by koolheaven
I am now getting just 1 error:

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


Pls help me how I can recover it too!

Thanks a lot!

Posted: Tue Aug 08, 2006 5:09 pm
by Ollie Saunders
Delete the space at the top of the script

Posted: Tue Aug 08, 2006 5:15 pm
by koolheaven
IC

Posted: Tue Aug 08, 2006 5:27 pm
by feyd
The code posted does not call setConfiguration() or ever attempt to set the $wordart attribute in the Captcha class.

var_dump($this->wordart) just before the call to rand().

Posted: Tue Aug 08, 2006 8:21 pm
by Weirdan
Double post, please continue here
Image