[PHP] GD / Pixel Font Rendering

2008-03-15 Thread nihilism machine
I am trying to render an 8 pixel pixel font without anti aliasing to  
look crisp (silkscreen) in 8pt with gd. the font is huge and ugly:


?php
// Set the content-type
header(Content-type: image/png);

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'silkscreen.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?


-- any ideas?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Sendmail question

2008-03-14 Thread nihilism machine
I have a link that i want to use as the  body of an html email. here  
is the code i use:


// Notify about comments
public function emailComment($Link, $ID) {
$mail = new SendMail();
$mail-SetCharSet(ISO-8859-1);
$mail-from(someone, [EMAIL PROTECTED]);
$mail-to([EMAIL PROTECTED]);
$mail-subject(New Comment!);
	$str = 'a href=http://www.mysite.com/permalink.php?ID='. 
$Link.'Comment ID #'.$ID.'/a';

$mail-text($str);
//$mail-attachment($fileName);
$mail-send();

Where link = a number.

the email that i get is:

So the email should be a link to: http://www.mysite.com/permalink.php?ID=120
but instead links to: http://www.mysite.com/permalink.php?ID%120

Here is the php sendmail library =

?

class SendMail {

public $emailheader = ;
public $textheader = ;
public $textboundary = ;
public $emailboundary = ;
public $charset = ;
public $subject = ;
public $empfaenger = ;
public $attachment = array();
public $cc = array();
public $bcc = array();

public function __construct() {
$this-textboundary = uniqid(time());
$this-emailboundary = uniqid(time());
$this-charset = ISO-8859-1;
}

public function SetCharSet($char) {
$this-charset = $char;
}

public function Validate_Email($emailAddress) {
	if(!preg_match(/[a-z0-9_-]+(\.[a-z0-9_-]+)*@([0-9a-z][0-9a- 
z-]*[0-9a-z]\.)+([a-z]{2,4})/i, $emailAddress)) {

die('Invalid Email Address: '.$emailAddress);
}
return $emailAddress;
}

public function from($name, $email) {
$this-emailheader .= 'From: '.$name.''.$email.''.\r\n;
}

public function to($to) {
$this-empfaenger = $this-Validate_Email($to);
}

public function cc($cc) {
$this-cc[] = $cc;
}

public function bcc($cc) {
$this-bcc[] = $cc;
}

public function makeMimeMail() {
if(count($this-cc)  0) {
$this-emailheader .= 'Cc: ';
for($i=0; $icount($this-cc); $i++) {
if($i  0) $this-emailheader .= ',';
$this-emailheader .= 
$this-Validate_Email($this-cc[$i]);
}
$this-emailheader .= \r\n;
}
if(count($this-bcc)  0) {
$this-emailheader .= 'Bcc: ';
for($j=0;$jcount($this-bcc);$j++) {
if($j  0) $this-emailheader .= ',';
$this-emailheader .= 
$this-Validate_Email($this-bcc[$j]);
}
$this-emailheader .= \r\n;
}
$this-emailheader .= 'MIME-Version: 1.0'.\r\n;
}

public function subject($subject) {
$this-subject = $subject;
}

public function text($text) {
	$this-textheader .= 'Content-Type: multipart/alternative;  
boundary='.$this-textboundary.''.\r\n\r\n;

$this-textheader .= '--'.$this-textboundary.\r\n;
	$this-textheader .= 'Content-Type: text/plain; charset='.$this- 
charset.''.\r\n;
	$this-textheader .= 'Content-Transfer-Encoding: quoted- 
printable'.\r\n\r\n;

$this-textheader .= strip_tags($text).\r\n\r\n;
$this-textheader .= '--'.$this-textboundary.\r\n;
	$this-textheader .= 'Content-Type: text/html; charset='.$this- 
charset.''.\r\n;
	$this-textheader .= 'Content-Transfer-Encoding: quoted- 
printable'.\r\n\r\n;
	$this-textheader .= 'htmlbody'.$text.'/body/html'.\r\n 
\r\n;

$this-textheader .= '--'.$this-textboundary.'--'.\r\n\r\n;
}

public function attachment($fileName) {
if(is_file($fileName)) {
$attachment_header = '--'.$this-emailboundary.\r\n ;
			$attachment_header .= 'Content-Type: application/octet-stream;  
name='.basename($fileName).''.\r\n;

$attachment_header .= 'Content-Transfer-Encoding: 
base64'.\r\n;
			$attachment_header .= 'Content-Disposition: attachment;  
filename='.basename($fileName).''.\r\n\r\n;

$file['inhalt'] = 
fread(fopen($fileName,rb),filesize($fileName));
$file['inhalt'] = base64_encode($file['inhalt']);
$file['inhalt'] = chunk_split($file['inhalt'],72);
$this-attachment[] = 
$attachment_header.$file['inhalt'].\r\n;
} else {
die('ERROR - Invalid Filename: ' . $fileName . \r\n);
}
}

public function send() {
$this-makeMimeMail();
$header = $this-emailheader;

if(count($this-attachment)0) {
			$header .= 'Content-Type: multipart/mixed; boundary='.$this- 
emailboundary.''.\r\n\r\n;

$header .= '--'.$this-emailboundary.\r\n;
 

[PHP] email issue

2008-03-14 Thread nihilism machine

here is my simple email lib: http://pastebin.com/m4d107c01

any idea why in the body i have a link with an = sign that gets  
replaced with a % sign?


-e

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] form cleaner class

2008-02-21 Thread nihilism machine
What is a better idea? Using this class in my db class and using  
CleanInput on the sql statements, or using it in the top of the all  
pages with form input to clean the $_POST's? Also, any ideas or  
comments on improving the class?


?php

class FormCleaner {

// Initializer  
function __construct() {
if (count($_POST)  0) {
foreach($_POST as $curPostKey = $curPostVal) {
$_POST[$curPostKey] = 
$this-CleanInput($curPostVal);
}
}
}

// Clean Form Input
public function CleanInput($UserInput) {
		$allowedtags = b/bi/ih1/h1a/aimgul/ulli/ 
liblockquote/blockquote;
		$notallowedattribs = array(@javascript:|onclick|ondblclick| 
onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress| 
onkeydown|[EMAIL PROTECTED]);

$changexssto = '';
		$UserInput = preg_replace($notallowedattribs, $changexssto,  
$UserInput);

$UserInput = strip_tags($UserInput, $allowedtags);
$UserInput = nl2br($UserInput);
return $UserInput;
}
}

?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] classes

2008-02-18 Thread nihilism machine
if i declare an instance of a class in the top of my php file, then  
have html, then later on user $myClassInstance-myMethod(); --  
myMethod() does not execute, only when i have the instantiation of the  
class right before the call to the method does it work. any ideas?


-e

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] mysql input

2008-02-18 Thread nihilism machine
I have a user saving a VARCHAR(255) field in a mysql db which has  
single quotes in the text, how can i replace them so that they dont  
fuck up my mysql command?


-e

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] upload issue

2008-02-17 Thread nihilism machine
any idea why this fails?this is the error: Sorry, there was a problem  
uploading your file


?php

require_once(classes/db.class.php);

$target = ;
$fileName = basename( $_FILES['uploaded']['name']);
$extension = strtolower(strrchr($fileName,.));
$DB = new DB();
$insertID = $DB-insert_sql(INSERT INTO CMS_Media (File_Name) VALUES  
(''));

$target = media/ . $insertID . $extension;
//echo $target;
if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
// Error
echo File was uploaded!;
} else {
echo Sorry, there was a problem uploading your file.;
}

chmod($target, 0755);

header(Location: crop.php?imageName=$newFileName);

?




---
Edward H. Hotchkiss
Chief Technical Officer
Durgle, INC
[EMAIL PROTECTED]
http://www.durgle.com
---



[PHP] separating strings from extensions

2008-02-17 Thread nihilism machine

i am using this code to get the extension of a filename:

$extension = strtolower(strrchr($fileName,.));

how can i get the text BEFORE the . (period)

?

thanks in advance.

-e

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] https forced redirect question

2008-02-15 Thread nihilism machine
why isnt this redirecting my page to https://www.mydomain.com instead  
the page stays at my domain.com

?php

class URL {

// Public Variables
public $HTTPS;
public $ServerName;
public $WWW;

// Public Functions

public function __construct() {
$this-checkHTTPS();
$this-checkWWW();
$this-ServerName = $_SERVER['SERVER_NAME'];
}

// Check if HTTPS
public function checkHTTPS() {
if ($_SERVER['HTTPS'] != on) {
$this-HTTPS = false;
} else {
$this-HTTPS = true;
}
}

// Redirect to HTTPS Site
public function HTTPSRedirect() {
if($this-HTTPS = false) {
$redir = Location: https://; . $_SERVER['SERVER_NAME'];
echo $redir;
header($redir);
}
}

// Check if site is preceeded by 'WWW'
public function checkWWW() {
 return true;
}

// Redirect to WWW
public function WWWRedirect() {
if ($this-WWW = false) {
$redir = Location: http://www.; . 
$_SERVER['SERVER_NAME'];
header($redir);
}
}

}

$myURL = new URL();
$myURL-HTTPSRedirect();

?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] www. not working

2008-02-15 Thread nihilism machine
this still does not work, if a domain has no preceeding www. it  
redirects to http://www.www.site.com, if it has a www. it goes to www.www.mydomain.com 
, any ideas?


?php

class URL {

// Public Variables
public $ServerName;
public $WWW;

// Public Functions

public function __construct() {
$this-checkWWW();
$this-ServerName = $_SERVER['SERVER_NAME'] . 
$_SERVER['REQUEST_URI'];
}

// Check if site is preceeded by 'WWW'
public function checkWWW() {
$myDomain = $_SERVER['SERVER_NAME'];
$FindWWW = 'www.';
$POS = strpos($myDomain, $FindWWW);
if ($POS === 1) {
$this-WWW = true;
} else {
$this-WWW = false;
}
}

// Redirect to WWW
public function WWWRedirect() {
if ($this-WWW == false) {
$redir = Location: http://www.; . $this-ServerName;
header($redir);
}
}

}

$myURL = new URL();
$myURL-WWWRedirect();

?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] check if website has www. in front of domain

2008-02-15 Thread nihilism machine

here is my function:

// Check if site is preceeded by 'WWW'
public function checkWWW() {
$myDomain = $_SERVER['SERVER_NAME'];
$FindWWW = '.';
$POS = strpos($myDomain, $FindWWW);
if ($POS === false) {
return false;
} else {
return true;
}
}

any idea why this is not working? just trying to test if the site is www.site.com 
 and not site.com


---
Edward H. Hotchkiss
Chief Technical Officer
Durgle, INC
[EMAIL PROTECTED]
http://www.durgle.com
---



Re: [PHP] www. check still not working

2008-02-15 Thread nihilism machine

thank you everyone!

On Feb 15, 2008, at 3:53 PM, Nathan Rixham wrote:


Anjan Upadhya wrote:

  // Redirect to WWW
  public function WWWRedirect() {
  if ($this-WWW == false) {
  $redir = Location: http://www.; .  
$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

  header($redir);
  }
  }
Regards,
Anjan Upadhya
nihilism machine wrote:

?php

class URL {

   // Public Variables
   public $HTTPS;
   public $ServerName;
   public $WWW;
   // Public Functions
   public function __construct() {
   $this-checkWWW();
   }
   // Check if site is preceeded by 'WWW'
   public function checkWWW() {
   $myDomain = $_SERVER['SERVER_NAME'];
   $FindWWW = 'www.';
   $POS = strpos($myDomain, $FindWWW);
   if ($POS === 1) {
   $this-WWW = true;
   } else {
   $this-WWW = false;
   }
   }

   // Redirect to WWW
   public function WWWRedirect() {
   if ($this-WWW = false) {
   $redir = Location: http://www.; .  
$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

   header($redir);
   }
   }
}

$myURL = new URL();
$myURL-WWWRedirect();

?


and

public function checkWWW() {
$this-WWW = (strtolower(trim(substr($_SERVER['SERVER_NAME'],0,4)))  
== 'www.');

}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] www. check still not working

2008-02-15 Thread nihilism machine

?php

class URL {

// Public Variables
public $HTTPS;
public $ServerName;
public $WWW;

// Public Functions

public function __construct() {
$this-checkWWW();
}

// Check if site is preceeded by 'WWW'
public function checkWWW() {
$myDomain = $_SERVER['SERVER_NAME'];
$FindWWW = 'www.';
$POS = strpos($myDomain, $FindWWW);
if ($POS === 1) {
$this-WWW = true;
} else {
$this-WWW = false;
}
}

// Redirect to WWW
public function WWWRedirect() {
if ($this-WWW = false) {
			$redir = Location: http://www.; . $_SERVER['SERVER_NAME'] .  
$_SERVER['REQUEST_URI'];

header($redir);
}
}
}

$myURL = new URL();
$myURL-WWWRedirect();

?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] mysql question

2008-02-10 Thread nihilism machine

i have this functuon:

public function select_one($sql) {
$this-last_query = $sql;
$r = mysql_query($sql);
if (!$r) {
$this-last_error = mysql_error();
return false;
}
if (mysql_num_rows($r) != 1) {
return false;   
}
$ret = mysql_result($r, 0);
mysql_free_result($r);
if ($this-auto_slashes) return stripslashes($ret);
else return $ret;
}


what is $ret, an array? if so how can i access the individual rows in  
it?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] mysql question #2

2008-02-10 Thread nihilism machine

Ok, I read the php.net info. so with this function though:

public function select_one($sql) {
$this-last_query = $sql;
$r = mysql_query($sql);
if (!$r) {
$this-last_error = mysql_error();
return false;
}
if (mysql_num_rows($r) != 1) {
return false;   
}
$ret = mysql_result($r, 0);
mysql_free_result($r);
if ($this-auto_slashes) {
return stripslashes($ret);
} else {
return $ret;
}
}


how can i get the contents of a column in the returned row say for  
something called Email as the column name. here is my code now:


// Attempt to login a user
public function CheckValidUser($Email, $Password) {
$PasswordEncoded = $this-encode($Password);
		$sql = SELECT * FROM CMS_Users WHERE Email='$Email' AND  
Password='$PasswordEncoded';

$result = $this-DB-select_one($sql);
if ($result) {
// User info stored in Sessions
$_SESSION['Status'] = loggedIn;
$_SESSION['ID'] = $row['ID'];
$_SESSION['Email'] = $row['Email'];
$_SESSION['AdminLevel'] = $row['AdminLevel'];
$_SESSION['FirstName'] = $row['FirstName'];
$_SESSION['LastName'] = $row['LastName'];
return true;
} else {
return false;
}
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Better DB Class MySQL

2008-02-09 Thread nihilism machine
Looking to really beef up my DB class, any suggestions for functions  
to add that will be more time saving for a web 2.0 app, or ways to  
improve existing methods? thank you everyone in advance.


?php

class db {

//  Members
public $db_user = ;
public $db_pass = ;
public $db_name = ;
public $db_server = ;
public $link;
public $result_id;

//  Methods
public function __construct() {
$this-connect();
}

// Connect to MySQL Server
public function connect() {
		$this-link = mysql_connect($this-db_server,$this-db_user,$this- 
db_pass) or die(Error: Cannot Connect to DataBase);
		mysql_select_db($this-db_name,$this-link) or die(Error: Cannot  
Select Database ( . $this-db_name .  ));	

}

// MySQL Query
public function query($sql) {
$this-result_id = mysql_query($sql);
return $this-fetch_rows();
}   

// MySQL Query
public function insert($sql) {
$this-result_id = mysql_query($sql);
return $this-select_id;
}

// MySQL Fetch Rows
public function fetch_rows() {
$rows = array();
if($this-result_id){
while($row = mysql_fetch_object($this-result_id)) {
$rows[] = $row;
}   
}
return $rows;   
}

// MySQL Affected Rows
public function num_rows() {
return mysql_num_rows($this-link);
}

// MySQL Affected Rows
public function select_id() {
return mysql_insert_id($this-link);
}

// Disconnect from MySQL Server
public function disconnect() {
mysql_close($this-link);
}

// Terminator Style Function simply in coolness
public function Terminator($tbl) {
}

// Destruct!
public function __destruct() {
$this-disconnect();
}
}

?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] issues with calling methods twice in a row

2008-02-08 Thread nihilism machine

that was just an example. yes they both provide 5 input variables.

On Feb 8, 2008, at 4:18 PM, Jim Lucas wrote:


nihilism machine wrote:
i have a method called CreateUser() which is public and takes 5  
variables as its data, then adds them to a db. it only executes the  
first method not the other although its all the same but the  
variable.


Here you say that the method takes five (5) variables.


ex:
$auth = new auth();
$auth-CreateUser(fake email, 1, fake name, 4);
$auth-CreateUser(fake email, 2, fake name, 4);
$auth-CreateUser(fake email, 3, fake name, 4);
$auth-CreateUser(fake email, 4, fake name, 4);
$auth-CreateUser(fake email, 5, fake name, 4);


But here, you are only putting 4 variables in the method call.

Are you missing something that is required?  The fifth field perhaps?


any ideas? only the first method gets executed?



--
Jim Lucas

  Some men are born to greatness, some achieve greatness,
  and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
   by William Shakespeare



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] issues with calling methods twice in a row

2008-02-08 Thread nihilism machine
i have a method called CreateUser() which is public and takes 5  
variables as its data, then adds them to a db. it only executes the  
first method not the other although its all the same but the variable.


ex:

$auth = new auth();
$auth-CreateUser(fake email, 1, fake name, 4);
$auth-CreateUser(fake email, 2, fake name, 4);
$auth-CreateUser(fake email, 3, fake name, 4);
$auth-CreateUser(fake email, 4, fake name, 4);
$auth-CreateUser(fake email, 5, fake name, 4);

any ideas? only the first method gets executed?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] shopping carts

2008-02-06 Thread nihilism machine
Does anyone know of a shopping cart which allows you to add multiple  
custom fields to each product?

--e

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] shopping carts

2008-02-06 Thread nihilism machine
that does not help, none specify whether they have a custom fields  
option or not.


On Feb 6, 2008, at 4:23 PM, Daniel Brown wrote:

On Feb 6, 2008 4:18 PM, nihilism machine [EMAIL PROTECTED]  
wrote:

Does anyone know of a shopping cart which allows you to add multiple
custom fields to each product?


   http://www.hotscripts.com/
   http://php.resourceindex.com/
   http://www.sf.net/

--
/Dan

Daniel P. Brown
Senior Unix Geek
? while(1) { $me = $mind--; sleep(86400); } ?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] first php 5 class

2008-01-29 Thread nihilism machine
Ok, trying to write my first php5 class. This is my first project  
using all OOP PHP5.2.5.


I want to create a config class, which is extended by a connection  
class, which is extended by a database class. Here is my config class,  
how am I looking?


?php

class dbconfig {
public $connInfo = array();
public $connInfo[$hostname] = 'internal-db.s23499.gridserver.com';
public $connInfo[$username] = 'db23499';
public $connInfo[$password] = 'ryvx4398';
public $connInfo[$database] = 'db23499_donors';

public __construct() {
return $this-$connInfo;
}
}

?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] first php class take 2

2008-01-29 Thread nihilism machine

How does this look now?

?php

class dbconfig {
public $connInfo = array();
public $connInfo[$hostname] = 'host.com';
public $connInfo[$username] = 'dbuser';
public $connInfo[$password] = 'dbpass';
public $connInfo[$database] = 'mydbname';

public __construct() {
return $this-$connInfo;
}
}

?

?php

include_once(dbconfig.class.php);

class dbconn extends dbconfig {

public $DB;

public __constructor(){
$this-$connInfo = new dbconfig();
$username =
$hostname =
$password =
$database =
		$DB = new PDO(mysql:host=$connInfo[$hostname];dbname= 
$connInfo[$database], $connInfo[$username], $connInfo[$password]);

return $DB;
}
}

?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] call to a member function select() on a non object.

2008-01-29 Thread nihilism machine
I amn trying to use my db class in my auth class, but i get the error:  
call to a member function select() on a non object


?php

class db {

//  Members
private $db_user = mydbuser;
private $db_pass = mypassword;
private $db_name = mydb;
private $db_server = myhost.com;
private $link;
private $result_id;

//  Methods
public function __construct() {
$this-connect();
}

// Connect to MySQL Server
private function connect() {
		$this-link = mysql_connect($this-db_server,$this-db_user,$this- 
db_pass) or die(ERROR - Cannot Connect to DataBase);
		mysql_select_db($this-db_name,$this-link) or die(ERROR: Cannot  
Select Database ( . $this-db_name .  ));	

}

// Disconnect from MySQL Server
private function disconnect() {
mysql_close($this-link);
}

// MySQL Select
public function select($sql) {
$this-result_id = $this-query($sql);
if($this-result_id){
$rows = $this-fetch_rows();
}
return $rows;
}

// Insert into MySQL
public function insert($params) {
extract($params);
$sql = 'INSERT INTO '.$table.' ('.$fields.') VALUES 
('.$values.')';
$this-query($sql);
if($this-result_id){
$affected_rows = $this-affected_rows();
}
return $affected_rows;  
}

// Delete from MySQL
public function delete($params) {
extract($params);
$sql = 'DELETE FROM '.$table.' WHERE '.$where;
if (is_numeric($limit)) {
$sql .= ' LIMIT '.$limit;
}
$this-query($sql);
if($this-result_id){
$affected_rows = $this-affected_rows();
}
return $affected_rows;  
}

// Update MySQL
public function update($params) {
extract($params);
$sql = 'UPDATE '.$table.' SET '.$values.' WHERE '.$where;
if(is_numeric($limit)){
$sql .= ' LIMIT '.$limit;
}
$this-query($sql);
if($this-result_id){
$affected_rows = $this-affected_rows();
}
return $affected_rows;
}

// MySQL Query
private function query($sql) {
$this-result_id = mysql_query($sql);
return $this-fetch_rows();
}   


// MySQL Fetch Rows
private function fetch_rows() {
$rows = array();
if($this-result_id){
while($row = mysql_fetch_object($this-result_id)){
$rows[] = $row;
}   
}
return $rows;   
}

// MySQL Affected Rows
private function affected_rows() {
return mysql_affected_rows($this-link);
}

// MySQL Affected Rows
private function num_rows() {
return mysql_num_rows($this-link);
}

// MySQL Affected Rows
private function select_id() {
return mysql_insert_id($this-link);
}

// Destruct!
public function __destruct() {
$this-disconnect();
}
}

?



?php

require_once(db.class.php);

class auth {

public $DB;
public $UserID;
public $AdminLevel;
public $FirstName;
public $LastName;
public $DateAdded;
public $MobileTelephone;
public $LandLineTelephone;

// Connect to the database
public function __construct() {
$DB = new db();
}

// Attempt to login a user
public function CheckValidUser($Email, $Password) {
$PasswordEncoded = $this-encode($Password);
		$rows = $DB-select(SELECT * Users WHERE Email='$Email', AND  
Password='$PasswordEncoded');

if ($DB-num_rows  0) {
$this-UserID = $row['ID'];
$this-AdminLevel = $row['Admin_Level'];
$this-FirstName = $row['First_Name'];
$this-LastName = $row['Last_Name'];
$this-DateAdded = $row['Date_Added'];
$this-MobileTelephone = $row['Telephone_Mobile'];
$this-LandLineTelephone = $row['Telephone_Land_Line'];
// User info stored in Sessions
session_start();
$_SESSION['Status'] = loggedIn;

[PHP] upload issue

2008-01-23 Thread nihilism machine

i am using this code on my form page:

form action=uploadAd2.php enctype=multipart/form-data  
method=post name=adForm id=adForm
input type=hidden name=donorID value=?php echo $_GET['ID']; ? 
 /

input type=hidden name=MAX_FILE_SIZE value=30 /
input type=file name=upload1 /
input type=image src=admin/images/next.png name=Submit  
alt=Submit Form /




my upload code is below:


$uploaddir = 'admin/advertisements/';
$uploadfileTmp = basename($_FILES['upload1']['name']);
$uploadfile = $uploaddir . basename($_FILES['upload1']['name']);
if (move_uploaded_file($_FILES['upload1']['tmp_name'], $uploadfile)) {
$FileName = $uploadfileTmp;
} else {
echo Error!;
exit();
}





my error is:


Internal Server Error

The server encountered an internal error or misconfiguration and was  
unable to complete your request.


Please contact the server administrator, [EMAIL PROTECTED] and  
inform them of the time the error occurred, and anything you might  
have done that may have caused the error.


More information about this error may be available in the server error  
log.


---


any ideas? i have no access to error.log...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] upload problem

2008-01-22 Thread nihilism machine

any ideas why this does not work?


class upload {

function upload() {
upload::uploader();
}

function uploader() {
$FileName = basename($_FILES['upload1']['name']);
if (move_uploaded_file($_FILES['upload1']['tmp_name'], 
$FileName)) {
chmod($FileName, 0755);
rename($FileName, admin/advertisements/ . $FileName);
return $FileName;
} else {
return Error!;
}
}
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] sessions/cookies

2008-01-22 Thread nihilism machine
I wrote an authentication class in php4. The sessions dont seem to be  
working with internet explorer, just with FF. here is the code below,  
a cookies notice pops up when you try and login:


?php



class auth {

var $UserID;
var $AdminLevel;
var $FirstName;
var $LastName;
var $DateAdded;
var $MobileTelephone;
var $LandLineTelephone;

// Connect to the database
function auth() {
		mysql_connect('','','') or die('ERROR: Could not connect to  
database');

mysql_select_db('') or die('ERROR: Could not select database');
}

// Attempt to login a user
function CheckValidUser($Email,$Password) {
$result = mysql_query('SELECT * FROM Users');
$Password = $this-encode($Password);

if (mysql_num_rows($result) != 0) {
while($row = mysql_fetch_assoc($result)) {
if (!strcmp($row['Email'],$Email)) {
if 
(!strcmp($row['Password'],$Password)) {
// User info stored in Globals
$this-UserID = $row['ID'];
$this-AdminLevel = 
$row['Admin_Level'];
$this-FirstName = 
$row['First_Name'];
$this-LastName = 
$row['Last_Name'];
$this-DateAdded = 
$row['Date_Added'];
$this-MobileTelephone = 
$row['Telephone_Mobile'];
$this-LandLineTelephone = 
$row['Telephone_Land_Line'];
// User info stored in Sessions
session_start();
$_SESSION['Status'] = 
loggedIn;
$_SESSION['Email'] = 
$row['Email'];
$_SESSION['AdminLevel'] = 
$row['Admin_Level'];
$_SESSION['LandLine'] = 
$row['Telephone_Land_Line'];
$_SESSION['MobileTelephone'] = 
$row['Telephone_Mobile'];
$_SESSION['FirstName'] = 
$row['First_Name'];
$_SESSION['LastName'] = 
$row['Last_Name'];
return true;
}
}
}
header(Location: index.php?error=invalidLogin);
} else {
die('ERROR: No Users in the database!');
}
}

// Create a new user account
	function CreateUser($Email, $Password, $AdminLevel,  
$LandLineTelephone, $MobileTelephone, $FirstName, $LastName) {

$Password = $this-encode($Password);
$this-AccessLevel = $AdminLevel;
$DateAdded = date(Y-m-d H:i:s);
		mysql_query(INSERT INTO Users (Email, Password, Admin_Level,  
Date_Added, First_Name, Last_Name, Telephone_Land_Line,  
Telephone_Mobile) VALUES ('$Email','$Password','$AdminLevel',  
'$DateAdded', '$FirstName', '$LastName', '$LandLineTelephone',  
'$MobileTelephone')) or die(mysql_error());

return $this-UserID = mysql_insert_id();
}

// Update a users access level
function UpdateAccessLevel($ID,$AdminLevel) {
		mysql_query(UPDATE Users SET Admin_Level='$AdminLevel' WHERE ID= 
$ID) or die(mysql_error());

return true;
}

// Delete a user
function DeleteUser($ID) {
mysql_query(DELETE FROM Users WHERE ID=$ID) or 
die(mysql_error());
return true;
}

// Get a users access level
function GetAccessLevel() {
return $this-AccessLevel;
}

// Get a users ID
function GetUserID() {
return $this-UserID;
}

// Log user out
function LogOut() {
session_start();
session_unset();
session_destroy();
header(Location: index.php);
}

	// Check users access level to see if they have clearance for a  
certain page

function CheckUserLevel($RequiredLevel) {
if ($_SESSION['AdminLevel']  $RequiredLevel) {
if ($_SESSION['AdminLevel'] == 2) {
header(Location: financial.php);
} else if ($_SESSION['AdminLevel'] == 1) {
header(Location: user.php);
} else {

[PHP] forms class

2008-01-21 Thread nihilism machine

Why isnt this cleaning my form $_POST's

class forms {

var $UserInputClean;

// Forms to variables
function forms() {
if (count($_POST)  0) {
foreach($_POST as $curPostKey = $curPostVal) {
$curPostKey = forms::CleanInput($curPostVal);
}
}
// Debug
print_r($_POST);
}

// Clean XSS
function CleanInput($UserInput) {
		$allowedtags =  
strongemaulliprehrblockquoteimgspan;
		$notallowedattribs = array(@javascript:|onclick|ondblclick| 
onmousedown|onmouseup
		.|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown| 
[EMAIL PROTECTED]);

$changexssto = '';
		$UserInput = preg_replace($notallowedattribs, $changexssto,  
$UserInput);

$UserInput = strip_tags($text, $allowedtags);
$UserInput = nl2br($UserInput);
return $this-UserInputClean;
}
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] form cleaning class

2008-01-21 Thread nihilism machine
now my debug shows that with the following code, all of the  
$_POST['whatever'] values are blank.



class forms {

var $UserInput;

// Forms to variables
function forms() {
if (count($_POST)  0) {
foreach($_POST as $curPostKey = $curPostVal) {
$_POST[$curPostKey] = 
forms::CleanInput($curPostVal);
}
}
// Debug
print_r($_POST);
}

// Clean XSS
function CleanInput($UserInput) {
		$allowedtags =  
strongemaulliprehrblockquoteimgspan;
		$notallowedattribs = array(@javascript:|onclick|ondblclick| 
onmousedown|onmouseup
		.|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown| 
[EMAIL PROTECTED]);

$changexssto = '';
		$UserInput = preg_replace($notallowedattribs, $changexssto,  
$UserInput);

$UserInput = strip_tags($text, $allowedtags);
$UserInput = nl2br($UserInput);
return $UserInput;
}
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] $_POST Array and Cleaning

2008-01-20 Thread nihilism machine
I'm trying to create a function that will first take an array of  
$_POSTs and give them key/value pairs like variables. For instance, if  
i had $_POST['whatever'] = whatever, that would be made into  
$whatever = whatever, then i can clean for sql injection and xss.  
any ideas here?


- e

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] POST/GET into variables

2008-01-20 Thread nihilism machine
how does this look? should this by me calling ... myforms = new  
forms(); work by turning all key/value pairs for both get and post  
into variable names of the same name as the get/post key, and the  
variable values as the values from the post/get?


class forms {

// Some stuff
var $MyPosts;
var $MyGets;
var $CleanedInput;

// Connect to the database
function forms() {
foreach($_POST as $curPostKey = $curPostVal) {
CleanInput($curPostKey);
$$curPostKey = $curPostVal;
}
foreach($_GET as $curGetKey = $curGetVal) {
CleanInput($curGetKey);
$$curGetKey = $curGetVal;
}   
}

// Attempt to login a user
function CleanInput($userInput) {
return $this-CleanedInput;
}
}

thanks to anyone in advance

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] POST/GET into variables

2008-01-20 Thread nihilism machine
im trying to keep this php4 OOP. im just trying to clean the post/gets  
and then make them all into variables with their names being the keys  
to the get/post, and their values as the variables values.


ie: $_POST['someFormInputName'] = somevalue ... turns into
$someFormInputName = somevalue.

I am not concerned about cleaning the input as i have a function  
already for that.



On Jan 20, 2008, at 10:06 PM, Nathan Nobbe wrote:

On Jan 20, 2008 9:47 PM, nihilism machine  
[EMAIL PROTECTED] wrote:

how does this look? should this by me calling ... myforms = new
forms(); work by turning all key/value pairs for both get and post
into variable names of the same name as the get/post key, and the
variable values as the values from the post/get?

class forms {

   // Some stuff
   var $MyPosts;
   var $MyGets;
   var $CleanedInput;

// Connect to the database
   function forms() {
   foreach($_POST as $curPostKey = $curPostVal) {
   CleanInput($curPostKey);
   $$curPostKey = $curPostVal;
   }
   foreach($_GET as $curGetKey = $curGetVal) {
   CleanInput($curGetKey);
   $$curGetKey = $curGetVal;
   }
   }

// Attempt to login a user
   function CleanInput($userInput) {
   return $this-CleanedInput;
   }
}

im a little bit lost on the comments about connecting to the  
database and logging
in a user.  if you are writing a class to filter data in the $_POST  
and /or $_GET, then

thats all it should be responsible for.
the decision youll have to make is this; will this class simply act  
as a filter for these
arrays, which means it will modify the data in those arrays, or will  
it leave the contents
of those arrays unaltered and store the filtered values in instance  
variables?  the design

of the class will depend upon this decision.
i think if you want to keep it simple, you should shoot for the  
former option.  then your

class would look something like this

class InputFilter {
public static function filterInput($optionalFilter='') {
if(count($_GET)  0) {
   self::filterArray($_GET, $optionalFilter);
}
if(count($_POST)  0) {
self::filterArray($_POST, $optionalFilter);
   }
}

private static function filterArray($array, $optionalFilter='') {
foreach($array as $key = $value) {
$$key = self::filterValue($value);
if(!empty($optionalFilter)   
is_callable($optionalFilter)) {

$$key = $optionalFilter($$key);
}
}
}

private static function filterValue($value) {
return trim(stripslashes($value));/// -- NOTE: this is  
only an example

}
}


then from client space you would just say
InputFilter::filterInput();

then, subsequently you can use $_POST and $_GET directly with the  
assumption

that the input has been escaped.
and, using the class above, you can also supply a custom filtering  
function as well,

on a per-need basis; eg.

function filterMsql($value) {
return mysql_real_escape_string($value);
}
InputFilter::filterInput('filterMysql');

NOTE: i just typed this into my mail client, so it might not be  
perfect.


-nathan