Click here to Skip to main content
15,888,003 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
GeneralRe: RESOLVED: How to debug PHP Memory Leak Pin
Mohibur Rashid31-Oct-11 18:01
professionalMohibur Rashid31-Oct-11 18:01 
QuestionProblem receiving arabic emails Pin
Jassim Rahma27-Oct-11 7:38
Jassim Rahma27-Oct-11 7:38 
AnswerRe: Problem receiving arabic emails Pin
Graham Breach27-Oct-11 9:26
Graham Breach27-Oct-11 9:26 
QuestionHow to make a Cloud text from database Pin
Jassim Rahma26-Oct-11 10:58
Jassim Rahma26-Oct-11 10:58 
AnswerRe: How to make a Cloud text from database Pin
User 171649226-Oct-11 11:39
professionalUser 171649226-Oct-11 11:39 
QuestionFacebook-Like modal box Pin
Jassim Rahma25-Oct-11 6:26
Jassim Rahma25-Oct-11 6:26 
AnswerRe: Facebook-Like modal box Pin
Mohibur Rashid25-Oct-11 15:40
professionalMohibur Rashid25-Oct-11 15:40 
Questionsignature_invalid in Google API Pin
Paresh146225-Oct-11 2:36
Paresh146225-Oct-11 2:36 
I am developing Google app (with oauth 1.0)that retrieve google contatcs but i got error : signature_invalid please help me Thx in advance

PHP
function GetRequestToken()
{
	$consumer = 'YOUR_CONSUMER_KEY';
	$secret = 'YOUR_CONSUMER_SECRETE';
	$callback = 'http://localhost/Gcontacts/welcome/redirection';
	$sign_method = 'HMAC-SHA1';
	$version = '1.0';
	$scope = 'https://www.google.com/m8/feeds/';
	$path = "/accounts/OAuthGetRequestToken";	 
	$mt = microtime();
	$rand = mt_rand();
	$nonce = md5($mt.$rand);
	$time = time();
	$url = 'https://www.google.com/accounts/OAuthGetRequestToken';		
	$post = array(
	    'oauth_callback' => $callback,
	    'oauth_consumer_key' => $consumer,
	    'oauth_nonce' => $nonce,
	    'oauth_signature_method' => $sign_method,
	    'oauth_timestamp' => $time,
	    'oauth_version' => $version,
	    'scope' => $scope
		);
	$post_string1 = '';
	foreach($post as $key => $value)
	{
         	$post_string1 .= $key.'='.($value).'&';
	}
	$post_string1 = trim($post_string1, '&');
		
	$key_part = $this->urlencodeRFC3986($secret);
	$key = $key_part;
	$base_string = $this->calculateBaseString($scope, "GET", $post);
	echo $base_string;
	$signature = base64_encode(hash_hmac('sha1', $base_string, $key,true));
	$post_string1 .= 'oauth_signature'.'='.urlencode($signature);
			$post['oauth_signature'] = $signature;

	$header[] = 'POST'.$path.'?scope='.$scope.' HTTP/1.1';
	$header[] = 'Content-Type: application/x-www-form-urlencoded';
	$header[] = 'Accept: */*';	
	$header[] = $this->calculateHeader($post).', Content-Type: application/x-www-form-urlencoded ,Host: www.google.com';			
	$ch = curl_init();		
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string1);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_POSTFIELDS, 'scope='.$scope);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
	curl_setopt($ch, CURLOPT_POST,1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	$result = curl_exec($ch);
	curl_close($ch);
}

private static function urlencode_rfc3986($value)
	{
		if(is_array($value)) return array_map(array('Welcome_model', 'urlencode_rfc3986'), $value);
		else
		{
			$search = array('+', ' ', '%7E', '%');
			$replace = array('%20', '%20', '~', '%25');

			return str_replace($search, $replace, urlencode($value));
		}
	}
	
function calculateBaseString($url, $method, array $parameters)
	{
		$url = (string) $url;
		$pairs = array();
		$chunks = array();

		// sort parameters by key
		uksort($parameters, 'strcmp');

		// loop parameters
		foreach($parameters as $key => $value)
		{
			// sort by value
			if(is_array($value)) $parameters[$key] = natsort($value);
		}

		// process queries
		foreach($parameters as $key => $value)
		{
			// only add if not already in the url
			if(substr_count($url, $key . '=' . $value) == 0) $chunks[] = self::urlencode_rfc3986($key) . '%3D' . self::urlencode_rfc3986($value);
		}

		// buils base
		$base = $method . '&';
		$base .= urlencode($url);
		$base .= (substr_count($url, '?')) ? '%26' : '&';
		$base .= implode('%26', $chunks);
		$base = str_replace('%3F', '&', $base);

		// return
//		echo $base;exit;
		return $base;
	}

	
function calculateHeader(array $parameters)
	{
		// redefine
//		$url = (string) $url;

		// divide into parts
//		$parts = parse_url($url);

		// init var
		$chunks = array();

		// process queries
		foreach($parameters as $key => $value) $chunks[] = str_replace('%25', '%', self::urlencode_rfc3986($key) . '="' . self::urlencode_rfc3986($value) . '"');

		// build return
		$return = 'Authorization: OAuth ';
		$return .= implode(',', $chunks);

		// prepend name and OAuth part
//		echo $return;exit;
		return $return;
	}
	
	function urlencodeRFC3986($string)
{
	return urlencode($string);
}

AnswerRe: signature_invalid in Google API Pin
Niall Barr26-Oct-11 3:21
professionalNiall Barr26-Oct-11 3:21 
Questiondata was not displayed in the application in the correct format. Pin
Honeyboy_2025-Oct-11 1:01
Honeyboy_2025-Oct-11 1:01 
AnswerRe: data was not displayed in the application in the correct format. Pin
cjoki4-Nov-11 10:30
cjoki4-Nov-11 10:30 
QuestionBest Practices - mysql calls Pin
Dwayner7920-Oct-11 13:59
Dwayner7920-Oct-11 13:59 
AnswerRe: Best Practices - mysql calls Pin
Mohibur Rashid21-Oct-11 0:02
professionalMohibur Rashid21-Oct-11 0:02 
GeneralRe: Best Practices - mysql calls Pin
Dwayner7923-Oct-11 7:40
Dwayner7923-Oct-11 7:40 
GeneralRe: Best Practices - mysql calls Pin
Mohibur Rashid23-Oct-11 12:05
professionalMohibur Rashid23-Oct-11 12:05 
QuestionUsing MSSQL stored procedure with codeigniter Pin
noadek20-Oct-11 6:43
noadek20-Oct-11 6:43 
QuestionAverage Disk Queue Length In Linux Pin
ReaperDR17-Oct-11 2:52
ReaperDR17-Oct-11 2:52 
JokeRe: Average Disk Queue Length In Linux Pin
Albert Holguin17-Oct-11 4:00
professionalAlbert Holguin17-Oct-11 4:00 
GeneralRe: Average Disk Queue Length In Linux PinPopular
ReaperDR17-Oct-11 15:27
ReaperDR17-Oct-11 15:27 
JokeRe: Average Disk Queue Length In Linux Pin
AspDotNetDev14-Nov-11 10:03
protectorAspDotNetDev14-Nov-11 10:03 
QuestionVisual Studio for PHP!! Pin
Jassim Rahma16-Oct-11 5:00
Jassim Rahma16-Oct-11 5:00 
AnswerRe: Visual Studio for PHP!! Pin
Graham Breach16-Oct-11 5:12
Graham Breach16-Oct-11 5:12 
AnswerRe: Visual Studio for PHP!! Pin
Mohibur Rashid17-Oct-11 18:43
professionalMohibur Rashid17-Oct-11 18:43 
AnswerRe: Visual Studio for PHP!! Pin
User 171649217-Oct-11 22:27
professionalUser 171649217-Oct-11 22:27 
GeneralRe: Visual Studio for PHP!! Pin
Jassim Rahma19-Oct-11 0:11
Jassim Rahma19-Oct-11 0:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.