codeigniter - Email Contact retrieivng code running well on localhost but not server -


i have following script retrieves code gmail. code runs in localhost, gives error when upload on server , make eun. script made in codeigniter.

<?php class invite_friends extends ci_controller{     var $feed_url = "http://www.google.com/m8/feeds/contacts/default/full";     var $login_url = "https://www.google.com/accounts/clientlogin";     var $username = "my_qmail@gmail.com";     var $passwd   = "my_passowrd";     var $postdata = array();     function __construct() {         parent::__construct();         session_start();     }      function index()     {         if(isset($_session['logged_user']))             redirect(base_url().'home');         $this->load->view('header');         $this->load->view('invite_friends');         $this->load->view('footer');     }           /*function gmailcontacts_lib($gusername, $gpassword) {             //constructor function             $this->username = $gusername;             $this->passwd = $gpassword;         }*/          function get_gmail_contacts() {             $emaillists = array();             //create array post data             $this->postdata = array(                 "accounttype"   => "hosted_or_google",                 "email"         => $this->username,                 "passwd"        => $this->passwd,                 "service"       => "cp",                 "source"        => "anything"             );             //initialize curl object             $curl = curl_init($this->login_url);             //set curl options             $this->set_curl_options($curl, curlopt_post, true);             $this->set_curl_options($curl, curlopt_postfields, $this->postdata);             $this->set_curl_options($curl, curlopt_httpauth, curlauth_any);             $this->set_curl_options($curl, curlopt_ssl_verifypeer, false);             $this->set_curl_options($curl, curlopt_returntransfer, 1);              //following variable contains responses             $response = curl_exec($curl);              //check if user has logged in sucessfully             //and save auth key if logged in             preg_match("/auth=([a-z0-9_\-]+)/i", $response, $matches);             $auth = $matches[1];             if( !empty($auth)) {                 $headers = array("authorization: googlelogin auth=".$auth);                  //make request google contacts feed auth key maximum contacts 10000                 $curl1 = curl_init($this->feed_url);                  //passing headers of auth key                 $this->set_curl_options($curl1, curlopt_httpheader, $headers);                 //return result in variable                 $this->set_curl_options($curl1, curlopt_returntransfer, 1);                  //results response                 $feed = curl_exec($curl1);                 //parse feed , return email list array                 $emaillists = $this->parse_response($feed);             }             else {                 $emaillists = array("invalid username/password");             }             print_r($emaillists);         }          //function set curl options         function set_curl_options($ch, $option, $value) {             //make post true             return curl_setopt($ch, $option, $value);         }          //function parse response         public function parse_response($feed) {             $contacts = array();             $doc = new domdocument();              //load xml response             $doc->loadxml($feed);             //check entry tag             $nodelist = $doc->getelementsbytagname( 'entry' );              foreach($nodelist $node) {                 //children of each entry tag                 $entry_nodes    = $node->childnodes;                 $temparray      = array();                  foreach($entry_nodes $child) {                     //get tagname of child                     $domnodesname = $child->nodename;                     switch($domnodesname) {                         case "title":                             { $temparray['fullname'] = $child->nodevalue; }                         break;                         case "gd:email":                             {                             if (strpos($child->getattribute('rel'),'home')!==false)                                     $temparray['email_1']=$child->getattribute('address');                             elseif(strpos($child->getattribute('rel'),'work')!=false)                                     $temparray['email_2']=$child->getattribute('address');                             elseif(strpos($child->getattribute('rel'),'other')!==false)                                     $temparray['email_3']=$child->getattribute('address');                             }                         break;                     }   //end of switch nodenames                 }   //end of foreach entry_nodes child nodes                 if( !empty($temparray['email_1'])) $contacts[$temparray['email_1']] = $temparray;                 if( !empty($temparray['email_2'])) $contacts[$temparray['email_2']] = $temparray;                 if( !empty($temparray['email_3'])) $contacts[$temparray['email_3']] = $temparray;             }             return $contacts;         }  }  ?> 

it gives error , here error

a php error encountered  severity: notice  message: undefined offset: 1  filename: controllers/invite_friends.php  line number: 54 

i suggest changing code following

if(preg_match("/auth=([a-z0-9_\-]+)/i", $response, $matches)) {     $auth = $matches[1]; } else {     $auth = null; } 

you set $auth null or 0. if set null instead check:

if(!is_null($auth)) { 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -