0

I have spent several hours and for the life of me the $_SESSION will not set. If I apply a value to it directly it works. I have renamed ['username'] in the form and tried various combinations.

<?php

//data security check ip

// include 'functions/getclientip.php';

if(isset($_POST['submit'])){

                                // get post data from login form
                                $getuser = trim(htmlentities($_POST['username']));
                                $getpass = trim(htmlentities(md5($_POST['password'])));

                                if ($getuser&&$getpass){          //check to see if both entered
                                       require('admin_connect.php');   //connect to db

                                        //check db for user match
                                        $query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
                                        $numrows = mysql_num_rows($query);  

                                                if($numrows !== 0){     //check for number of rows

                                                    while ($row = mysql_fetch_assoc($query)) {
                                                              $dbid = $row['id'];
                                                              $dbuser = $row['username'];
                                                              $dbpass = $row['password'];
                                                              $dbstatus = $row['status'];

                                                              $active = "active"; // set to match required status

                                                              if(($getuser === $dbuser)&&($getpass === $dbpass)&&($active === $dbstatus)){   //check for match from POST to db

                                                                  //session_start();
                                                                  $client=$_SESSION['myusername'];

                                                                  // $client=$_SESSION['username']; 

                                                                  //relabel url and send to new page
                                                                      $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
                                                                            if((substr($url, -1)=='/') OR (substr($url, -1) == '\\')) {
                                                                                  $url = substr ($url, 0, -1);
                                                                              }
                                                                      $url .='/loader.php';

                                                                       // header("location: $url");

                                                                        echo $client;
                                                                          exit(); 

                                                              }//check for match from POST to db

                                                    } // mysql_fetch_assoc


                                                }// check number of rows


                                }   // check to see if username and password entered

} // isset submit
?>

remybink
  • 11
  • 2
  • 1
    did you start the *you know what?* – Funk Forty Niner Apr 28 '15 at 23:30
  • I did everything, I commented the session_start when i was trying various things, should have removed it for here, but I swear I have tried and tried - I actually have this working in another site no problem, I am just lost – remybink Apr 28 '15 at 23:32
  • Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Apr 28 '15 at 23:33
  • Notice: Undefined variable: _SESSION in /home/content/94/7423194/html/pmb/platform/login_process.php on line 33 – remybink Apr 28 '15 at 23:34
  • So much for asking for help in a forum designed for that purpose. – remybink Apr 28 '15 at 23:51
  • for anyone like me, who cannot get help on this topic - try this - $client = ($_SESSION['username'] = $dbuser); after lots of trial and error this fixes my issue. Maybe it will for you – remybink Apr 29 '15 at 01:51

0 Answers0