Jump to content

[SOLVED] uh,... Sessions, I suck at them


d22552000

Recommended Posts

ok so my first time ever trying to use sessions...  and I suck at it.

 

Normally I simply don't use sessions altogether.  So bear with me.

 

 

      session_start();
      session_register($id);
      header("location: index.php?id=".$id."&pw=".$pw."&s=2");

 

This happens to set the session IF you get your password right.

Do I need to pass a sid or semething to the page for it to get it?

 

I have set the script to generate a 403 error if the session is either invalid or not set.  I goto the page and I get a 403.  How do I set sessions then?

 

      if (isset($_SESSION['$id'])) {

 

That is what checks for the session.. am I doing this all wrong?

Link to comment
https://forums.phpfreaks.com/topic/67776-solved-uh-sessions-i-suck-at-them/
Share on other sites

session_register() has long been depricated. Try this example.

 

p1.php

<?php

  session_start();
  $_SESSION['foo'] = 'hello';
  echo "<a href='p2.php'>p2</a>";

?>

 

p2.php

<?php

  session_start();
  if (isset($_SESSION['foo'])) {
    echo $_SESSION['foo'];
  }

?>

the funny part is this is all one page... but ok :D

 

      if (isset($_SESSION['$id']) && ($_SESSION['$id'] == $pw)) {

 

would that be a better session checker?

 

and I changed my set code to:

 

      session_start();

      $_SESSION['$id'] = $p

 

I might as well put session_start(); at the top of hte page since the whole page is a restartcted area and it has its own login system, all in one php ifle :D

 

Why would I not put session_start at the top of the page?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.