Location: PHPKode > scripts > get2post > get2post/class.get2post.php
<?php
class getToPost {

	var $strKey = 'zaxscdvf';
	var $random_id_length = 8;
	
	// encrypting a passed value
	function encrypt($string)
	{
		$string = 'STT576PWZA'.$string;
		
		$result = '';
		
		for($i=0; $i<strlen($string); $i++)
		{
			$char = substr($string, $i, 1);
			$keychar = substr($this->strKey, ($i % strlen($this->strKey))-1, 1);
			$char = chr(ord($char)+ord($keychar));
			$result.=$char;
		}

	return base64_encode($result);
	
	}

	// decrypting a passed value
	function decrypt($string)
	{
		$result = '';
		
		$string = base64_decode($string);
		
		for($i=0; $i<strlen($string); $i++)
		{
			$char = substr($string, $i, 1);
			$keychar = substr($this->strKey, ($i % strlen($this->strKey))-1, 1);
			$char = chr(ord($char)-ord($keychar));
			$result.=$char;
		}
		
		$result = substr($result,10,strlen($result));
	
	return $result;
	
	}
	
	// create a form with the following parameters:
	// $formAction = html action of the form
	// $linkText = in browser displayed html link for submitting form
	// $getString = string with values as: name{=}John{&}surname{=}Joe{&}age{=}20
	// $yesOrNo = text asked for confirmation (leave it empty for no question)
	function get2post ($formAction, $linkText, $getString, $yesOrNo=NULL)
	{
	 
		$rnd_id = crypt(uniqid(rand(),1)); 
		$rnd_id = strip_tags(stripslashes($rnd_id)); 
		$rnd_id = str_replace(".","",$rnd_id); 
		$rnd_id = strrev(str_replace("/","",$rnd_id)); 
		$rnd_id = substr($rnd_id,0,$this->random_id_length);
		
		($yesOrNo) ? $ask = $yesOrNo : $ask = 0;
	
		$form = '<form name="form'.$rnd_id.'" action="'.$formAction.'" method="POST" style="margin: 0 none; padding: 0 none; display:inline; " >' . chr(10);
		
		$getString2Arr = explode('{&}', $getString);
		
		foreach ($getString2Arr as $key=>$val)
		{
		
			list($inputName, $inputVal) = preg_split('/{=}/', $val);
			
			$form .= '<input type="hidden" name="'.$this->encrypt($inputName, $this->strKey).'" value="'.$this->encrypt($inputVal, $this->strKey).'" />' . chr(10);
		
		}
		
		$form .= '<a href="#" onclick="return submitlink( \''.$ask.'\', \'form'.$rnd_id.'\' )">'.$linkText.'</a>' . chr(10);
		
		$form .= '</form>' . chr(10);
		
		echo $form;
	
	}
	
	// write the javascript
	function writeJS ()
	{
	
		echo '<script language="JavaScript" type="text/javascript"> 
		<!-- 
		function submitlink ( ask, formId ) 
		{ 
		
			if(ask != 0){
			
				var yn = confirm(\'\'+ ask +\'\');
				
				if(yn && yn == true){
				
					document.forms[\'\'+ formId +\'\'].submit();
				
				}
				if(yn && yn == false){
				
					return false;
				
				}
				
			}
			
			if(ask == 0){
			
				document.forms[\'\'+ formId +\'\'].submit();
			
			}
			
		} 
		--> 
		</script> ';
	
	}

}
?>
Return current item: get2post