User Forwarding with PHP

This sample php code sets up a user's call forwarding

Sample Code
//Forwarding is being done using Restful API via Curl - here to demonstrate using both programming interfaces to accomplish a task
function addForwarding($user,$ext,$pass)
{
	//set up the forwarding rules (we append 7 because that tells sipx to dial on the nostalgic NEC system)
	//structured like this because we're actaully passing "XML" data to the page
	$rules = "
	<call-sequence> 
	  <rings> 
		<ring> 
		  <expiration>30</expiration> 
		  <type>At the same time</type> 
		  <enabled>false</enabled> 
		  <number>7".$ext."</number> 
		</ring> 
	  </rings> 
	  <withVoicemail>false</withVoicemail> 
	</call-sequence>
	";
	
	//this URL does the magic - we're just passing everything to it
	$url = "https://sipx:8443/sipxconfig/rest/my/forward"; 
	
	//open up curl
	$ch = curl_init(); 
	
	//open the URL    
	curl_setopt($ch, CURLOPT_URL, $url);
	
	//we have to "PUT" the data to the server
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');  
	curl_setopt($ch, CURLOPT_POSTFIELDS, $rules); 
	
	//these two lines are only for servers with invalid SSL - hopefully you don't have that issue and can delete these
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

	//who are you? authorization errors if they are not a user yet
	curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
	curl_exec($ch);
	//close our curl
	curl_close($ch);	
}