discover:
The imeem Media Platform Group
Problem in creation of User Authentication Cookies in php
Rate this thread:
Average Rating:
Not rated


Reply  
 Problem in creation of User Authentication Cookies in php
Posted Jul 29, 2008 at 8:11 AM
Hello Everybody,

Here is the code I am using to sign in the to Imeem. I am having two very strange issues:

1- If i pass apiKey using the following then I got the the response:


4
Invalid signature.



Here is the code:

$method = "usersLogin";
$url = $base_url . $method;
$api_key = "4c905f33-a8b2-4091-9032-54e0bec03e13";
$secret = "a0b123d6-9b77-4948-af21-29252e013cad";

$version = "1.0";
$arrSig = array(
'username'=>,$username
'password'=> $password,
'keepLoggedIn'=> 'true',
);

ksort($arrSig);
$i = 1;
foreach ($arrSig as $key => $val) {
if($i==1){
$para_string = "$key=$val";
}
else{
$para_string .= "&$key=$val";
}
$i++;
}

foreach ($arrSig as $key => $val) {
$sig_string .= "$key=$val";
}
$url = "http://www.api.imeem.com/api/xml/".$method;

$sig_string .= $secret;
$hash_string = $method . $para_string . $secret;
$sig = md5($sig_string);

$query_string = "apiKey=".$api_key."&version=1.0&".$para_string."&sig=".$sig;

$result = do_post_request($url,$query_string);
echo($result);


function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}


2- Secondly If i remove the apikey Like in this code:

$method = "usersLogin";
$url = $base_url . $method;
$api_key = "4c905f33-a8b2-4091-9032-54e0bec03e13";
$secret = "a0b123d6-9b77-4948-af21-29252e013cad";

$version = "1.0";
$arrSig = array(
'username'=>,$username
'password'=> $password,
'keepLoggedIn'=> 'true',
);

ksort($arrSig);
$i = 1;
foreach ($arrSig as $key => $val) {
if($i==1){
$para_string = "$key=$val";
}
else{
$para_string .= "&$key=$val";
}
$i++;
}

foreach ($arrSig as $key => $val) {
$sig_string .= "$key=$val";
}
$url = "http://www.api.imeem.com/api/xml/".$method;

$sig_string .= $secret;
$hash_string = $method . $para_string . $secret;
$sig = md5($sig_string);

$query_string = "version=1.0&".$para_string."&sig=".$sig;

$result = do_post_request($url,$query_string);
echo($result);


function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}

Then I get the message:


0
Success



Which means user is successfully log In but No Cookies created because when i checked user method "usersGetCurrentUser" I am getting the following Response:


103
An imeem user must be logged in to perform this request




If any body could help me out with this. I would grateful.

Thanks & Regards,
Talha
 Problem in creation of User Authentication Cookies in php
Posted Jul 29, 2008 at 8:20 AM
In addition to my above post, I want to mention that i can see both required cookies in my FireFox

under Tools\Options\Privacy\Show Cookies.

Cookies Name:

gamma_fc and an ASP.NET_SessionId

but still when i try using "usersGetCurrentUser" I get the response as :

103
An imeem user must be logged in to perform this request
 Re: Problem in creation of User Authentication Cookies in php
Posted Aug 06, 2008 at 11:15 PM

Without looking at your code dump, I recommend having a quick read of this post from me a while back...

Report Thread as Objectionable

Reply