Cookie or Session on Wordpress

0

I created an external page in WP, but I need only that who is logged in to wp-admin can view the page. The external page is not part of the WP, it is a separate page. How would I do this check?

I have found that in the file pluggable.php it seems that it creates a COOKIE ( $_COOKIE[LOGGED_IN_COOKIE] ) . So I did it this way:

Está logado <?php $_COOKIE[LOGGED_IN_COOKIE]; ?>;

But nothing appears.

    
asked by anonymous 11.01.2016 / 20:15

1 answer

0

First do not use $_COOKIE it is not secure. related link

As you said, you are creating an independent page. The first thing you have to keep in mind is:

  

Nothing you have in the other can be availed.

What does it say? Simple, it would be the same as starting something from scratch.

No constant, variable, class, or method of the previous location is known. If it exists, it is by mere coincidence, or because you have the same base project.

That way you have to think:

  

What resources do I have for these applications to communicate?

Some are JSON , cookie , sessão , Arquivo Texto .

In your case the ideal would be session, since it is a communication of independent pages on the same server.

To do this is simple, you can test with two same files.

file1.php

session_start();
$_SESSION['name'] = 'Guilherme Lautert';

file2.php

session_start();
echo isset($_SESSION['name'])?$_SESSION['name']:'Nome não definido';

Explanation

  • In file1.php I sent the session a "key" name with a value.
  • Note that in file2.php I am checking ( isset ) if there is a "key" name in the session, this is either saying that it exists so I would have to handle it it does not exist.

Addendum

  • Remember that session is the same as $_GLOBAL so if you change something in session it will be changing at all.
28.10.2016 / 14:19