mysql - PHP Globally visible login -


i went through quite few articles , couldnt find looking for. have tried using $globals doesnt work when querying mysql.

the problem have here want username visible on entire page , php files included after username , password confirmed on login screen.

example of mean (password hashing removed simplification):

<?php include('config.php');  global $logged;  $email = $_post["email"]; $globals['email'] = $email;  $password = $_post["password"];  $results = sqlquery("select upassword usertable useremail='$email' limit 1");  foreach ($results $result) {     $cpassword = $result[0][0]; }  if($cpassword === $password) {     echo "login succesful";     $logged = 0;     redirect('index.php', false); } else {     $logged = 1;     echo "incorrect username or password"; } ?> 

==============================

function sqlquery($sql) { global $db_conn; // execute query     $db_result = mysql_query($sql, $db_conn); // if db_result null trigger error if ($db_result === null) {     trigger_error(mysql_errno() . ": " . mysql_error() . "\n");     exit(); } // prepare result array $resultset = array(); // if resulted array isn't true , in case of select statement open loop // (insert / delete / update statement return true on success)  if ($db_result !== true) {     // loop through fetched rows , prepare result set     while ($row = mysql_fetch_array($db_result, mysql_num)) {         // first column of fetched row $row[0] used array key         // more elements in 1 table cell         $resultset[$row[0]][] = $row;     } } // return result set return $resultset; } 

==================

<?php // include config database definition include('config.php');  // start transaction sqlquery('start transaction');  // delete sqlquery('delete sometable');  // accept parameters - p array (suppress errors adding "@" sign) $arr = @$_request['p'];  // if input array exists (in cases except deleting last element) if (is_array($arr)) { // open loop through each array element foreach ($arr $p) {     // detach values combined parameters     // $tbl parameter ignored because saving goes table 1     list($sub_id, $row, $col) = explode('_', $p);     // discard clone id part sub_id     $sub_id = substr($sub_id, 0, 2);     // insert database     sqlquery("insert sometable (sub_id, tbl_row, tbl_col) values      ('$sub_id', $row, $col)"); } }  // commit transaction (sqlcommit function config.php) sqlcommit();  // redirection index.php header('location: index.php'); ?> 

now if use $globals['email'] seen in login name in query: sqlquery("insert sometable (sub_id, tbl_row, tbl_col) values ('$sub_id', $row, $col)"); fail, how can it?

the comment explains globals used for. though should never use globals.

now, question. put session_start() @ top of script. right, after <?php

then, modify block of code.

if($cpassword === $password) {     echo "login succesful";     $logged = 0;     redirect('index.php', false);     $_session['user_email']= (isset($_post['email'])) ? $_post['email'] : false; } 

now, need echo email, can use echo $_session['user_email'] @ time , place in script. long function session_start() available page.

your code , overall logic miss conventions , standards, suggest read php right way. learn stuff.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -