Is there any way to pass the value of a $_SESSION to a link?

Asked

Viewed 45 times

-1

There is a login system with email and password, however, as I already used $_SESSION to capture the session id and the name of the user who is logged in,clicking only on any link that gave access pro inside the site.
The problem is:How to pass the values of these sessions to a variable?

I’m using this redirect to protect the pages:

    if(empty($_SESSION['id'])) {
    ?>
    <script type="text/javascript">window.location.href="login.php"; 
    </script>
    <?php
    exit;
    }     

Therefore, since it is the only thing I need for access to the system to be guaranteed, there is some way to put at least the built-in ID on the link that will be generated later?

2 answers

1


You can print your Session and concatenate as you see fit.

ex print:

<?php echo $_SESSION['id']; ?>

ex concatenate:

www.site.com/id=<?php echo $_SESSION['id']; ?>

or

<?php echo "www.site.com/id=" . $_SESSION['id']; ?>

0

You can use the header(), it would look like this:

header("Location: url_de_redirecionamento?id=$_SESSION['id']")

Browser other questions tagged

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