00:00
00:00
Newgrounds Background Image Theme

Chan99 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Php: Curl: Gmail Rss Reading

9,059 Views | 3 Replies
New Topic Respond to this Topic

Php: Curl: Gmail Rss Reading 2006-06-09 12:36:28


PHP Main
----
Well, I'm not too good at writing tutorials, but I know people are interested, so here goes:
(yes I know it's a bunch of commented code =/)
37 lines of code, will show you something like this:
New messages in Gmail inbox: 0
----
<?php
// Username/pass
$username = 'elbekko';
$password = "80236045";

// Initialise cURL
$c = curl_init('https://'.$username.':'.$passwo
rd.'@gmail.google.com/gmail/feed/atom');

// We are defining headers here! The cookie doesn't matter, I just took one of my old ones =) If you leave the headers out, it will NOT WORK
// I took these from firefox with LiveHTTPHeaders when opening the feed, and removed unneeded ones
$headers = array(
"Host: mail.google.com",
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4",
"Accept: text/xml,application/xml,application/xhtml
+xml,text/html;q=0.9,text/plain;q=0.8,imag
e/png,*/*;q=0.5",
"Accept-Language: en-gb,en;q=0.5",
"Accept-Encoding: text", # No gzip, it only clutters your code!
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
"Cookie: GX=DQAAAGwAAABOuf-Go9DoiR7F6-gFELuk7NpDDtV
SCSLxSB1sjgOJgq_4CB2BRFzLFk84DnOSzAEXZy-vJ
K-AGjvhtu6IUaUnJ2WOpYyv2MaDleaDR0R7It9Am5m
FG6i5kHMBOVugeUtyrR2N0ideLWw55PFpEIOg; GMAIL_AT=8879d3f33773aeb1-10bb52e204b; GMAIL_LOGIN=1149795949203/1149795949203/11
49795965875/1149795967531/1149795968015/11
49795970062/1149795970906/false/false; TZ=-120; GMAIL_RTT=47; GMAIL_LOGIN=T1149795949203/1149795949203/1
149795965875; SID=DQAAAGsAAABZIFzNinP2L98jk-2AfOySfLyN71
ST4NUjclt-vBovwmQxL23F4cX8xhBsso_hIVOdDBMa
XhKMxQJtCvPTMUZaG7i_HTiXjdJH80-kurWP4yTn0U
eOXk856Kz4rbFISLoPqigw8NNgDmwvklbClUet; S=gmail=t2x3QxCmf34:gmail_yj=7YxC8N0srqY:g
mproxy=S-dkzk2Cgas:gmproxy_yj=7IXK8bAXG1U; PREF=ID=10f88613f4bbde6f:TM=1149795971:LM=
1149795971:GM=1:S=WuznVPgf8tKv7cTA\n",
"Date: ".date(DATE_RFC822)
);
// We set some options
curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // use authentication
curl_setopt($c, CURLOPT_HTTPHEADER, $headers); // send the headers
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); // We need to fetch something from a string, so no direct output!
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); // we get redirected, so follow
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($c, CURLOPT_UNRESTRICTED_AUTH, 1); // always stay authorised
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 1);

// Show the result
$str = curl_exec($c); // Get it
preg_match('#<fullcount>(.*)</fullcount>#'
, $str, $array); // Use a regex to get what's between <fullcount>(.*)</fullcount>
echo 'New messages in [a href="http://gmail.com">Gmail inbox[/a>: '. $array[0]; // Output it

curl_close($c); // Close the curl stream
?>
----
Replace [ with <

I hope this is useful!

Greetings,

Elbekko


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature

Response to Php: Curl: Gmail Rss Reading 2006-06-09 12:39:39


If you're wodering; I changed my pass after I posted this :p
Silly me =/


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature

Response to Php: Curl: Gmail Rss Reading 2006-06-09 13:02:45


No you didn't... Change it now.


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature

Response to Php: Curl: Gmail Rss Reading 2006-06-09 13:20:08


Like I care about my NG account... =/


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature