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
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'];
  }

?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.