⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reprofunctions.php

📁 这是国外的resip协议栈
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/*System:  ReproFile:    reprofunctions.phpPurpose: shared functions used by multiple pagesAuthor:  S. Chanin*//* because I don't have a final database abstraction to work with and I don't know how to save db connection state in a cookie (or even if that's possible forall the db's we need to support, I'm going to make every function open and closeit's own connection.  This is inefficient, but at least it's clean. */// shared constants (the alternative for this would be to define them// as constants$provider = "XYZ";$providerEmail = "XYZ Activation <activation@xyz.com>";$sessionDuration = 600;  /* 600 seconds = 10 min *//*Purpose: Used for debugging.  Can pretty print a variable to the browser  or can stuff the pretty printed version in a string (in Broswer format).return values are:  if $return_str is FALSE or not passed: ""  if $return_str is TRUE: the printable representation of the $data*/function dbgShowBroswer($data, $return_str = false, $func = "print_r"){   ob_start();   $func($data);   $output = '<pre>'.htmlspecialchars(ob_get_contents()).'</pre>';   ob_end_clean();   if($return_str) {     return $output;    } else {     echo $output;     return("");   }}/*Purpose: Used for debugging.  Stuffs the pretty printed version in a string into  a string which is returned so it can be stored in a file.return values are:  the storable representation of the $data*/function dbgShowFile($data, $func = "print_r"){   ob_start();   $func($data);   $output = ob_get_contents();   ob_end_clean();   return $output; }/*Purpose: Used for debugging.  Appens a string ($) to the file /tmp/squirt.  Use tail -f /tmp/squirt in a terminal window to watch the output.*/function dbgSquirt($s, $stamp=1) {  $fp = fopen ("/tmp/squirt", "a+");  if ($stamp == 1) {    fputs($fp, date('ymd H:i:s '));  }  fputs($fp, $s."\n");  fclose($fp);}/*Purpose: checks if the supplied user/password combination matches a known user.If so, the state of that user is returned.return values are:    A = matches an active user    U = matches an unverified user    D = matches a disabled user    N = does not match */function validateUser($u, $p) {    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());    mysql_select_db("repro",$db) or die (mysql_error());    $query="select * from Users where username='$u' and password='$p'";    $result = mysql_query($query) or die(mysql_error());        $count=mysql_num_rows($result);        if ($count == 1) {        // we matched, so lets get the state of the user        $state = mysql_result($result,0,"state");    } else {		$state = "N"; }		    mysql_free_result($result);	mysql_close($db);	return $state;}/*Purpose: Used to get the state of a user.  The state will only be returned ifthe function is called with an activationCode that matches the one set for thatuser in the database. return values are:    A = matches an active user    U = matches an unverified user    D = matches a disabled user    N = does not match */function getUserState($user, $code) {    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());    mysql_select_db("repro",$db) or die (mysql_error());    $query="select * from Users where username='$user' and activationCode='$code'";    $result = mysql_query($query) or die(mysql_error());        $count=mysql_num_rows($result);        if ($count == 1) {        // we matched, so lets get the state of the user        $state = mysql_result($result,0,"state");    } else {		$state = "N"; }		    mysql_free_result($result);	mysql_close($db);	return $state;}/*Purpose: Check to see if a user name is already in usereturn values are:    Y = username is in use    N = username is not in useNote -- it is not possible to reuse a user name. */function usernameInUse($u) {    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());    mysql_select_db("repro",$db) or die (mysql_error());    $query="select * from Users where username='$u'";    $result = mysql_query($query) or die(mysql_error());        $count=mysql_num_rows($result);    if ($count == 1) {        // we matched, so that name is in use        $state = "Y";    } else {		$state = "N"; }			mysql_free_result($result);	mysql_close($db);	return $state;}/*Purpose: create a new account in the system.  New accounts are automatically         created in U (unverified) state and have the current date used for 	 the activationDate.return values are:	True = account creation succeeded.	False = account creation failed. */function createAccount($username, $passwordMD5, $fullname, $domain, $email,$activationCode) {    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());    mysql_select_db("repro",$db) or die (mysql_error());    $activationDate = date("Y-m-d");    $query="insert into Users (username,password,fullname,domain,email,state,activationDate,activationCode) values('$username','$passwordMD5','$fullname','$domain','$email','U','$activationDate','$activationCode')";    $result = mysql_query($query) or die(mysql_error());	$count = mysql_affected_rows();	    if ((1 == $count) && (TRUE == $result)) {        // no error and 1 row inserted        $state = TRUE;    } else {		$state = FALSE; }			mysql_close($db);	return $state;}/*Purpose: set a new account to active statusreturn values are:	TRUE = account activation succeeded.	FALSE = account activation failed. */function activateUser($username, $activationCode) {    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());    mysql_select_db("repro",$db) or die (mysql_error());    $activationDate = date("Y-m-d");    $query="update Users set state = 'A' where username = '$username' and activationCode = '$activationCode'";    $result = mysql_query($query) or die(mysql_error());	$count = mysql_affected_rows();	    if ((1 == $count) && (TRUE == $result)) {        // no error and 1 row updated        $state = TRUE;    } else {		$state = FALSE; }			mysql_close($db);	return $state;}/*Purpose: Check to see if the supplied username and email address match a known	 active user (can't do password resets for unverified or disabled 	 users)return values are:    TRUE = username/email combination are a match    FALSE = the combination does not match*/function matchUserAndEmail($username,$email) {    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());    mysql_select_db("repro",$db) or die (mysql_error());    $query="select * from Users where username='$username' and email='$email' and state = 'A'";    $result = mysql_query($query) or die(mysql_error());        $count=mysql_num_rows($result);    if ($count == 1) {        // we matched, so that user/email combination is valid        $state = TRUE;    } else {		$state = FALSE; }			mysql_free_result($result);	mysql_close($db);	return $state;}/*Purpose: Create a new resource for a user.return values are:	TRUE = create succeeded.	FALSE = create failed. */function createResource($username, $aor, $forwardType, $forwardDestination, $voicemail) {    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());    mysql_select_db("repro",$db) or die (mysql_error());    // first we need to get the userid from the username    $query="select id from Users where username = '$username'";    $result = mysql_query($query) or die(mysql_error());    $count=mysql_num_rows($result);    if ($count == 1) {      // we matched, so lets get the userid of the user      $userid = mysql_result($result,0,"id");      mysql_free_result($result);              // if there are any constraints (e.g. AOR must be unique, etc, check      // for them here		      // add the resource to the Resources table      $query = "insert into Resources (userid,aor,forwardType,forwardDestination,voicemail) values($userid,'$aor','$forwardType','$forwardDestination','$voicemail')";		      $result = mysql_query($query) or die(mysql_error());      $count = mysql_affected_rows();	      if ((1 == $count) && (TRUE == $result)) {        // no error and 1 row inserted	$state = TRUE;      } else {	$state = FALSE; }    } else {      $state = FALSE; }    mysql_free_result($result);    mysql_close($db);    return $state;}/*Purpose: Looks up other info tied to a user. Since arguments are passed by reference, they are set to the values returnedby the select.  The functions return value is used to indicate whether executionsucceed or failed.return values are:	TRUE == lookup suceeded.	FALSE == error during lookup*/function lookupUserInformation($username,&$id,&$fullname,&$domain,&$email) {    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());    mysql_select_db("repro",$db) or die (mysql_error());    $query="select * from Users where username='$username'";    $result = mysql_query($query) or die(mysql_error());        $count=mysql_num_rows($result);        if ($count == 1) {        // we matched, so lets get the state of the user        $id = mysql_result($result,0,"id");        $fullname = mysql_result($result,0,"fullname");        $domain = mysql_result($result,0,"domain");        $email = mysql_result($result,0,"email");        $state = TRUE;    } else {		$state = FALSE; }		    mysql_free_result($result);	mysql_close($db);	return $state;}/*Purpose: Builds an associative array containing all the resources associated		 with a username.  This is extra work, but it should isolate any dependency		 on mysql here and allow the function to be re-implemented for other		 databases without affecting the surrounding code.		 return values are:	TRUE == lookup succeeded	FALSE == lookup failed*/function getResourcesByUsername($username,&$resources) {    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());    mysql_select_db("repro",$db) or die (mysql_error());    // first we need to get the userid from the username    $query="select id from Users where username = '$username'";    $result = mysql_query($query) or die(mysql_error());    $count=mysql_num_rows($result);    // print "Query -- $query<br />\nCount -- $count<br \>\n";        if ($count == 1) {        // we matched, so lets get the userid of the user        $userid = mysql_result($result,0,"id");        mysql_free_result($result);                $query = "select id,aor,forwardType,forwardDestination,voicemail from Resources where userid = '$userid'";        $result = mysql_query($query) or die(mysql_error());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -