我们可以使用javascript检索和设置PHP cookie

I've set a cookie using PHP,

setcookie("redirect", $this->currentPage(), time() + 31536000);  

but I want to retrieve the value of this cookie using javascript when a certain link is clicked. How can I do that?

Yes its possible.

Try this to read cookie:

function getCookie(c_name) {
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++) {
       x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
       y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
       x=x.replace(/^\s+|\s+$/g,"");
       if (x==c_name){
         return unescape(y);
       }
    }
 }

// get cookie foo
var foo = getCookie('foo');

Try this to set a cookie:

/**
 * Sets a cookie
 */
function setCookie(c_name,value,exdays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
   document.cookie=c_name + "=" + c_value;
}

// set a cookie 'foo=bar' for 3 days
setCookie('foo', 'bar', 3);

Cookies are not PHP specific they are browser specific and they can be placed both from PHP and Javascript. For an easy solution, you can look into jQuery's Cookie plugin

Here's another take that attempts to be easier to understand.

Also, since cookies are encoded (both keys and values), you will want to decode them both.

var getCookie = function(name) {

    var thisCookie,
        keyValuePair,
        key,
        value,
        cookies = document.cookie.split('; ') ;

    for ( var i=0 ; i<cookies.length ; i++ ) {
        thisCookie = cookies[i] ; 
        keyValuePair = thisCookie.split('=') ; 
        key = decodeURIComponent(keyValuePair[0]) ; 
        if ( key === name ) { 
            value = keyValuePair[1] ; 
            return (value != null) ? decodeURIComponent(value) : null;
        }
    }
}

Regarding the part about getting the cookie on a link click, you would call this function in an event handler.

Let's assume that you know how to get the link in question in JavaScript. Here's one way to get the first link in the document:

var link = document.querySelector('A') ;

In any case, once you have your link, here is how to get the value when the link is clicked:

var getCookieOnLinkClick = function() {
    var cookieValue = getCookie('cookieName') ;
    console.log('Cookie value is ', cookieValue) ; 
} 

link.addEventListener('click', getCookieOnLinkClick) ;

(Of course, most links will load a new page, so you won't have much time to do anything with the cookie value once you get it.)

Wrong concept. Cookies are stored in browsers. PHP gets/sets browser cookies through HTTP requests and responses. So both PHP and browser JS can manipulate the same cookies.