Cookie or Session in Wordpress

Asked

Viewed 96 times

0

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

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

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

But nothing shows up.

1 answer

0

First don’t use $_COOKIE he’s not safe. related link

Like you said, you’re creating an independent page.
The first thing you have to keep in mind is :

Nothing that can be taken advantage of.

What does that 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 basic design.

That way you have to think :

What means 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 the file1.php I sent the session a "key" name with a value.
  • Note that in the file2.php I am checking out (isset) if there is a "key in the session" name, That is to say that it exists so I would have to treat for if it does not exist.

Addendum

  • Remember that session is the same thing as a $_GLOBAL then if you change something in the session you will be changing throughout.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.