OSdata.com: holistic issues 

OSdata.com

example source code
accounts.php

    Building a game — open source code This is the actual source code from a new web game. See the game at thissideofsanity.com and read how this was built starting at example code.

    This is example code from the SlamZee project and This Side of Sanity, released under Apache License 2.0.

    Copyright 2013 Milo (for software), Distribution and website handled by Strazbick.com

    Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

    This narrative uses anchor links so that you can follow the building of this software in chronological order. Go to software explanation to start reading. Go to thissideofsanity.com to see the working software.

Google

example source code
accounts.php

    This is example code from the SlamZee project and This Side of Sanity, released under Apache License 2.0.

account utilities
first pass

    SessionManagement is called near the beginning of processing the main page -- it sets session variables from the cookie. Relies on built-in function, but easy to swap out with something soon.

    CheckValidUser relies on the work of SessionManagement and returns the user name if there is a valid user, otherwise returns the empty string

    GetAccountNumberFromAccountName does exactly what the title says.

    GetAccountNameFromAccountNumber also does exactly what the title says.

<?php

/* FILE NAME /php/accounts.php */

/* these are routines related to accounts so that a website can conveniently swap these out with hooks to their own account management software */

/******************************/
/* SessionManagement                                  */
/* perform session management                    */
/* called from index.php                               */
/******************************/
function SessionManagement()
{

session_start(); /* PHP function */
/* IMPORTANT NOTE: there is NO security on a faked account name in cookie -- must add unique one use codes */

} /* SessionManagement */

/******************************/
/* CheckValidUser                                         */
/* called by index.php                                    */
/******************************/
// returns the email of the account if the session is valid
// otherwise returns empty string
// relies on SessionManagement() already having run

function CheckValidUser()
// see if somebody is logged in and report who it is
{
  global $_SESSION;
  if (isset($_SESSION['valid_user']))
  {
    return $_SESSION['valid_user'];
  }
  else
  {
      return '';
  }  
} /*CheckValidUser */

/******************************/
/* GetAccountNumberFromAccountName        */
/* get info from MySQL database                   */
/* returns actual account number if in DB     */
/* returns zero (0) is not in DB                    */
/******************************/
function GetAccountNumberFromAccountName($acctname)
{

  // fetch visitor id number 
//Connect To Database
$visitorconnection = ConnectCelebDataBase(0); /* located in databasefunctions.php */

// Check If Record Exists
$query = "SELECT accountnumber FROM accounts where accountname = '".$acctname."'";

$visitorresult = mysql_query($query);

if($visitorresult)
  {
    $row = mysql_fetch_array($visitorresult);
    $accountnumber = $row["accountnumber"];
    return $accountnumber;
  } /* END if visitorresult */
else
  {
    return 0;
  } /* END visitorresult */

} /* GetAccountNumberFromAccountName */

/******************************/
/* GetAccountNameFromAccountNumber        */
/* get info from MySQL database                   */
/* returns name on success                          */
/* returns empty string on failure                */
/******************************/
function GetAccountNameFromAccountNumber($acctnumber)
{

  // fetch visitor id number 
//Connect To Database
$visitorconnection = ConnectCelebDataBase(0); /* located in databasefunctions.php */

// Check If Record Exists
$query = "SELECT accountname FROM accounts where accountnumber = '".$acctnumber."'";

$visitorresult = mysql_query($query);

if($visitorresult)
  {
    $row = mysql_fetch_array($visitorresult);
    $accountname = $row["accountname"];
    return $accountname;
  } /* END if visitorresult */
else
  {
    return '';
  } /* END visitorresult */

} /* GetAccountNameFromAccountNumber */

?>

return to explanation of source code

account utilities
second pass

    Created a new account function and modified an existing account function to support the switch from account name to email being the unique identifier. We will now allow duplicate account (screen) names.

/******************************/
/* GetAccountNumberFromEmail                    */
/* get info from MySQL database                   */
/* returns actual account number if in DB     */
/* returns zero (0) is not in DB                    */
/******************************/
function GetAccountNumberFromEmail($email)
{

  // fetch visitor id number 
//Connect To Database
$visitorconnection = ConnectCelebDataBase(0); /* located in databasefunctions.php */

// Check If Record Exists
$query = "SELECT accountnumber FROM accounts where email = '".$email."'";

$visitorresult = mysql_query($query);

if($visitorresult)
  {
    $row = mysql_fetch_array($visitorresult);
    $accountnumber = $row["accountnumber"];
    return $accountnumber;
  } /* END if visitorresult */
else
  {
    return 0;
  } /* END visitorresult */

} /* GetAccountNumberFromEmail */

/******************************/
/* GetEmailFromAccountNumber                   */
/* get info from MySQL database                   */
/* returns name on success                          */
/* returns empty string on failure                */
/******************************/
function GetEmailFromAccountNumber($acctnumber)
{

  // fetch visitor id number 
//Connect To Database
$visitorconnection = ConnectCelebDataBase(0); /* located in databasefunctions.php */

// Check If Record Exists
$query = "SELECT email FROM accounts where accountnumber = '".$acctnumber."'";

$visitorresult = mysql_query($query);

if($visitorresult)
  {
    $row = mysql_fetch_array($visitorresult);
    $email = $row["email"];
    return $email;
  } /* END if visitorresult */
else
  {
    return '';
  } /* END visitorresult */

} /* GetEmailFromAccountNumber */

return to explanation of source code


OSdata.com is used in more than 300 colleges and universities around the world

Find out how to get similar high web traffic and search engine placement.


OSdata.com is used in more than 300 colleges and universities around the world

Read details here.


    A web site on dozens of operating systems simply can’t be maintained by one person. This is a cooperative effort. If you spot an error in fact, grammar, syntax, or spelling, or a broken link, or have additional information, commentary, or constructive criticism, please e-mail Milo. If you have any extra copies of docs, manuals, or other materials that can assist in accuracy and completeness, please send them to Milo, PO Box 1361, Tustin, CA, USA, 92781.

    Click here for our privacy policy.


previous page next page
previous page next page

home page


Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

Viewable With Any Browser


    Names and logos of various OSs are trademarks of their respective owners.

    Copyright © 2013 Milo

    Last Updated: October 3, 2013

    Created: September 9, 2013

previous page next page
previous page next page