Login redirect issues

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
apexskier
Forum Newbie
Posts: 3
Joined: Thu Mar 11, 2010 11:11 am

Login redirect issues

Post by apexskier »

Hi there,

I am creating a website with some user functionality and my login page (or sign up or anything like it) is not working. I successfully made another website that worked fine, but something's not working here. My page should direct someone to the homepage if they log in successfully, and the sign up page if they don't but both redirects are not working. Here's the code...

Code: Select all

<?php virtual('/forerunners/Connections/skisite_db.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
mysql_select_db($database_skisite_db, $skisite_db);
$query_login = "SELECT username, password FROM skier_info";
$login = mysql_query($query_login, $skisite_db) or die(mysql_error());
$row_login = mysql_fetch_assoc($login);
$totalRows_login = mysql_num_rows($login);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}
 
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
 
if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "/forerunners/index.php";
  $MM_redirectLoginFailed = "/forerunners/sign-up.php";
  $MM_redirecttoReferrer = true;
  mysql_select_db($database_skisite_db, $skisite_db);
  
  $LoginRS__query=sprintf("SELECT username, password FROM skier_info WHERE username=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $skisite_db) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;       
 
    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
Does anyone know what might be wrong?

I'm very new to php coding and I'm using dreamweaver, so go easy on me if it's a simple mistake.

Thanks!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Login redirect issues

Post by requinix »

Code: Select all

<?php virtual('/forerunners/Connections/skisite_db.php'); ?>
virtual() is an Apache-specific function which is similar to <!--#include virtual...--> in mod_include. It performs an Apache sub-request. It is useful for including CGI scripts or .shtml files, or anything else that you would parse through Apache. Note that for a CGI script, the script must generate valid CGI headers. At the minimum that means it must generate a Content-Type header.

To run the sub-request, all buffers are terminated and flushed to the browser, pending headers are sent too.
That last sentence is especially important. It means you can't use header() anywhere after you use virtual().
pradeepgems
Forum Newbie
Posts: 4
Joined: Thu Mar 11, 2010 10:52 am

pradeepgems Re: Login redirect issues

Post by pradeepgems »

can you post the error message? virtual is a custom funtion that defined by you?
apexskier
Forum Newbie
Posts: 3
Joined: Thu Mar 11, 2010 11:11 am

Re: Login redirect issues

Post by apexskier »

None of this is code I wrote myself. It's all auto generated by dreamweaver. @tasairis, so does that mean I have to take out those header() parts?

Thanks for the help.
Post Reply