Re: [PHP] how to assign a value to a variable inside a class

2006-04-11 Thread Jarratt Ingram
If you are using PHP4, you could always

class foo {
  var $var1;
  var $var2;
  var $var3;

 function bar(){
  echo $this-var1.br /;
  echo $this-var2.br /;
  echo $this-var3.br /;
 }
}

then in your code

$foo = new foo();

$foo-var1 = 'blah';
$foo-var2 = 'blah';
$foo-var3 = 'blah';

$foo-bar();

Or you could

class foo {
  var $var1;
  var $var2;
  var $var3;

 function foo($var1='',$var2='',$var3=''){
   $this-var1 = $var1;
   $this-var2 = $var2;
   $this-var3 = $var3;
 }

function bar(){
  echo $var1.br /;
  echo $var2.br /;
  echo $var3.br /;
 }
}

$foo = new foo('blah1','blah2','blah3');
$foo-bar();

Note this will have to be written differently in PHP5 and up using public as
var  has been depreciated and using __construct instead of class name as the
constructor.  The  correct  way to set variables inside a class from user
space code was mentioned before using a set method as it allows the set
function to perform additional checks like type and so on and control is
kept to the class.  This can be tedious as it does add a little more code
but will save you in the long run when incase some developer decides to just
over write one of your variables by accident or not can be difficult to
track down.

HTH
Jarratt










On 4/11/06, Merlin [EMAIL PROTECTED] wrote:

 chris smith schrieb:
  On 4/11/06, Merlin [EMAIL PROTECTED] wrote:
  chris smith schrieb:
  On 4/11/06, Merlin [EMAIL PROTECTED] wrote:
  Hi there,
 
  no much simpler. I do not need to assign the value from outside the
 class. This
  is just inside the class. I have the login data for a database saved
 in a file
  and would like to use simply the variable $DB_login inside this
 class.
 
  This does not work:
 
  $this-db_username = $DB_login;
  That's the right way to do it.
 
  What are you seeing?
 
  --
  Postgresql  php tutorials
  http://www.designmagick.com/
  The following code:
   class search_helper extends AjaxACApplication
   {
  var $db_username;
  $this-db_username  = $DB_LOGIN;
 
  Try it like this:
 
  class search_helper extends AjaxACApplication
  {
var $db_username;
  ...
 
  function SetDBUsername($db_username) {
$this-db_username = $db_username;
  }
 
 
  If you want to set a default:
 
  var $db_username = '';
 
  --
  Postgresql  php tutorials
  http://www.designmagick.com/

 That looks like to much for just assigning value to a variable?!
 I would need 4 of those functions just to set the value of 4 variables to
 a
 value saved inside another variable. If I do understand you right, I would
 also have to call that function inside the class to get that value set?:

   function SetDBUsername($db_username) {
 $this-db_username = $db_username;
   }
   SetDBUsername();

 Is there not something more easy than that. For example $var1 = $var2;

 Merlin

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




[PHP] PDO, Persistent Connections

2006-03-28 Thread Jarratt Ingram
Hi,

I have a little unusual question, we are currently looking into the new PDO
extension with PHP5.1. We are currently use Mysql, InnoDB and transactions.

What we would like to know if we use the PDO extension and persistent
connections, can we start a Transaction on one page and then commit it from
another separate page by carrying the PDO object through a php session? Thus
preventing php from automatically closing that specific DB connection.  The
reason for this we use remote connections to the Database.

Any thoughts or comments if i have missed the boat completely

Regards
Jarratt


Re: [PHP] Environment Variable

2006-03-08 Thread Jarratt Ingram
Hello,

If you are running on apache and have access to either the .conf file or
.htaccess you can use the apache SetEnv directive

eg. SetEnv APPLICATION_ROOT /var/www/html/

and then from php use the $_SERVER['APPLICATION_ROOT'] to access the correct
information

HTH

Jarratt





On 3/7/06, steff [EMAIL PROTECTED] wrote:

 Hello,

 I want to define my own environemnt variable APPLICATION_ROOT and be
 able to retrieve his value from php. As apache module, cgi, cron and
 command line.

 Now i'm just be able to get it from command line. In other
 (module,cgi,cron) when I print $_ENV I never get the same environment :(

 Is it possible to do it with PHP ???

 Thanks.
 Steff

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




Re: [PHP] Environment Variable

2006-03-08 Thread Jarratt Ingram
Sorry i ment to add to my previous email,

you will only be able to access the $_SERVER['APPLICATION_ROOT'] when using
apache and not from Cron or Command line, for that i suppose you could add
the following to the /etc/profile file

APPLICATION_ROOT=/var/www/

and then to the export line

EXPORT .  APPLICATION_ROOT

you will need to run $ source /etc/profile
once have edited that file to make the changes affect the curernt user
logged in. That should also enable you to see it from $_ENV variable.

On 3/7/06, steff [EMAIL PROTECTED] wrote:

 Hello,

 I want to define my own environemnt variable APPLICATION_ROOT and be
 able to retrieve his value from php. As apache module, cgi, cron and
 command line.

 Now i'm just be able to get it from command line. In other
 (module,cgi,cron) when I print $_ENV I never get the same environment :(

 Is it possible to do it with PHP ???

 Thanks.
 Steff

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




Re: [PHP] IP Geographical

2005-08-11 Thread Jarratt Ingram
Hello John 

http://www.ip-to-country.com/ provides a downloadable csv database
that should help you along your way.

HTH

On 8/11/05, John Taylor-Johnston [EMAIL PROTECTED] wrote:
 I have a field in my counter that collects IP addresses. Now the powers
 that be want be to collect that data and sort it geographically etc.
 Is there anyone who has done this? Where would I find some OS code? I've
 heard of it done.
 John
 
 --
 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



Re: [PHP] Login Script

2004-07-20 Thread Jarratt Ingram
Hey Brian, 

how about something like this, just change the session info to cookies
if you want?

?
session_start();
## get db connection
Require_once('../conf/Systemconfig.inc.php');
## Disable DOS Attacks
if ($_SERVER['HTTP_USER_AGENT'] ==  || $_SERVER['HTTP_USER_AGENT'] ==
-) {
die();
}
// If no Post Dont Process Page
If ([EMAIL PROTECTED]){
  @header(HTTP/1.0 404 Not Found);
  $error = 1;
  // Error No Post
  die();
 }

## Process Login
## Run security Checks
if (!get_magic_quotes_gpc()) {
   $User = addslashes($_POST['Username']);
   $Password = addslashes($_POST['Password']);
} else {
   $User = $_POST['Username'];
   $Password = $_POST['Password'];
}

$Result = mysql_query(SELECT * From `site_users` WHERE Username='$User'
AND Password='$Password' AND Visible='1');
if($GetRes=mysql_fetch_array($Result));
{
## Create Session vars and redirect
$_SESSION['AuthUser'] = TRUE;
$_SESSION['AuthName'] = $User;
$_SESSION['AdminID']  = $GetRes['UserID'];
$_SESSION['FirstName'] = $GetRes['FirstName'];
}
else {
$_SESSION['FAILURE']   = TRUE;
}
## Redirect to Main page
@header('Location: index.php');
exit();
?

hth

On Mon, 2004-07-19 at 21:01, Brian Krausz wrote:

 [snip]
 a. do not reply off-list unless asked, your question may not receive the 
 attention it needs
 [/snip]
 Sorry, I got the email before the board post so I assumed you were only 
 replying off-list.
 
 [snip]
 2. You do know basic PHP, correct? Create a page that accepts a username
 and password. Have the un and pw checked against the db. If it is good,
 set a cookie and check for the cookie with each page, if not redirect to
 the proper location.
 [/snip]
 My 2 main concern are security and user-friendlyness.  I would like 
 anyone (regardless of cookies being allowed or not) to be able to use my 
 service, but I would still like it to be secure.
 
 But I guess I'll try making my own script...worth a shot.


Re: [PHP] Parse Error, Unexpected $

2004-07-19 Thread Jarratt Ingram
Hello, 

Try adding the closing brace } to the last else 

  forEach($errors as $error)
  {
  echo $error . 'brbr';
  }
  }
  else
  {
   echo Hi...!; -- 

hth
Jarratt

On Mon, 2004-07-19 at 12:02, Harlequin wrote:

 Jim
 
 I deleted a whole load of lines and still get the error. I've narrowed it
 down to this code:
 
 ?php
 // Verify User Input:
   echo brbrbr;
 
   $requiredFields =
 array('Title','ChristianName','Surname','HomePhone','Address01','City','Post
 code','Country','Gender','WorkPermitRequired','MyStatus');
 
   $errors = array();
   forEach($requiredFields as $fieldName)
   {
 // If using post, change $_GET to $_POST instead
   if (empty($_POST[$fieldName]))
   {
 // The field is empty
   $errors[] = 'Required field ' . $fieldName . ' empty!';
   }
   }
   if (count($errors))
   {
 // Empty fields detected!
   echo Sorry ;
   echo $_SESSION['UserCName'];
   echo brbr;
   echo The Following Fields Require Input ~ Please Go Back.;
   echo brbr;
 
   forEach($errors as $error)
   {
   echo $error . 'brbr';
   }
   }
   else
   {
echo Hi...!;
 ?
 
 But the error (line 40) is actually the last line...! :|
 
 -- 
 -
  Michael Mason
  Arras People
  www.arraspeople.co.uk
 -
 Jim Root [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  I see one problem, but not the one you are talking about.
 
   // Convert Values to Variables:
 $Title = $_POST[Title];
 
  This (and the rest of the post fields) should have quotes:
 
  $Title = $_POST[Title];
 
  (php looks for a constant named Title, instead of the string Title)
 
  What line gives you the parse error?
 
  On Mon, 19 Jul 2004 11:10:09 +0100, Harlequin
  [EMAIL PROTECTED] wrote:
   I've checked my syntax but obviously missing something.
  
   Would anyone mind a quick scan:
  
   // Convert Values to Variables:
 $Title = $_POST[Title];
 $ChristianName = $_POST[ChristianName];
 $MiddleName = $_POST[MiddleName];
 $Surname = $_POST[Surname];
 $HomePhone = $_POST[HomePhone];
 $Address01 = $_POST[Address01];
 $Address02 = $_POST[Address02];
 $Address03 = $_POST[Address03];
 $City = $_POST[City];
 $Postcode = $_POST[Postcode];
 $Country = $_POST[Country];
 $Nationality = $_POST[Nationality];
 $Gender = $_POST[Gender];
 $WorkPermitRequired = $_POST[WorkPermitRequired];
 $MyStatus = $_POST[MyStatus];
  
   // Dump Data Into MembersData:
 $UserDataDump = INSERT INTO MembersData (Title, ChristianName,
   MiddleName, Surname, DOB, TelephoneHome, Address01, Address02,
 Address03,
   AddressCity, AddressPostcode, AddressCountry, Nationality, Gender,
   WorkPermit, Status)
  
  
 VALUES('$Title','$ChristianName','$MiddleName','$Surname','$HomePhone','$Add
  
 ress01','$Address02','$Address03','$City','$Postcode','$Country','$Nationali
   ty','$Gender','$WorkPermitRequired','$MyStatus');
  mysql_query($UserDataDump) or die(Couldn't Create User Data Entry.
 MySQL
   Error:  . mysql_error());
  
   --
   -
Michael Mason
Arras People
www.arraspeople.co.uk
   -
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
  
 
 
  -- 
  Jim Root
  [EMAIL PROTECTED]


[PHP] OOP variables

2004-04-15 Thread Jarratt Ingram
Hello, 

I was wondering if somebody would mind explaining this to me, is there a
big difference or requirement to pre defining variables your going to
use in a class eg: 

class name {
$var1 = '';
$var2 = '';

function blah(){
$var2
}
   }//-- End class  

Or is this also right 

class name {

function name(){

  $this-var1 = ''; 
  $this-var2 = '';
}   
function blah(){

}
}//-- End class


Thanks 
Jarratt

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



Re: [PHP] php and texfield values

2004-02-17 Thread Jarratt Ingram
Hello Angelo

Have you tried, 

tdinput type=text name=company value=? echo
$row['p_company'];?/td

You are missing in your example the closing  tag for the value
parameter. 

regards 
Jarratt



On Tue, 2004-02-17 at 12:52, Angelo Zanetti wrote:
 Say I want to populate a textfield from a resultset and the resultset's
 field has 2 words in it say: mike smith.
 when I echo the value out to the texfields value it only displays mike and
 not mike smith, I cant understand why.
 
 here is my code:
 
 
tdinput type=text name=company
 
   ?  if (!$prospects ==)
   {   echo(value= . $row[p_company]); }?
 
 /td
 
 is the space between mike and smith possibly causing it to only recognize
 the first word as all that is needed. Should i be running some function on
 the returned value or is my code for entering the value of the textfield
 simply incorrect??
 
 TIA
 Angelo
 
 
 Disclaimer 
 This e-mail transmission contains confidential information,
 which is the property of the sender.
 The information in this e-mail or attachments thereto is 
 intended for the attention and use only of the addressee. 
 Should you have received this e-mail in error, please delete 
 and destroy it and any attachments thereto immediately. 
 Under no circumstances will the Cape Technikon or the sender 
 of this e-mail be liable to any party for any direct, indirect, 
 special or other consequential damages for any use of this e-mail.
 For the detailed e-mail disclaimer please refer to 
 http://www.ctech.ac.za/polic or call +27 (0)21 460 3911

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



[PHP] sessions not registering inside a function.

2004-01-23 Thread Jarratt Ingram
Hello All, 

I have created a login system, which works as expected on php 4.2. When
i was asked to move it onto an older server using 4.0.6, the system
stopped registering sessions.

main page: 
? session_start();
   include('PROC_Login.php');   
   login($username,$password);

PROC_Login.php: 

function login($username, $password){
global $HTTP_SESSION_VARS;

// validate user ...

session_register('AuthUser');
$HTTP_SESSION_VARS['AuthUser'] = $username;

do some other stuff ..

}

This code was modified to backdate it to version 4.0.6, and now it wont
register the session. Is it because its inside the function, or to do
with the older version of php?  

If i move it out of the function the session gets registered correctly.

I did try adding session_start() inside the function, in the same
include page. still no luck.

Ideally i would like to keep it inside the function as its more tidier.
any ideas as to why this wont register would be fannytastic.

Thanks 
Jarratt




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



Re: [PHP] sessions not registering inside a function.

2004-01-23 Thread Jarratt Ingram
Thank you John, 

I did manage to get it working by calling global $AuthUser after i ran
the function on the main page and it seems to have resolved the issue. 

have a good weekend 
J

On Fri, 2004-01-23 at 16:38, John W. Holmes wrote:
 From: Jarratt Ingram [EMAIL PROTECTED]
 
  I have created a login system, which works as expected on php 4.2. When
  i was asked to move it onto an older server using 4.0.6, the system
  stopped registering sessions.
 
  main page:
  ? session_start();
 
  function login($username, $password){
  global $HTTP_SESSION_VARS;
  session_register('AuthUser');
  $HTTP_SESSION_VARS['AuthUser'] = $username;
 
  This code was modified to backdate it to version 4.0.6, and now it wont
  register the session. Is it because its inside the function, or to do
  with the older version of php?
 
  If i move it out of the function the session gets registered correctly.
 
 I think you're registering a variable that only has a scope within the
 function. Try adding a global $AuthUser; after global
 $HTTP_SESSION_VARS;
 
 ---John Holmes...

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