Jump to content

Recommended Posts

I'm pretty much a foreigner when it comes to php, so I need a little help with a bit of code. I have this bit of code:

 

<?php
require( 'ccproto_client.php' );

// your connect information
define( 'HOST',		"72.233.64.162"	);	// YOUR HOST
define( 'PORT',		7462		);	// YOUR PORT
define( 'USERNAME',	"myusername"	);	// YOUR LOGIN
define( 'PASSWORD',	"mypassword");	// YOUR PASSWORD

define( 'PIC_FILE_NAME',	"pic.jpg"	);
    
$ccp = new ccproto();
$ccp->init();

print( "" );
if( $ccp->login( HOST, PORT, USERNAME, PASSWORD ) < 0 ) {
	print( " FAILED\n" );
	return;
} else {
	print( "" );
}

$system_load = 0;
if( $ccp->system_load( $system_load ) != ccERR_OK ) {
	print( "" );
	return;
}
print( "" );

$balance = 0;
if( $ccp->balance( $balance ) != ccERR_OK ) {
	print( "" );
	return;
}
print( "" );

$major_id	= 0;
$minor_id	= 0;
for( $i = 0; $i < 3; $i++ ) {
	$pict = file_get_contents( PIC_FILE_NAME );
	$text = '';
	print( "" );

	$pict_to	= ptoDEFAULT;
	$pict_type	= ptUNSPECIFIED;

	$res = $ccp->picture2( $pict, $pict_to, $pict_type, $text, $major_id, $minor_id );
	switch( $res ) {
		// most common return codes
		case ccERR_OK:
			print( $text );
			break;
		case ccERR_BALANCE:
			print( "not enough funds to process a picture, balance is depleted" );
			break;
		case ccERR_TIMEOUT:
			print( "picture has been timed out on server (payment not taken)" );
			break;
		case ccERR_OVERLOAD:
			print( "temporarily server-side error" );
			print( " server's overloaded, wait a little before sending a new picture" );
			break;

		// local errors
		case ccERR_STATUS:
			print( "local error." );
			print( " either ccproto_init() or ccproto_login() has not been successfully called prior to ccproto_picture()" );
			print( " need ccproto_init() and ccproto_login() to be called" );
			break;

		// network errors
		case ccERR_NET_ERROR:
			print( "network troubles, better to call ccproto_login() again" );
			break;

		// server-side errors
		case ccERR_TEXT_SIZE:
			print( "size of the text returned is too big" );
			break;
		case ccERR_GENERAL:
			print( "server-side error, better to call ccproto_login() again" );
			break;
		case ccERR_UNKNOWN:
			print( " unknown error, better to call ccproto_login() again" );
			break;

		default:
			// any other known errors?
			break;
	}
	print ( "\n" );

	// process a picture and if it is badly recognized 
	// call picture_bad2() to name it as error. 
	// pictures named bad are not charged

	//$ccp->picture_bad2( $major_id, $minor_id );
}

$balance = 0;
if( $ccp->balance( $balance ) != ccERR_OK ) {
	print( "balance() FAILED\n" );
	return;
}
print( "" );

$ccp->close();

// also you can mark picture as bad after session is closed, but you need to be logged in again
$ccp->init();
print( "" );
if( $ccp->login( HOST, PORT, USERNAME, PASSWORD ) < 0 ) {
	print( "" );
	return;
} else {
	print( "" );
}
print( "" );
$ccp->picture_bad2( $major_id, $minor_id );
$ccp->close();


?>

 

It's supposed to return a value, but it's returning that value three times. I've asked someone else, but they said it's in this php code, and that this is an example code so I have to modify it so it only returns that value once. Like I said before, I don't have a clue when it comes to php, so I was wondering if someone was just able to look at the code and tell me what to fix.

 

That would be so helpful!

 

Thanks guys/gals,

Hayden

Link to comment
https://forums.phpfreaks.com/topic/188332-triple-posting-issue/
Share on other sites

I'm sorry, I'm not even sure what I'm looking for. I know that this code is supposed to return a decoded captcha, but it's returning the captcha three times, so I'm not sure where to look for that.

 

I hope that helps! Sorry about the lack of info.

 

Thanks,

Hayden

Link to comment
https://forums.phpfreaks.com/topic/188332-triple-posting-issue/#findComment-994280
Share on other sites

for( $i = 0; $i < 3; $i++ ) {

Theres your problem. It's looping through that code three times. Either get rid of this, and the related closing bracket near the end, or change $i < 3 to $i < 1.

 

Thanks! I'll give it a try and report back here in case any others were having the same issues.

Link to comment
https://forums.phpfreaks.com/topic/188332-triple-posting-issue/#findComment-994316
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.