WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-10-2006, 02:26 PM
freehits's Avatar
WebProWorld Veteran
 

Join Date: Sep 2004
Location: Posse's On Broadway
Posts: 953
freehits RepRank 0
Default php headaches abound

Authentication not working.

LOGIN.PHP
Code:
<?php require_once('Connections/myconn.php'); ?>
<?php

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
  $GLOBALS['PrevUrl'] = $accesscheck;
  session_register('PrevUrl');
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "a_index.php";
  $MM_redirectLoginFailed = "login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_myconn, $myconn);
  
  $LoginRS__query=sprintf("SELECT id,email, password FROM members WHERE email='%s' AND password='%s' and active = 'Yes' ",
    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
   
  $LoginRS = mysql_query($LoginRS__query, $myconn) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
  	//admin type
     $loginStrGroup = "MEMBER";

	$array = mysql_fetch_assoc($LoginRS);
	$GLOBALS['memberID'] = $array['id'];
	
    //declare two session variables and assign them
    $GLOBALS['MM_Username'] = $loginUsername;
    $GLOBALS['MM_UserGroup'] = $loginStrGroup;	

   

    //register the session variables
    session_register("MM_Username");
    session_register("MM_UserGroup");
	session_register("memberID");


    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
	echo "login fail";
  }
}
?>

LOGIN-CHECK.PHP

Code:
<?php
$MM_authorizedUsers = "MEMBER";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  echo "<script>window.location = 'login.php'; </script>";
  exit;
}
?>
RELEVENT OPENING LINES of a_index.php
Code:
<?php 
include('header.php'); 
require_once('myfunctions.php');
require_once('Connections/myconn.php'); ?>
<?php

//debug check
print $_SESSION['memberID'];
print $_SESSION['MM_Username'];
print $_SESSION['MM_Usergroup'];
//

//fetch header
require_once('login_check.php'); 
$currentPage = $_SERVER["PHP_SELF"];


The debug is empty and it appears the session variables are blank and because of that its causing every login attempt to default to hitting this line.
Code:
echo "<script>window.location = 'login.php'; </script>";
I enter tha member and password oon LOGIN.PHP it accepts it successfully and redirects me to 1_index.php, then it goes through the PHP and hits the LOGIN-CHECK.php at which point the seesion variables I believe are empty so it fails the check and sends me back to login.php.

This session junk is not my strong suit and this has wasted my whole morning.

Apreciate any help.
Reply With Quote
  #2 (permalink)  
Old 08-10-2006, 05:44 PM
WebProWorld Pro
 

Join Date: Sep 2005
Location: Manchester, UK
Posts: 257
mikesmith76 RepRank 0
Default

i may have missed it as i only skimmed over your page but i didn't see any calls to session_start() anywhere. I'd say that's at least some of your problem, how can you read session variables from a session that hasn't been started?
Reply With Quote
  #3 (permalink)  
Old 08-11-2006, 09:33 PM
freehits's Avatar
WebProWorld Veteran
 

Join Date: Sep 2004
Location: Posse's On Broadway
Posts: 953
freehits RepRank 0
Default

I remember at one point moving it to an included file, ....

lemme check that out, perhaps it got un-included, Appreciate yout ime in skimming, hope you got it.
Reply With Quote
  #4 (permalink)  
Old 08-11-2006, 09:38 PM
freehits's Avatar
WebProWorld Veteran
 

Join Date: Sep 2004
Location: Posse's On Broadway
Posts: 953
freehits RepRank 0
Default

MO@#THER @#@# DIK@#@# !!!

I had moved it into a custom meta generating include at the top named meta.php, this way it was on top of all relevent pages.

Apparently it got cut but not pasted.
I lost like 3 hours on this.

I really appreciate the fresh perspective and it appears solved.

"The smarter you get the dumber your mistakes"

Which is to say you make the same stupid mistakes over and over, but it gets dumber to do so.

Thanks again.
Reply With Quote
  #5 (permalink)  
Old 08-14-2006, 03:16 AM
WebProWorld Pro
 

Join Date: Sep 2005
Location: Manchester, UK
Posts: 257
mikesmith76 RepRank 0
Default

No problem, glad I could help
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0