Saturday, October 3, 2015

starting a php session

starting a php session


starting a php session

Posted: 02 Oct 2015 10:44 AM PDT




Mã PHP:

<?php
session_start
(); // start up your PHP session! 
?>


storing a session variable
Mã PHP:

<?php
session_start
(); 
$_SESSION['views'] = 1// store session data
echo "Pageviews = "$_SESSION['views']; //retrieve data
?>

php sessions: using php's isset function

Mã PHP:

<?php
session_start
();  
if(isset(
$_SESSION['views']))
    
$_SESSION['views'] = $_SESSION['views']+ 1;
else
    
$_SESSION['views'] = 1;

echo 
"views = "$_SESSION['views']; 
?>

cleaning and destroying your session
Mã PHP:

<?php
session_start
();  
if(isset(
$_SESSION['cart']))
    unset(
$_SESSION['cart']); 
?>

Mã PHP:

<?php
session_start
(); 
session_destroy();
?>










----------
Nguồn www.yeuquangngai.net

Auto post into Blogspot using php code?

Posted: 02 Oct 2015 10:37 AM PDT




Mã PHP:

<?php session_start();
    
$email "blogger_email@gmail.com";
    
$pass "password";
    
$blogIDurlencode("blogger_id"); // like 6304924319904337556
 
    // Do Not Modify Below Code
    
if(!isset($_SESSION['sessionToken'])) {
 
    
$ch curl_init("https://www.google.com/accounts/ClientLogin?Email=$email&Passwd=$pass&service=blogger&accountType=GOOGLE");
    
curl_setopt($chCURLOPT_POST,1);
    
curl_setopt($chCURLOPT_FOLLOWLOCATION ,1);
    
curl_setopt($chCURLOPT_HEADER,0);
    
curl_setopt($chCURLOPT_RETURNTRANSFER ,1);
    
$result curl_exec($ch);
    
$resultArray curl_getinfo($ch);
    
curl_close($ch);
    
$arr explode("=",$result);
    
$token $arr[3];
    
$_SESSION['sessionToken'] = $token;
    }
 
    
$entry "<entry xmlns='http://www.w3.org/2005/Atom'>
 
    <title type='text'>Title of blog post </title>
 
    <content type='xhtml'>
 
    This is testing contnetto post in blog post.
 
    </content>
 
    </entry>"
;
 
    
$len strlen($entry);
 
    
$headers = array("Content-type: application/atom+xml","Content-Length: {$len}","Authorization: GoogleLogin auth={$_SESSION['sessionToken']}","$entry");
 
    
$ch curl_init();
    
curl_setopt($chCURLOPT_URL"https://www.blogger.com/feeds/$blogID/posts/default");
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt($chCURLOPT_TIMEOUT4);
    
curl_setopt($chCURLOPT_HTTPHEADER$headers);
    
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    
curl_setopt($chCURLOPT_UNRESTRICTED_AUTH1);
    
curl_setopt($chCURLOPT_POSTtrue);
    
$result curl_exec($ch);
    
$ERROR_CODE curl_getinfo($ch);
    
curl_close($ch);
 
    echo 
'<pre>';
    
print_r($headers);
    
var_dump($result);
    
print_r($ERROR_CODE);
    exit;
 
    
?>










----------
Nguồn www.yeuquangngai.net

No comments:

Post a Comment