WordPress.org

Ready to get started?Download WordPress

Forums

Is it safe use wordpress cookie check if user is loggin? (1 post)

  1. youlichika
    Member
    Posted 1 year ago #

    I am secondary development wordpress for a news site.
    I use wordpress only for register/login system and site official blog.
    The news site is use a custom mysql db (out of wp db).

    I find if an empty wp page will cost 13824KB memory. If include the custom mysql query, it will cost neally 15360KB memory. the memory usage is very huge.

    Cause this is a news site, all the data need fresh (30 seconds ago, 1 minutes ago... ), I think wordpress cache plugin is not suit for me.

    I find some way for my situation, check if user is login use cookie. but not sure if it is safe?

    $cookies =  $_COOKIE["wordpress_logged_in_".md5("http://localhost/wp")];
    $exusr = explode('|',$cookies);
    $db = mysql_connect("localhost","root","root");
    mysql_select_db("wp",$db);
    mysql_query("SET NAMES utf8");
    $result = @mysql_query("SELECT user_login FROM wp_users where user_login ='".mysql_real_escape_string($exusr[0])."' limit 1");
    $total = mysql_num_rows($result);
    mysql_close($db);
    if($total>0){
        echo 'hello: '.$exusr[0]);
    }else{
        echo '<a href="http://localhost/wp/login.php"'>Login</a>';//a link to login page.
    }

    this only cost 384kb memory, 2.7% of first.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags