Jump to content


Photo

Code check


  • Please log in to reply
2 replies to this topic

#1 sgiandhu

sgiandhu
  • Validating
  • PipPip
  • Member
  • 13 posts
  • LocationVancouver, B.C. Canada

Posted 20 November 2005 - 01:52 AM

Can someone please check over my DW generated syntax and let me know if I've got the bits all in the right place? I'm mostly concerned about the position of the cookie in relation to both the call for the secure site and the connection...

<?php //made sure we go to the secure server
include_once ('../igosecure.php');

//connect to the DB
 require_once('../Connect/myDB.php'); 

// save the username information for the login form
if (isset($_POST['Login'])) {
    if (isset($_POST['storeprofile'])) {
setcookie("UserName", $_POST['username'], time()+86400*30);
}
else { setcookie ("UserName", "",time()-43200);
}
}

// *** Validate request to login to this site.
session_start();
$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 = "access";
  $MM_redirectLoginSuccess = "https://www.mysite.com/others/theirpage.php";
  $MM_redirectLoginFailed = "login.php?failed=true";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_myDB, $myDB);
      
  $LoginRS__query=sprintf("SELECT username, password, m_access, memberID FROM members WHERE username='%s' AND password='%s'",
  get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
   
  $LoginRS = mysql_query($LoginRS__query, $myDB) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    $loginStrGroup  = mysql_result($LoginRS,0,'m_access');
    
    //declare two session variables and assign them
    $GLOBALS['MM_UserName'] = $loginUsername;
    $GLOBALS['MM_UserID'] = mysql_result($LoginRS,0,'memberID');
    $GLOBALS['MM_UserGroup'] = $loginStrGroup;          

    //register the session variables
    session_register("MM_UserName");
    session_register("MM_UserID");
    session_register("MM_UserGroup");

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
etc etc etc.

If I want to now carry that username cookie over to the next page, do I also need to put in a set cookie command?

Many thanks

J

#2 binime

binime
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 November 2005 - 10:19 AM

session_start should often go straight after the opening php tags

<?php

session_start();

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]If I want to now carry that username cookie over to the next page, do I also need to put in a set cookie command?[/quote]

in your next page

if(isset($_COOKIE['UserName'])) {
echo "welcome back ". $_COOKIE['UserName'];
}
else {
echo "No user cookie found";
}


#3 sgiandhu

sgiandhu
  • Validating
  • PipPip
  • Member
  • 13 posts
  • LocationVancouver, B.C. Canada

Posted 13 December 2005 - 04:08 PM

[!--quoteo(post=322188:date=Nov 26 2005, 02:19 AM:name=binime)--][div class=\'quotetop\']QUOTE(binime @ Nov 26 2005, 02:19 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
session_start should often go straight after the opening php tags

<?php

session_start();
in your next page

if(isset($_COOKIE['UserName'])) {
echo "welcome back ". $_COOKIE['UserName'];
}
else {
echo "No user cookie found";
}
[/quote]


Thanks - working properly now!

Cheers,
Joss




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users