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

-1

There is a login system with email and password, however, since I already used $ _SESSION to capture the session id and the user name that is logged in, it would not be a problem to save email and password too, so I would like to do with this login process was automated, just clicking on any link that gave access to the interior of the site. The problem is: How to pass the values of these sessions to a variable?

I'm using this redirect to do page protection:

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

So, since it's the only thing I need for system access to be secured, is there any way to put at least the ID embedded in the link that will be generated later?

    
asked by anonymous 29.08.2018 / 21:01

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']; ?>
    
29.08.2018 / 21:51
0

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

header("Location: url_de_redirecionamento?id=$_SESSION['id']")
    
29.08.2018 / 21:04