开发者

how to implent cookie-free domain or request?

开发者 https://www.devze.com 2023-02-15 22:49 出处:网络
hello im trying to implant something like static.domain.com where we can put our image without cookie. but the problem is that im serving my image via php. like this

hello im trying to implant something like static.domain.com where we can put our image without cookie. but the problem is that im serving my image via php. like this

public function getIMG( $img )
{
    if ( ! file_exists( "www-static". DS ."assets". DS ."images". DS . $img ) ) {
        throw new Exception( "No such img as $img" );
    }

    $img = "/image-static". DS ."assets". DS ."images". DS . $img;
    echo '<img src="' . $img . '" />';
}

can we still implant them ? maybe using php cookie_set and somehow clear all the cookie ? but im afraid its part together with the sessions if im correct.

here is the request from firebug.

how to implent cookie-free domain or request?

开发者_运维技巧


That is the php session cookie which gets created automatically when using sessions.

See this question on how to disable it.


You can still do something like what you have in your description. The trick is that instead of checking whether an image is in the local file system, you would check whether an image is available on a remote server.

You may want to use something like:

$image_headers = get_headers('http://static.domain.com/image.png'); 
if (false !== strpos($image_headers[0], '200'))
     // echo image tag if the response's status code is 200

Of course, constantly pinging a remote server is a costly process. So you may want to keep a local list of images that are available on static.domain.com

0

精彩评论

暂无评论...
验证码 换一张
取 消