Jump to content

session var


jagguy

Recommended Posts

Now this needs its own thread because it is confusing.

 

q)I have 2 webapges with password access on a website. I just want to login into once and be able to view both password protected pages .

I dont want to login into every page I load. How do i set this up with session vars or something?

Link to comment
Share on other sites

A simple login script works like this:

 

#1: Have the user enter a username and password

 

#2: Get the username and password using php

 

#3: Validate the username and password (against a database or something like that)

 

#4: If the username and password is valid set a start set a session variable $_SESSION['is_logged_in'] = true;

 

#5: On every page which require the user to be logged you check if($_SESSION['is_logged_in']) {}

 

Note: session_start() should be used on the top of every page which will be accessing the session.

 

Link to comment
Share on other sites

my site needs security and i read that

Note:If you are not experienced with session programming it is not recommended that you use sessions on a website that requires high-security, as there are security holes that take some advanced techniques to plug.

 

 

huh?

Link to comment
Share on other sites

I have 2 pages and i log into 1 but how can i tell the other page i am already logged in? How do i pass the session var and keep it secure from hacking into?

 

I  log into this

 

session_start();

 

$_SESSION['is_logged_in'] = true;

$file="linuxhelp.txt";

 

  echo  "<br> <a href='div4.html?file=".$file."'>file download</a>";

  echo  "<br> <a href='main2.php?is_logged_in=true'>main2</a>";

...

 

 

then i load this page and i cant get it to work if already logged in

 

session_start()

 

if($_SESSION['is_logged_in']) {

 

  $file="linuxhelp.txt";

  echo  "<br> <a href='div4.html?file=".$file."'>file download</a>";

  echo  "<br> <a href='main.php'>main</a>";

}

else {

  echo "not logged in.";

  }

 

Link to comment
Share on other sites

I can't edit mesages previous posts here!

 

q)I have a problem still.

I can work out how to do session vars but I want it to work when the user closes the browser with the website.

If I have another browser open on some other page the session still wont close untill all browsers are closed. I want the session to end when an instance of the browser pointing to the  website is closed.

 

Can I use a session_unset or something?

 

 

 

 

once logged in  i star the session.

--

  session_start();

  $_SESSION['uid']=$log;

  header( "Location: http://localhost/school/test/main.php" );

  exit;

 

 

a page that you can''t access without a login from the other page.

---

session_start();

 

  echo $_SESSION['uid'] ;

if (!isset($_SESSION['uid']))

  {

    echo "not logged in";

  }

  else

  {

 

Link to comment
Share on other sites

I don't understand the problem here.. (maybe because its 2:30am)

Sessions will stay alive until they timeout (set in the php.ini file), as for unsetting the session.. well thats not going to work if the users just closes the window..

 

login.php

<?php
   session_start();
   unset($_SESSION['uid']);
//check username/password if correct then do below
   $_SESSION['uid']=true;
   header( "Location: http://localhost/school/test/private.php" );
   exit;
?>

 

 

private.php

<?php
   session_start();
   if($_SESSION['uid'] === true)
   {
      echo "Woohoo";
      exit;
   }else{
      echo "Sorry no access";
      die;
   }
?>

Link to comment
Share on other sites

Ok say i have 2 browsers open of FF and no tabs. One broswer is on google and the other has got the website logged in. I close the browser and keep the google page open. BY rights I shouldnt be logged in still but because the google page is still up I am. I can still go back and not need to login provided I keep FF open to something.

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.