Jump to content

need help with login script


shan2batman

Recommended Posts

hi,

i recently changed my host from openshift to heroku and from then on my problems started to grow. my main conn from dbconfig file is nothing but my login script is able to fetch results yet not able to login tried heroku support it didn't work. So, i decided to try my luck with you php experts to guide me create a connection and make login process easy.

 

here is my db config file:

$url=parse_url(getenv("CLEARDB_DATABASE_URL"));

  $server = $url["host"];
  $username = $url["user"];
  $password = $url["pass"];
  $db = substr($url["path"],1);

 $host= "mysql:host=$server;dbname=$db";

try {
    $conn=new PDO("mysql:host=$server;dbname=$db" , $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

} catch (PDOException $exc) {
    echo $exc->getMessage();
}
//var_dump($url);
var_dump($conn);
echo "<br>";
var_dump($exc);
include 'classes.inc.php';

 //echo "<br>".$db."<br>";
$project= new projecteg($conn);
var_dump($project);

here is my login script:

include_once 'dbconfig.inc.php';
if (isset($_POST['submit-login'])) {
$uname= htmlspecialchars($_POST['unamel']);
$unamel=  stripslashes($_POST['unamel']);
$pass= htmlspecialchars($_POST['passl']);
$pass1= stripslashes($_POST['passl']);
$passl=  md5($pass1);

$user = $project->viewProtectedArea($unamel,$passl);

var_dump($user);
exit();
if ($user!="") {
some conditions ...   
}

here is my output:

object(PDO)#1 (0) { }
NULL object(projecteg)#2 (4) { ["_db":"projecteg":private]=> object(PDO)#1 (0) { } ["query"]=> NULL ["stmth"]=> NULL ["conn"]=> NULL } array(1) { [0]=> array(21) { ["user_id"]=> string(3) "142" ["fname"]=> string(6) "gowri " ["lname"]=> string(7) "shanker" ["uname"]=> string(15) "aboutthecreator" ["pass"]=> string(32) "0c484476449dfd9a8bdf826bee31f03c" ["email"]=> string(21) "gsshanker10@gmail.com" ["phone"]=> string(1) "0" ["avatar"]=> string(25) "TueDec619064920166367.jpg" ["activated"]=> string(1) "1" ["notescheck"]=> string(19) "2017-08-14 14:51:53" ["work"]=> string(22) "inventor, entreprenuer" ["graduation"]=> string(39) "Maharaja arts and science college, cbe." ["school"]=> string(43) "Seventh day adventist, chockikulam, madurai" ["city"]=> string(14) "chennai, india" ["about_me"]=> string(123) "To tell about myself i'm a cool headed guy who loves to take risks and experiment with things if i have something in excess" ["residence"]=> string(18) "I reside in India." ["gender"]=> string(4) "male" ["interests"]=> string(116) "I love Bikes, love to chat, and spend some time on thinking on action plans about problems i face and also in women." ["quote"]=> string(79) "write something worth reading or do something worth reading- Benjamin Franklin." ["privacy"]=> string(1) "0" ["like_person_count"]=> string(1) "1" } }
Link to comment
Share on other sites

here is my code for login page:

<?php   

include_once 'dbconfig.inc.php';
if (isset($_POST['submit-login'])) {
$uname= htmlspecialchars($_POST['unamel']);
$unamel=  stripslashes($_POST['unamel']);
$pass= htmlspecialchars($_POST['passl']);
$pass1= stripslashes($_POST['passl']);
$passl=  md5($pass1);

$user = $project->viewProtectedArea($unamel,$passl);

var_dump($user);
exit();
if ($user!="") {
    
                 $_SESSION['id']=$user['user_id'];
                  $_SESSION['fname']=$user['fname'];
                   $_SESSION['lname']=$user['lname'];
                  $_SESSION['uname']=$user['uname'];
                  $_SESSION['email']=$user['email'];
                  $_SESSION['phone']=$user['phone'];
                  $_SESSION['avatar']=$user['avatar'];
                  $_SESSION['app']=TRUE;
                  $user_ok=TRUE;
                  if (isset($_SESSION[u2])) {
                      header("location: ../home.php?u={$_SESSION['u2']}&v={$_SESSION['uname']}");
                  } else {
                       header("location: ../home.php?u={$_SESSION['uname']}");
                  }
                 



    
}}

if (isset($_SESSION['app'])&&$_SESSION['uname']!="") {
    //echo 'your name is '.$_SESSION['fname'];   
    header("location: ../home.php?u={$_SESSION['uname']}");
                  } else {
                      header("location: ../index.php?usernotfound?id=017");
                  }
 

here is the viewprotected area code from classes file:

 public function viewProtectedArea($unamel,$passl)
                {
                 // $active=1;
                   $stmth= $this->_db->prepare("select * from user where uname=:uname and pass=:pass and activated=1");
                   $stmth->bindValue(":uname",$unamel);
                 $stmth->bindValue(":pass",$passl);
                   $stmth->execute();
                  return $stmth->fetchAll(PDO::FETCH_ASSOC);
               
               
           }
Link to comment
Share on other sites

if this is your "working on past hosting" code, it never worked correctly.

 

the (miss named) viewProtectedArea() method returns an array of row(s). in order to reference the zero'th/only row, you would need to reference $user[0][...].

 

since the query will at most match one row, you should use the ->fetch() method.

Link to comment
Share on other sites

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.