Jump to content

Recommended Posts

Once you set a session it suppose to stay set, right?

 

<?
   if(!isset($_SESSION))
       session_start();

   $login = htmlentities($_GET['login']);

   if($login == "admin")
       $_Session['admin'] = true;

   $admin = $_Session['admin'];

   echo $_Session['admin'];

       if($admin != true)
           return;
   echo" Welcome Admin!";
?>

 

So for testing purpose I set the admin session to 1 once I use login == "admin".

It sets fine, the I reload the page and I'm not in admin mode,

 

 

Is there more to it or what?

Link to comment
https://forums.phpfreaks.com/topic/272721-session-is-resetting/
Share on other sites

Always been told to put session_start() right at THE VERY TOP of your script. Not sure if that applies in every instance but put it there for now.

<?php
session_start();

$login = htmlentities($_GET['login']);

if($login == "admin")
{
  $_SESSION['admin'] = true;
$admin = $_SESSION['admin'];
echo $admin;
echo "welcome admin!";
}
else{
return;
}
?>

 

Also, you need to always use curly braces '{' when writing more than one statement within an if statement.

 

hope this puts you on the right track.

 

Regards,

 

L2C.

I hope the code you have posted is just a test. Getting someone's 'admin' status from them via a $_GET parameter will allow anyone to become an admin to your site.

 

The only place you should determine anyone's login type and privileges is by having that information stored on the server and you get it based on who the user is.

 

Also, session_start should be unconditional. There's no good reason to start a session only when the session has not already been started.

Edited by PFMaBiSmAd
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.