Re: [PHP] Using PHP to get a word count of a MSword doc

2003-03-19 Thread Erik Price


Brad Wright wrote:
Erik, 
thanks, are you able to pint me to some good reference sources on
tokenizer's... i have never come across them before

I have been scouring the web, and am coming up a decided blank. :)
The only tokenizers I have used are the StringTokenizer and 
StreamTokenizer classes in Java.  If you want to learn about these, go 
to this web page: http://www.mindview.net/Books/TIJ/ and download the 
book Thinking in Java.  Chapter 9 is the chapter that covers File I/O 
and discusses how to use them.  I have a feeling that the PHP tokenizers 
work very similarly to the Java one (just judging from the docs on the 
PHP site).

Good luck,

Erik

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


Re: [PHP] complicated but fun, please help.

2003-03-18 Thread Erik Price


Daniel McCullough wrote:
Yes sorry for not being clear.   I am trying to use exec() and system().
I guess I'm trying to see if there is another way to do it, like write 
to a file and have acron job run every minute or so, or if there is some 
way to make it seem like I am doing this with the right permissions.
That sounds like a good plan.



Erik

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


Re: [PHP] Question about a text file and foreach

2003-03-18 Thread Erik Price


Jim Greene wrote:
Hi All,
I have a text file that has entries like the following:
user1:mbox1:
user1:mbox2:
I basically do: $mboxs = `cat file | grep user1 | cut -d: -f2';
I then want to print out the data in the $mboxs variable (array)
I am trying to use foreach but it does not work..  I am assuming the data is not 
considered an array?
I might be mistaken, but wouldn't the value of $mboxs just be a string 
containing those characters?  If you meant to use backticks to open up a 
shell pipe, I /think/ that's something you can do only in Perl.  You can 
do it in PHP with the system() function, but it doesn't return an array 
but rather a string.  You can parse the string into an array with 
string-processing functions.

Erik

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


Re: [PHP] Authentication

2003-03-18 Thread Erik Price


Beauford.2002 wrote:
I am looking for a simple authentication script that uses MySQL. I have
downloaded about 10 of them (most with no instructions on it's use), but
even at that they are not what I need.
The PEAR project has 7 different authentication packages, including Auth 
which I understand lets you design your own.  PEAR code tends to be 
widely used and well-tested.  Also there is a mailing list similar to 
this one dedicated to discussion of and support for PEAR projects.

http://pear.php.net/packages.php?catpid=1catname=Authentication

When you go to the main page of my site it will ask you to login or signup.
So I want to be able to authenticate the user if he logs in (not to much of
a problem here, but I want to protect all pages (I don't want to use cookies
as not everyone has these enabled). What other options do I have? If anyone
knows a small script that can be modified, or point me in the right
direction of how to do this, it would be appreciated.
If you really want to reinvent the wheel, write an include file that is 
included onto every page of your site except your login page and the 
ones that you don't need to protect.  This include file should check for 
a flag that indicates whether or not the user is logged in.  If the user 
is not logged in, send a redirect header to the login page followed 
immediately by an exit() call.  This way none of your scripts will be 
accessible without the user being logged in.  To handle the login, the 
simple way to do it is to accept a username and password input from the 
user on the login screen and ship these to the database or wherever your 
user list is kept and test to see if they are valid.  If they are valid, 
set the flag in the user's session indicating that they are logged in 
(which is checked by the include file).  For maximum security, use SSL 
and beware the possibility of session hijacking.  If you don't want to 
use cookies, you can either embed the SID in all hyperlinks of your site 
or just recompile PHP with the --enable-trans-sid flag (unless you're on 
PHP 4.2 or greater).

Erik

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


Re: [PHP] Sorting Recordset by a calculation between 2 Records

2003-03-18 Thread Erik Price


Vernon wrote:
I am calculating distances between to record's zip codes using php and have
a need to sort the recordset by that value. How do I do something like this?
I mean it's not a value in the table that I can use the SQL ORDER BY
statement. I want to be able to have the distances closest to the individual
first.
When you say using php I'm assuming that this means you are not doing 
the calculation at the database, but rather in your PHP code.  Use the 
distance you've calculated as the numeric index of an array, pointing to 
the record that corresponds to that distance.



Erik

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


Re: [PHP] Sorting Recordset by a calculation between 2 Records

2003-03-18 Thread Erik Price


Vernon wrote:

Use the distance you've calculated as the numeric index of an array,
pointing to

the record that corresponds to that distance.


Can you please expalin this statement? Perhaps a tutorial somewhere?
I could explain it better if you could post the code that you have so 
far which extracts the records from the database.  In other words, it's 
hard for me to explain it without seeing your records' structures.  I 
don't know of a tutorial on this, when you see what I'm talking about 
you'll realize it's kind of basic.

Erik

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


Re: [PHP] php auth instead of .htaccess

2003-03-18 Thread Erik Price


Bryan Koschmann - GKT wrote:
Hello,

I have gotten used to using .htaccess to protect files/directories, but
now I am looking at a need to authenticate against mysql. I have no
problem actually getting it to authenticate, but I'm wondering what the
simplest way to prevent someone from hitting anything other than the main
page (and not needing authenticate) without having to login at every page.
I'm assuming I would use something with sessions. Does anyone have a quick
sample of how to do this?
Yes, create a session variable using this syntax:

$_SESSION['logged_in'] = false;

Then authenticate the user.  If the authentication succeeds, then change 
the variable's value to true.

$_SESSION['logged_in'] = true;

Now on every page except your login page, test for the session variable 
before displaying the page.  If it's present and valid, display the page 
as usual, if not, redirect to the login page.

if (isset($_SESSION['logged_in']) 
$_SESSION['logged_in'] == true) {
  // display page
}
else {
  header(Location: http://domain.com/login;);
  exit(Sorry, you are not logged in.);
}
The details are all in the manual under Sessions and Session-related 
functions.

Erik

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


Re: [PHP] PHP Processing Order || Function Calls

2003-03-18 Thread Erik Price


CF High wrote:
Hey all.

I was under the impression that PHP processes all php code first before
handing HTML processing over to the browser.
http://www.php.net/manual/en/ref.outcontrol.php



Erik

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


Re: [PHP] Sorting Recordset by a calculation between 2 Records

2003-03-18 Thread Erik Price


vernon wrote:
I think that maybe I should explain the fist Zip comes from a session, here 
I've defined the variable. I use the caluation in the code to get the 
distance and then loop the recordset so that the distance is created each 
time the record loops through. I have taken many things from the file and am 
only looking for what we discussed, to sort the records by distance.
I see.  When you have a collection of items, the best place to put them 
is in an array.  I assumed that you were going to be putting them into 
an array anyway, so my solution simply explained a different way of 
putting them into an array so that you would easily be able to determine 
the distance if given any element in the array.

There might be ways to solve your problem without using arrays, but I 
wouldn't waste any time investigating them.  Use arrays for this, that's 
why they exist.

I've CC'd this back onto the list since this kind of discussion can be 
helpful for others who are learning too.

Erik

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


Re: [PHP] nstalling PHP

2003-03-18 Thread Erik Price


Marc Bakker wrote:
Hello all,

I installed PHP, Apache and MySQL. I read the install.txt file that came
with php and changed the default values in php.ini and httpd.conf. When I
restart Apache and type my local website (127.0.0.1/index.php) IE comes with
a 'Save file As' dialog box.
Instead of parsing the php code and returning html code, Apache returns the
index.php file!
Does the AddType line in httpd.conf so that files ending with the 
extension .php are processed by the PHP binary?  You should have a 
section in your httpd.conf that looks something like this:

IfModule mod_mime.c
  # a bunch of lines go here
  # a bunch of lines go here
  # a bunch of lines go here
  # a bunch of lines go here
  # a bunch of lines go here
  AddType application/x-httpd-php .php .php3 #--- you need this line
/IfModule


Erik



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


Re: [PHP] Using PHP to get a word count of a MSword doc

2003-03-18 Thread Erik Price


Brad Wright wrote:
Thanks for the reply Rene,

Any change of a code sample of how u did this?? Im not at all experienced in
Java.
According to the manual, PHP does have some tokenizer functions:

http://www.php.net/manual/en/ref.tokenizer.php

However, the documentation appears to be lacking as they are still under 
development.  Using it might be somewhat straightforward if you are 
accustomed to using a tokenizer in another language (like Java) but if 
not, it's really a little too difficult to explain in an email.

A less elegant but ultimately quicker and probably more reliable 
solution might be to investigate some kind of external word-counting 
program that knows how to parse .DOC files (good luck on that part), and 
call this from your PHP script using system().  Catch-22: the only 
libraries I am familiar with that can parse .DOC files are the Jakarta 
POI libraries, which are written in Java.  But I am sure that if you 
scour the web you can find some Perl, Python, or maybe even PHP-based 
solution.

Erik

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


Re: [PHP] sorting results in PHP

2003-03-17 Thread Erik Price


bill wrote:
Hi André,

Sorting like that doesn't get it sorted by date.  Each row has a lot of fields.  It
actually needs to be sorted three times by three fields, Year, Month, and Day.
Because the query uses a GROUP BY statement, I can't sort it in the query.
MySQL offers a DATE column type.  You can extract a day, year, or month 
from this, without having to maintain three separate tables, using 
DATE_FORMAT.  You can also sort by DATE in the query.  Would this not be 
better for your situation?

Erik

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


Re: [PHP] A faster way to Redirect pages

2003-03-17 Thread Erik Price


Poon, Kelvin (Infomart) wrote:

I know this topic was discussed but I deleted my previous mail so I can't go
back and review them.
STFA:  http://marc.theaimsgroup.com/?l=php-general

My question is, is there a faster way to redirect
html pages other than just using  meta HTTP-EQUIV=REFRESH CONTENT=1;
URL=login.php ?  Is there any way we can do that in php so that it
redirect FASTER?  Right now I set the redirect time to be 1 sec, but for
some reason it still takes kind of long until it actually redirects, I was
wondering if there is any other way I can do this faster.
Yes, check out the header function.  You will pass it a string argument:

  $my_url = http://php.net/header;; // your URL goeth here
  header(Location: $my_url);
Note that you have to call header /before/ you send output to the browser.



Erik

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


Re: [PHP] Working with dates

2003-03-17 Thread Erik Price


Brad Harriger wrote:
I have two variables, $StartDate and EndDate that contain values read 
from MySQL Date fields.  How can I determine if a value entered by the 
user is between the two dates?  I'm using PHP 4.0.6.
if ($user_input  $StartDate 
$user_input  $EndDate) {
// do something
}


Erik

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


Re: [PHP] Looking at individual chars of string

2003-03-17 Thread Erik Price


Bix wrote:
Is it possible to look at individual chars of a string?

eg: $str = 12345;

print $str_1 // Gives 1
print $str_2 // Gives 2
Try this:

  print $str{0}; // gives 1
  print $str{1}; // gives 2


Erik

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


Re: Fw: [PHP] Looking at individual chars of string

2003-03-17 Thread Erik Price


Kevin Stone wrote:

Actually as far as the computer knows strings *are* arrays.  Access any
character within a string in the same mannor as you would access an element
in an array.  For example:
$str = hello world;
echo $str[4]; // prints o
echo $str[6]; // prints w
That works but is deprecated.  Use curlies.

http://www.php.net/manual/en/language.types.string.php#language.types.string.substr



Erik

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


Re: [PHP] What is the difference: include()

2003-03-17 Thread Erik Price


Charles Kline wrote:
What is the difference as in... why one or the other?

include('somefile.php');

include(somefile.php);

Just wondering...
If you had a constant named somefile or php and you use the second 
syntax, the constant would be interpolated/evaluated to the value of the 
constant.

Generally I always use single quoted strings unless there's some need 
for double-quoted strings (like if I want to embed a variable) so 
something like this can't happen.

Also good idea to only use capital letters for constants.



Erik

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


Re: [PHP] What is the difference: include()

2003-03-17 Thread Erik Price


Erik Price wrote:

If you had a constant named somefile or php and you use the second 
syntax, the constant would be interpolated/evaluated to the value of the 
constant.

Generally I always use single quoted strings unless there's some need 
for double-quoted strings (like if I want to embed a variable) so 
something like this can't happen.
BTW, I'm talking out my butt here, but it might be true.  The advice is 
still sound, regardless.



Erik

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


Re: [PHP] What is the difference: include()

2003-03-17 Thread Erik Price


CPT John W. Holmes wrote:

Well, the first part is out your butt... :)

Yep.  I tested it after making the assumption, sure enough I was WRONG. 
 I've got to keep my butt under control, it's getting a little out of hand.

To the OP, sorry 'bout that.

Erik

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


Re: [PHP] copy ...

2003-03-17 Thread Erik Price


John Taylor-Johnston wrote:
Captn John,
What the difference? I recognise the code from my attempts at Perl. What's the diff 
between ^ and *? Is there a doc I can read up more on?
;) Swabbie John
Cpt John W. Holmes wrote:


What about

eregi(TI(.*)¶,$line,$m)

might want to use

eregi(TI([^¶]*)¶,$line,$m)
The first one says eat TI then any number of characters until you get 
to the last ¶ in the target string, then eat that one too and stop 
there.  The second one says eat TI and then any number of characters 
that isn't a ¶, then when you finally get to one, eat it too but stop 
there.

As for your doc, the definitive guide is 
http://www.oreilly.com/catalog/regex2.  No, it's not a free web page 
somewhere, but it /will/ make you a master of regexes, something you can 
carry across all languages (except Perl6 :).  I count it as possibly the 
most useful book I've ever read.

Erik

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


Re: [PHP] Loop Problem

2003-03-17 Thread Erik Price


[EMAIL PROTECTED] wrote:
Ok, here's what I got.  I'm trying to create an entire site that grabs 
all it's information (Page content, titles, link info, etc.) from a 
MySQL database.  In this site I would like to have sub pages of master 
pages.  For instance, Page 1 is a master page, Page 2 is a sub page of 
Page 1, and Page 3 is a sub page of Page 2 which is a sub page of page 
one.  Now I would like to display this entire hierarchy if possible.  
Here's what I have but either I get an infinite loop or it doesn't work 
worth a damn

?
mysql_connect(127.0.0.1,webuser,);
$query=SELECT * FROM PageInfo WHERE PageID'0' and PageID=$MasterPage 
ORDER BY PageID;
I might be mistaken, but it looks like $MasterPage hasn't been defined 
at this point.  This should be giving you an error.  ($MasterPage gets 
defined later, but...)  If you have your error-reporting turned off, it 
might not throw the error, so you are getting all the way to your DB. 
Try turning your error-reporting up and seeing if this causes you problems.

The other thing is I don't understand your query -- why are you 
selecting where PageID is greater than something and at the same time 
where it is equal to something else?  That is redundant.  Finally, in 
your query, remove the single quotes around the 0.  You don't need them, 
and it may be asking MySQL to treat the 0 as a character or string 
rather than an integer (and the column type is an integer).  I'm not 
really definite on that last one though (more talking out the butt, I 
suppose).



Erik

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


Re: [PHP] complicated but fun, please help.

2003-03-17 Thread Erik Price


Daniel McCullough wrote:

Where I am having problems at is when they need to update the poppasswd, 
which is a IMAP or QMAIL file.  Plesk has files that will update the 
system, but it seems that I using the exec() and system() I can access 
those pl files.  From the command prompt it works fine, html/php file 
doesnt work.  Any thoughts?  I would really appreciate the help, I'm 
doing this as a favor and would like to clear this off my plate.
You probably are logged into the command prompt as a different user than 
what the PHP binary runs as.  If the PHP binary runs as a user named 
apache, and you log in as dmcullough or root, and the commands you 
are trying to execute are restricted only to being run by dmcullough 
or a group that dmcullough is in but apache is not, then PHP won't 
run them.

I'm assuming that you are using the system() or exec() commands, your 
email is a little difficult to understand in that respect... sorry.

Erik

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


Re: [PHP] How to break out of nested loops

2003-03-17 Thread Erik Price


Bix wrote:
I have a for loop within a for loop, and need to break out of both
together...
for ( blah ) {
 for ( blah ) {
  if ( true ) { break; } // only breaks out of this loop, how can I break it
out of both loops.
 }
}
break accepts an optional numeric argument which tells it how many 
nested enclosing structures are to be broken out of.

from http://www.php.net/manual/en/control-structures.break.php

Erik

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


[PHP] function getting redeclared

2003-02-18 Thread Erik Price
Hi,

I have a problem where I am getting the following error, and I was 
wondering if anyone has seen this one before and can help me out.

Fatal error:  Cannot redeclare isvalidphonenumber() (previously 
declared in /home/bluekomo/public_html//classes/Registrant.class:360) 
in /home/bluekomo/public_html//classes/Registrant.class on line 360

I have a script, registration.php, which calls require_once on the 
Registrant.class file mentioned in the above error message.  The 
Registrant::setPhone() method is called more than once.  Since it is 
called more than once, the function isValidPhoneNumber() defined 
within setPhone() is defined more than once, which I suspect is the 
source of the problem.  Does PHP not allow you to define a function 
within a function and then call the enclosing function more than once?  
Here is the relevant section of code:

354 /**
355  * sets the phone property
356  */
357 function setPhone($phone) {
358 // TODO: determine if these formats are acceptable
359 // TODO: account for extensions (separate form field?)
360 function isValidPhoneNumber($num) {
361 $valid = false;
362 if (preg_match('!\d{9,9}!', $num)) {
363 $valid = true;
364 }
365 if (preg_match('!\(?\d\d\d\)?-?\s*\d\d\d-?\s*\d\d\d\d!',
366 $num)) {
367
368 $valid = true;
369 }
370
371 return $valid;
372 }
373
374 if (isValidPhoneNumber($phone)) {
375 $this-phone = $phone;
376 }
377 }


I am using PHP 4.3.0 on a RedHat machine with Apache 1.3.x.

Thanks for your help, it's been a while since I've used PHP!


Erik







--
Erik Price

email: [EMAIL PROTECTED]
jabber: [EMAIL PROTECTED]


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



Re: [PHP] function getting redeclared

2003-02-18 Thread Erik Price

On Tuesday, February 18, 2003, at 10:27  AM, Ford, Mike [LSS] wrote:


I have a script, registration.php, which calls require_once on the
Registrant.class file mentioned in the above error message.  The
Registrant::setPhone() method is called more than once.  Since it is
called more than once, the function isValidPhoneNumber() defined
within setPhone() is defined more than once, which I suspect is the
source of the problem.  Does PHP not allow you to define a function
within a function and then call the enclosing function more
than once?


Well, it kinda does, but as it doesn't limit the scope in any way 
there's
not really any point.  Besides, it can lead to the kind of problems 
you're
experiencing.  Just declare the two functions sequentially in your 
include
file.

Okay, so PHP stores all functions that are not class methods in a 
global namespace?  Or does it even do this with methods?

Just curious so I don't depend on anything I'm used to from other 
languages thanks!


Erik





--
Erik Price

email: [EMAIL PROTECTED]
jabber: [EMAIL PROTECTED]


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



Re: [PHP] Re: recursion?????

2003-02-18 Thread Erik Price

On Tuesday, February 18, 2003, at 10:58  AM, Johnson, Kirk wrote:


The latest survey I've seen indicates that about 11% of browsers have 
JS
disabled.

About the same percent have cookies disabled.

Too many for my tastes.  Probably 8% of browsers have JS and cookies 
disabled for a reason (knowingly) and therefore can be considered the 
most dangerous segment of users.  (Knowledge being power and all.)


Erik





--
Erik Price

email: [EMAIL PROTECTED]
jabber: [EMAIL PROTECTED]


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



Re: [PHP] MySQL DB Schema

2003-02-18 Thread Erik Price

On Tuesday, February 18, 2003, at 12:23  PM, Phillip S. Baker wrote:


Is there an easy way to pull out the schema of a MySQL for viewing??


If you have access to the command line (either directly or via the 
system() function), try this:

bash 2.05 $  mysqldump -t databasename --user=username --password



Erik





--
Erik Price

email: [EMAIL PROTECTED]
jabber: [EMAIL PROTECTED]


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



Re: [PHP] MySQL DB Schema

2003-02-18 Thread Erik Price

On Tuesday, February 18, 2003, at 12:39  PM, David Otton wrote:


You want the tables and the relationships between them? Not easy to get
the links because of the lack of foreign keys in MySQL.


You can add a comment to your table with the COMMENT modifier, which 
gives you 60 characters to describe your table's relationship to other 
tables.

(In a table named registrants, you could have the comment

  registrants.user_id = users.user_id

)

http://www.mysql.com/doc/en/CREATE_TABLE.html



Erik




--
Erik Price

email: [EMAIL PROTECTED]
jabber: [EMAIL PROTECTED]


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



[PHP] escaping quotes for redisplay

2003-02-18 Thread Erik Price
Hi,

I am running into a problem, that I'm certain I've had before but for 
some reason don't remember how to handle.  If anyone can advise me on 
what to do here, that would be great.

I have a PHP script that accepts some user input and validates it, and 
if the validation fails, it re-displays the form.  In the form, the 
text fields' value attributes are set to the user's input so that the 
user doesn't have to fill everything out again.  The whole system works 
great, and I'm sure you've all seen it a hundred times before.

The problem happens when a user enters a single quote, such as in the 
string O'Reilly.  Re-displaying this value in the value attribute 
of the form, like this:

  input type='text' name='publisher' value='O'Reilly' /

is clearly invalid HTML, and it shows when the page is rendered in the 
user's browser (only the O gets through).

If I turn on magic_quotes_gpc or use addslashes, the output is like so:

  input type='text' name='publisher' value='O\'Reilly' /

And of course, when rendered, simply allows the O\ to get through.

I can solve this problem by using double-quotes instead of 
single-quotes for my attributes, and that is probably what I'm going to 
have to do.  However, this means I can't let users enter double quotes, 
or the same thing will happen.  In other fields, double-quotes might be 
necessary.  Is there any other solution?

Thanks,

Erik

PS: I am using htmlentities() on the output before displaying it in the 
browser, but it doesn't apply to singlequotes.  I suppose I could 
str_replace it, but I'm wondering how other people handle this 
situation






--
Erik Price

email: [EMAIL PROTECTED]
jabber: [EMAIL PROTECTED]


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



Re: [PHP] does a form submit from a http page to a https ensure secure data?

2002-07-03 Thread Erik Price


On Tuesday, July 2, 2002, at 09:48  PM, Richard Lynch wrote:

 My old ISP had SSL on another server (or at least directory) and 
 personally
 vetted every line of code that went on it.  Royal PITA, but more secure.

What does vetted mean?  I didn't see it in the Jargon File so maybe 
it's OT but I'm curious.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Setting a cookie and redirecting

2002-07-03 Thread Erik Price


On Tuesday, July 2, 2002, at 11:10  PM, Justin French wrote:

 on 03/07/02 11:54 AM, Richard Lynch ([EMAIL PROTECTED]) wrote:

 Rule of Thumb:
 If you have to do header(Location: ...)  you have a
 design/engineering/organizational problem in your code/pages/site.

 I'm sure a zillion people will disagree with this rule

 I agree, except there's one exception to this that I can't see a way 
 around.

 When dealing with form submissions the receiving file needs to validate 
 all
 the code before anything is sent to the browser, update the database (or
 whatever) and then redirect to itself with some sort of GET flag that 
 issues
 a thankyou note or something.

 Otherwise people can hit refresh and post the data twice, or 10 
 times :)

Justin!  That's a great idea.  No one ever mentioned that to me before 
(and I've been on and off this list for months).  Or actually, I think 
YOU mentioned it once but I didn't understand it.

So let me ask:  do you have one giant script that validates all data, 
depending on the variables sent to it?  Or do you have a formcheck 
script for each individual form?

This is a great way to stop someone from hitting refresh and 
resubmitting their POST data accidentally, since you've got that GET 
flag which basically says do not process this form!  It's not 
-secure-, since anyone can remove this flag (even if you used POST), but 
it will work for Joe User to stop him from accidentally resubmitting.


Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Re: synchronizing php functions

2002-07-03 Thread Erik Price


On Wednesday, July 3, 2002, at 04:08  AM, Philip MacIver wrote:

 The problem is that sessions are local to the clients machine

Huh?

 so if I tried to put this information in the session then the only 
 information that I would get back is the people that
 are
 logged in on my machine, not the server (Please tell me if I wrong in 
 what I say here). Therefore I need to be able to
 but this
 information in the session and have it available to all sessions (sort 
 of like the way static variables in Java belong
 to the class and
 not the individual objects that are created from that class). So if you 
 undersatnd what I'm trying to do here and know
 of a way
 to do it I would love to here it.

This has been discussed on the list before, and even I think just last 
week (so check the archives, using server variables asp as your search 
criteria).  Some theories suggest that it would entail a lot of 
overhead, unless you only have a few users to keep track of 
simultaneously.  Possible suggestions are

1) if the data doesn't change, put it into an includefile
2) if the data is dynamic, be clever and implement this yourself with 
database-managed persistence (but beware the overhead).

Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] $_POST into a formatted string, help!

2002-07-03 Thread Erik Price



 Oh man I hope you don't shoot yourself when you realize how easy this 
 is..

 foreach ($_POST as $key = $val)
 {
 $str .= $key=$val;
 }

 Then just crop the first char off and there you go.

Even easier, though maybe requiring a tiny bit extra memory to deal with 
the array:

$arr = array();
foreach ($_POST as $key = $val) {
$arr[] = $key . '=' . $val;
}
$str = implode('', $arr);




Erik









Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] addslahes and magic quote woes

2002-07-03 Thread Erik Price


On Wednesday, July 3, 2002, at 09:40  AM, Jean-Christian Imbeault wrote:

 I am trying to make my PHP safe against malicious data user inputs. 
 Reading up on this most people suggest using addslashes(), magic_quotes 
 on and other things like mysql_escape_string();

 But I have been running into the problem that I mess up the user's 
 input because I use more then one of these functions in succession on 
 the data.

 Is there any way to prevent the re-escaping/re-slashing of data 
 that has already been escaped or slashed?

Turn off magic_quotes and do addslashes() explicitly every time you do a 
database insert.  Then make sure you always stripslash() data returned 
from a database query.

magic_quotes is convenient for newbies, but after a while you'll find it 
only trips you up, as you've discovered.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] V basic newbie problem

2002-07-03 Thread Erik Price


On Wednesday, July 3, 2002, at 10:43  AM, Duncan Ellwood wrote:

 My problem arises when I want to fill in the subsequent rows of the 
 table
 with the subesquent rows from the database. How do I create the 
 recordset
 that will pull the info from the relevant subsequent rows for my 
 columns?

 The code for the first row and first column entry is:

 ?php echo $row_RsSingStanDailybb['DailyBB']; ?

 but in the row below in the html table I want to refer to the second 
 row DB
 entry for DailyBB but I cant see how to go about this:( The Repeat 
 server
 behaviour in DW Mx simply puts all the values in one html cell which is 
 not
 what I wish to achieve. Basically I want the html table to match the
 database but have only succeeded in getting the first row to display so
 far:(

I haven't used DW Mx myself, I don't really like WYSIWYGs.  But the way 
to do it is use a while loop.

// $db = your connection parameters
// $sql = your query
if (!$result = mysql_query($sql, $db)) {
die('The query failed for some reason');
}

// this part goes through all the data in $result
// and does something with that data on each iteration
while ($row = mysql_fetch_assoc($result)) {
echo $row_RsSingStanDailybb['DailyBB'];
}




Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] php and apache path...

2002-07-03 Thread Erik Price


On Wednesday, July 3, 2002, at 11:08  AM, Nightshade wrote:

 Yea,I understood. But my question is: is right that my Document_root 
 (shown
 in phpinfo) is /var/www/html/ and not /var/www/html/mysite? And if isn't
 right where I can change this?

I'm not sure -- is that the directory that you want to be your document 
root?  I doubt it from what you're saying but nobody else has any way of 
knowing.

If you want your document root to be /var/www/html/mysite and it is 
currently something else, you need to set your httpd.conf file 
differently.  Or perhaps a .htaccess file can be used.  (This is 
assuming you are using Apache.)

Go to www.apache.org and read the httpd documentation there for more 
information about setting up the document root in httpd.conf.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Another Regex Question (General)

2002-07-03 Thread Erik Price


On Wednesday, July 3, 2002, at 12:00  PM, Martin Clifford wrote:

 Does [a-zA-Z0-9] (yes, I know [:alnum:] is the same) mean that there 
 can be a number, but it has to follow a letter?  Or would you just do 
 [a-zA-Z][0-9] to do that?

That bracketed construction is called a character class.  It represents 
any *one* of the contained characters.  But not more than one.  So there 
is no following at all, since for all intents and purposes the character 
class matches a single character (unless you use a qualifier like +, ?, 
or *).



Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Other than substr

2002-07-03 Thread Erik Price


On Wednesday, July 3, 2002, at 12:35  PM, César Aracena wrote:

 I need to show up some data from a DB which consist of phone numbers
 with area code. They're stored like () . What is the best
 approach to print them into some textboxes so they can be edited? I'm
 using substr but area codes (inside parenthesis) goes from 3 to 5
 numbers, so sometimes the closing parenthesis is showed and other times
 even the first number from the actual number is also showed. Can I use
 regex instead? How is it used? I tried to figure it out in the PHP
 manual, but it is NOT written in my level of English.

It would be a good idea to store the phone numbers in the DB as two 
separate columns of only numbers, for performance and for ease of 
coding.  One column for area codes (SMALLINT) and one column for the 
rest of the number (INT).  Then you can add the parentheses or reformat 
the numbers as desired.

But if the database is beyond your control, here is a regex that may 
help you:

// $number = the whole phone number record from the DB
preg_match_all('/^\((\d+)\) (\d+)$/', $number, $matches);

$area_code = $matches[1][0];
$rest_of_number = $matches[2][0];


Try that, but it's untested.



Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Unable to restart httpd after upgrading PHP

2002-07-02 Thread Erik Price


On Tuesday, July 2, 2002, at 12:22  AM, Robert Tan wrote:

 I am running a Sun Cobalt RAQ4 server. The PHP version on it is 4.0.6.
 I received an error message when I restart httpd after upgrading PHP
 scripting engine on my cobalt server through the patch that cobalt
 provided to fixes some security issues that were found on prior
 releases of PHP for Sun Cobalt server appliance.

Forgive my lack of knowledge of the RAQ4 server, but what's stopping you 
from just rolling your own?  The source code install isn't that 
difficult, and I have a documented log of an upgrade you can use as a 
guide if you want.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Re: Beginner Sessions Question

2002-07-02 Thread Erik Price


On Tuesday, July 2, 2002, at 03:04  AM, Richard Lynch wrote:

 And, really, $result is about a generic a variable name as $i

 How about using $user_info or even $user_info_result?

 Yes, I know every example and every PHP book on the planet uses $result.
 That doesn't make it right :-)

I hear you -- I used to use longer names for my SQL queries -- like 
$user_update_sql or $filerequest_result.


But once I had moved most of my code into object methods and functions 
(and therefore out of the global namespace/scope/whatever), I realized 
this really didn't matter as much.  In fact, for consistency and 
neatness, it was better that I use only $sql or $result, since there was 
only ever one query in the method or function definition, and this 
terseness was less cluttering to my code.

I completely agree if you're putting database calls into the body of a 
script, but if you can wrap everything into smaller scopes, it's not 
such a big deal.  IMHO.  This applies to a lot of variable names, in 
fact.  But I agree, in the main body of the script (global scope) it is 
best to be descriptive.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Help: Constants

2002-07-02 Thread Erik Price


On Tuesday, July 2, 2002, at 04:48  AM, Richard Lynch wrote:

 Change it back.

 You'll find a lot more bugs a lot quicker that way.

 :-)

 Use E_ALL

 Might need to transition one page at a time with error_reporting() at 
 the
 top or something, but migrate to E_ALL.

 You *will* benefit in the long run.  Promise.

Except in a production environment, where you really never want your 
users to see PHP error messages that you haven't coded yourself for the 
user's benefit.  It could reveal just a bit too much about your setup... 
even filenames are valuable to maleficants.

I recommend setting your php.ini to E_NONE and then putting 
error_reporting(E_ALL) at the top of each of your scripts, and then when 
the file is migrated to production, comment or remove the line.




Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] DOCUMENT_ROOT disappeared on me!

2002-07-02 Thread Erik Price


On Tuesday, July 2, 2002, at 10:47  AM, David E. Weekly wrote:

 After many tries, that is what indeed worked, but I'm a little irked, 
 since
 shouldn't it have been that setting register_global to On in my 
 php.ini
 would re-enable these base globals? I had to retool all of my 
 scripts. =/

IMHO you're better off, but yes, if you set register_globals = on then 
you shouldn't need to have retooled your scripts.  Did you restart your 
webserver after you adjusted php.ini?



Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Help: Constants

2002-07-02 Thread Erik Price


On Tuesday, July 2, 2002, at 10:58  AM, Analysis  Solutions wrote:

 Dude, that's nuts.  It creates way more work.  Having to put it on each
 page in the first place, then having to change it before you put it up.
 Then, there's the possibility that you forget to change it before
 uploading.  OUCH!

sheepish
In my case that could never happen.  First, all the scripts for this 
site are based on a template, so I stamp out a new template which 
already has this line on it when I need a new script.  But I also never 
use FTP/scp directly, I invoke scp from some shell/perl scripts I've 
written which clean up my files for me -- do things like rename the 
dev version to the prod version, move it to the appropriate 
directory of the appropriate machine, adjust the permissions 
appropriately, and do things like strip away certain lines (such as the 
aforementioned error_reporting() line).  So in my case, I *never* 
forget, since nothing gets moved to production without going through the 
shell script...
/sheepish

 Set error_reporting to E_ALL in php.ini on the development machine and 
 to
 0 in php.ini or .htaccess on the live server.  Set it once on each 
 machine
 and you're good.

You're right -- that's a far better way to do it.  I do my dev work in a 
separate virtual host on the prod machine though, so that's why I do it 
the way I described.  (This prod server is a firewalled intranet, as 
they call it, so is not really public, so I feel okay about doing dev 
work on it.  I'm also kind of an amateur.)


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Re: Executing a php script periodically using crond

2002-07-02 Thread Erik Price


On Tuesday, July 2, 2002, at 12:25  PM, Henry wrote:

 PS. I cannot compile as a binary etc. This configuration is the confi 
 of the
 shared server I am using which is hosted by a third part.

If your PHP is not compiled as a CGI interpreter, then you can't do 
commandline PHP commands.  But all is not lost.  You can have the cron 
job execute a shell script that executes lynx or links or wget, or even 
just executes the command directly from the cron job, and have that 
lynx/links/wget request a PHP script that does what you want done.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Re: Executing a php script periodically using crond

2002-07-02 Thread Erik Price


On Tuesday, July 2, 2002, at 01:00  PM, Henry wrote:

 Only one concern. Are there any security issues.
 And I suppose more
 importantly, if there are; is there a way to get the php-script to 
 ensure
 that is is being invoked by my cron deamon. Should I put the page in a
 directory and use .htaccess to control security. Or can I check the 
 referrer
 to ensure that it is not being invoked via a browser!!

There are always security issues.  I have no idea about the details of 
your system, your needs, or anything else, so I can't tell you anything 
except to think logically about what you are doing.  Does taking the 
wget path mean that anybody can use links/lynx/wget/telnet/Internet 
Explorer/Mozilla to execute your script?  Most definitely.  Be sure that 
you take this into account when you design it (you may wish to check 
things like the User-agent, IP address, and other HTTP variables to make 
sure that it is being executed properly).

 I'm going to go down the wget path at the moment. Thanks in advance.

Good idea -- seems like your only option according to what you've told 
us.

Personally I would probably write a Perl script (most hosts have Perl) 
to do whatever it is that needs to be done and have cron execute that, 
this saves you from a whole window of exploit (the web server).  But if 
you don't have Perl or don't know Perl, that's a problem.


Good luck,

Erik







Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Regular Expression Problem

2002-07-02 Thread Erik Price


On Tuesday, July 2, 2002, at 01:40  PM, Martin Clifford wrote:

 I'm trying to get this darn eregi_replace() to work, but it doesn't 
 produce any results at all.

 I want it to find all occurances of PHP variables.  Here is the regexp

 $output = eregi_replace(^[\$]{1,2}[a-zA-Z][0-9]+$, b\\1/b, 
 $var);

 As you might guess this is for a syntax highlighting function I am 
 trying to write.  Anyone have any ideas why it's not working?  Please 
 copy me directly, as I'm on the digest.  Thanks!

I prefer the PCRE regex syntax, this should do it:

$output = preg_replace('!^\${1,2}\w+$!', b$1/b, $var);

because \w is the same as [A-Za-z0-9_] (though perhaps it is in 
POSIX regexes too).


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] find and replace in php

2002-07-02 Thread Erik Price


On Tuesday, July 2, 2002, at 01:52  PM, Henry wrote:

 Imagine I have a piece of text

 Dear [firstname]

 Thankyou for purchasing [product] on [date].

 We're sure you'll be very [expectation].

 Ta Very much.

 Whats the easiest way to replace all the things in square brackets with
 variables of the same name.

 i.e. $firstname, $product, $date, $expectation

 Whilst ensuring that if the variable doesn't exist then it will be 
 replaced
 with  (absolutely nothing).

Here, I modified the template class I use for my site (very simple) to 
do what you want.  You need to have a template file that looks exactly 
like what you wrote above (EXACTLY), nothing more.  Here is a usage 
example:

?php
// the following vars have already been defined in your application,
// or are set to empty strings as appropriate:
// $firstname, $product, $date, $expectation

// create a new Template object
$template = new Template();

// specify where our template file is
$template-identifyTemplate('/path/to/file/above');

// set the parameters
$template-setParameter('firstname', $firstname);
$template-setParameter('product', $product);
$template-setParameter('date', $date);
$template-setParameter('expectation', $expectation);

// generate the output string and store in $outputStr
$outputStr = $template-createOutput();
// free memory occupied by the Template object instance
unset($template);

// print our data
print($outputStr);

Here is the class definition:



class Template
{
/**
 * @var template
 */
var $template;
/**
 * @var finalOutput
 */
var $finalOutput;
/**
 * @var parameters
 */
var $parameters = array();

/**
 * identifyTemplate
 *
 * determine which file to use for a template
 *
 * @access public
 * @param string $template path to a template file
 */
function identifyTemplate($template)
{
$this-template = $template;
}

/**
 * setParameter
 *
 * specify a name and a value to swap with that name
 *
 * this method can be called as many times as you have
 * parameters.
 *
 * @access public
 * @param string $name a parameter name
 * @param string $value value of the parameter
 */
function setParameter($variable, $value)
{
$this-parameters[$variable] = $value;
}

/**
 * createPage
 *
 * substitute parameter values where parameter names are found
 *
 * @access public
 * @return string template combined with values (transformed)
 */
function createOutput()
{
// read the template into an array, then
// generate a string from that array
$this-finalOutput = implode(, (file($this-template)));

// loop though all the parameters, and
// set the variables from the file to
// their corresponding values
foreach ($this-parameters as $key = $value) {
$template_name = '[' . $key . ']';
$this-finalOutput = str_replace($template_name, $value, 
$this-finalOutput);
}
return $this-finalOutput;
}
}






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Have you seen this host?

2002-07-02 Thread Erik Price


On Tuesday, July 2, 2002, at 03:50  PM, Tony Harrison wrote:

 Hi, if you can find a web host that offers ALL these services, i will 
 eat my
 hat on my webcam to the whole club:

Do you know the origin of that expression?  It refers to a period when 
sugar was sold in paper cones, known as hats.  So you won't really eat 
your baseball cap, just the family sugar jar.

 Usenet Newsgroup.
 at least 200MB space
 Perl/CGI support (optional)
 PHP - note: must have GD library installed!
 MySQL
 SHOUTcast web radio
 Reseller account option
 at least 300MB per month bandwidth
 ASP (optional)

I don't know about Shoutcast, but Pair.com is supposed to be good.  If 
you can get DSL or some service that doesn't block port 80, you may as 
well just host your own server (unless you want this for commercial use, 
in which case why not pay an ISP to host your own server?).





Erik







Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Re: Beginner Sessions Question

2002-07-02 Thread Erik Price


On Tuesday, July 2, 2002, at 04:31  PM, Richard Lynch wrote:

 Well, yeah, at that point all you have is SQL and Result, because the
 function has no idea what that SQL is about in any given call...

 But, personally, I just don't see the point to having a function/class 
 do my
 database work when it simply:

 Increases lines of code
 Increases debugging/maintenance time
 Decreases clarity of code
 Reduces performance
 Reduces flexibility
 Increases overhead

Hm.  Could be.  I haven't benchmarked it for performance, since in this 
case there will probably never be more than 20 simultaneous page 
requests at any given time considering the small number of users.  In 
fact, I'm sure you're right, that performance and overhead are 
definitely affected.

But I think you're mistaking what I said -- I don't necessarily write a 
function/class specifically to handle my DB work.  I write my classes 
and methods to manipulate objects easily and organize the data, and if 
maintaining state by doing a database insert (or resuming state by doing 
a database query) is necessary, well then that gets incorporated into 
the class.  It's not specifically a database abstraction layer, it's 
just an object, and most of my objects happen to get built from or 
stored in a database at some point within their lives.

And I write a function when I find that I am executing the same code all 
over again in various places -- like generating a date listbox or 
something.

The effect is that debugging/maintenance time and lines of code are 
decreased, not increased, and clarity of code and flexibility are IMHO 
much better when they are safely constrained to class definitions rather 
than all being in one giant script.

But one thing I have learned is that everyone has a different approach 
to writing code, and objects may not be your thing -- that's okay.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Populate Popup Menu from Database

2002-07-01 Thread Erik Price


On Saturday, June 29, 2002, at 11:41  AM, Mike Tuller wrote:

 What is here is beyond my understanding, and seems like it is a little 
 much
 for what I need.

 Here is what my database table looks like:

 Departments
 department_id
 department_name

 I just want to list the department name in the popup.

although I wrote this instruction in response to a question about 
integrating the listbox with javaScript, ignore the JS stuff, and you 
will see how to dynamically populate a listbox with database data:

http://marc.theaimsgroup.com/?l=php-generalm=102503848224300w=2





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Keeping Secrets in PHP Files

2002-07-01 Thread Erik Price


On Friday, June 28, 2002, at 06:14  PM, Lazor, Ed wrote:

 The hosting provider could probably implement a solution...  Alter the 
 FTP
 configuration to automatically set the group permission to that of the 
 web
 server when you transfer files.  You wouldn't need to be in the group.
 You're the owner and can modify your own files.  World Read access 
 would be
 unnecessary.

Someone pointed out last week that a maleficant can write a script that 
reads other files' data [and does something evil with that], since it 
will be executed as the web server user and the web server user can read 
all those files.

Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Javascript to PHP?

2002-07-01 Thread Erik Price


On Saturday, June 29, 2002, at 03:13  PM, Jed Verity wrote:

 I can't find any information on passing JavaScript variables to PHP on 
 the
 same page (i.e. not through the POST information of a submitted form). 
 Is
 this because it's not possible?

 To take the load off the server, I'm trying to do a bunch of string
 manipulations and loops in JavaScript and then hand that info off to PHP
 once it's done.

How will you communicate with PHP without submitting an HTTP request of 
some sort?  So, really, you will need to submit -something-, though it 
could be GET data, POST data, or COOKIE data.

You can't have JavaScript talk to PHP within the same page since the 
webserver/PHP forgets all information related to that page as soon as 
it shoots it to the user-agent.

I'm assuming you know how to use JavaScript to set a cookie, and/or make 
a new request with GET or POST data attached.  If not, let me know.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] strip_tags

2002-07-01 Thread Erik Price


On Monday, July 1, 2002, at 11:09  AM, BB wrote:

 OK, this is a 3x3 table pasted in from word!

It is against the rules to post HTML code generated by Microsoft Word.



Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Register globals off

2002-07-01 Thread Erik Price


On Monday, July 1, 2002, at 11:30  AM, Adrian Greeman wrote:

 Would it be true to say that every time an example is given where data 
 is
 passed on (for forms and so forth) that I can simply replace the 
 variable in
 the example with $_POST or $_GET?  Or do I have to do more?

Pretty much.  If the data was passed by a get-method form, or through 
the querystring, then the variable should be in the _GET array (such as 
$_GET['variablename']).  Likewise for post-method forms, and any 
cookie variable names are now $_COOKIE['variablename'].  Server 
variables like $PHP_SELF are now $_SERVER['PHP_SELF'], and you can read 
the rest under predefined variables in the manual at the web site.

 eg if a simple PHP file for handling form input takes in the data using
 $LastName can I simply use $_POST[LastName]??  It seems to work for a 
 very
 simple example.   But should I read the array into a variable first?

Only if you want to -- you can always just refer to it as 
$_GET['variablename'].  In fact this is probably better for memory use.

 And do
 I need to do any validation or declaring of variables etc??  [I did 
 have a
 problem reading in a number -  the solution was to put (int) before the 
 POST
 array name though I don't understand why that was not needed with a 
 string.

All POSTed or GETed data is string data, so if you for some reason 
explicitly need to cast the variable as an integer, then yes, you need 
to use (int).  But in many cases PHP does this automatically.

 I am also unclear what happens when you send something using header()  -
 does that also go into an array - if so which one and how do I use it?

I'm assuming you mean sending some querystring data, like

header(Location: http://domain.com/page.php?data=contents;);

if so, then yes, you will end up with the string 'contents' in a 
variable called $_GET['data'] .



Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] help with regex in preg_match();

2002-07-01 Thread Erik Price


On Monday, July 1, 2002, at 01:37  PM, [EMAIL PROTECTED] wrote:

 I got this line that is relly giving me a pain..:

 if (preg_match(@siteUserList.cgi\?group=site177(?)@,
 $QUERY_STRING))

 As you can see it just matches the query string when it looks like
 this: siteUserList.cgi?group=site177 (with or without a )

 The thing is I need it to match also if after the  there is a number
 (that will have more than 1 digit)

 Ive tried many diffrent thing with \d+ but I can get it to work.. can
 somebody give me some light? Thanks.

preg_match('/siteUserList.cgi\?group=site177?(\d\d+)?/', $QUERY_STRING)

that will match the following criteria:
 if there is a  sign
 OR a number with more than 1 digit
 OR both an  sign AND a number with more than 1 digit

If you only want it to match if there is BOTH an  sign AND a number 
with more than 1 digit, it should be like this:

preg_match('/siteUserList.cgi\?group=site177(\d\d+)?/', $QUERY_STRING)







Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Populate Popup Menu from Database

2002-07-01 Thread Erik Price


On Monday, July 1, 2002, at 04:22  PM, Mike Tuller wrote:

 Thanks. Here is what I did for future reference.

Good.  What you chose to do is exactly what I do except for one 
thing... :

 $sql = select department_name from Departments;

I generally grab the primary key column value as well, in the same 
query, and then I use that as the value attribute for the option 
tags:

 while($row = mysql_fetch_array($sql_result))
 {
 $department = $row[department_name];
 echo option value = '$department'$department/option;

 }

while ($row = mysql_fetch_assoc($result)) {
$dept_id = $row['department_id'];
$dept_name = $row['department_name'];
echo option value='$dept_id'$department_name/option\n;
}

The reason I do this is because I end up using the ID far more than the 
name of a database record -- while I might echo the name to the user 
where needed (such as in the above dropdown listbox), the ID comes in 
handy as a reference in hyperlinks, form fields, etc -- it provides 
something that I've discovered is really missing in writing HTML-based 
applications: a unique handle on an object.  This is very hard to 
replicate given the statelessness of HTTP, but with a database record's 
primary key, you always have this unique identifier by which to refer to 
the object.  and a number is more pithy than a name.

It'll avoid situations where someone enters the same name value twice, 
too.  But it's not really a big deal unless you're doing a lot of work 
with a lot of data.


Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] extracting data from text file

2002-07-01 Thread Erik Price


On Monday, July 1, 2002, at 05:17  PM, [EMAIL PROTECTED] wrote:

 I have trend this but it does not work properly

 $fp = @fopen(file.txt,r);
   $line = explode(\n,$fp);
   $valueC = $line[0];
   $valueST = $line[1];
   @fclose($fp);

What error messages are you getting?  I imagine that since you've 
suppressed the errors with the @, you will need to remove this to give 
us any useful information.

One other thing, has your file been saved with the appropriate line 
breaks for your server?  In some cases, a file may have DOS/Windows or 
Macintosh line breaks which are not \n but rather \r\n and \r 
respectively IIRC.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] securing an 'includes' dir

2002-06-28 Thread Erik Price


On Friday, June 28, 2002, at 04:25  AM, Nick Wilson wrote:

 How might I make an 'includes' dir inside the http root and stop users
 being able to browse it?

chmod go-rwx dirname

But this will probably stop the web server from reading the file.

Perhaps the administrators can provide a script (SUID) that allows a 
user to change the group association of the file to that of the web 
server?  Yet without making the user a part of the group itself, 
otherwise all users would be able to see all of these files...


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] checking

2002-06-28 Thread Erik Price


On Thursday, June 27, 2002, at 04:41  AM, Leo wrote:

 I have a form and I don't want to insert recording with blank value.
 I put:
 if ($lastname=) {
 $insert=no
 }
 if ($insert=no){
 do not insert;
 else
 insert;
 }
 my probleme is in some case $lastname= is true and other case is 
 false.
 I tried with $lastname=  but no change. how can I check if a varible 
 is
 empty or not?

http://www.php.net/empty






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Keeping Secrets in PHP Files

2002-06-28 Thread Erik Price


On Friday, June 28, 2002, at 09:30  AM, Jonathan Rosenberg wrote:

 Let's say I am in a shared server environment  the provider does
 NOT have safe_mode turned on.  In that case, it seems to me that
 it is insecure to keep secrets (e.g., DB passwords) in a PHP
 file that is executed by the server.

 I say this because any other users of that shared host can read
 the PHP file  obtain the secret.  There does not seem to be any
 way around this (once again, I am assuming safe_mode is NOT
 turned on).

Think about it in terms of the permissions on the file.  The people who 
can read this file are explicitly defined in your permissions.

The catch-22 is that the web server is usually not run as root, so it 
doens't automatically get to see your files -- you need to give it 
permission to read them just as you would any other user.  In a shared 
system, if you give others permission to read the file, the web server 
user can now read the file, but so can everyone else.

However, if there were some way for you to change the group association 
of the file to, say, the websecret group, and then you could close off 
the read permissons of others on that file.  As long as the web server 
is a member of websecret, and you grant read permissions to the group 
for that file, then the web server can read it.

The trick is that in order to change the file's group association to 
websecret, you probably need to be either root or a member of 
websecret, unless the system admins have provided some kind of script 
that does this on your behalf.  Which means that anyone else who has 
this ability can read the file too (since they are a member of 
websecret).

It's tough.  Shared hosting security is a difficult issue.




Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Another Pop-Up problem..

2002-06-27 Thread Erik Price


On Wednesday, June 26, 2002, at 08:39  PM, Doug Coning wrote:

 I've got it to work now where it will pop up a window.  However, now it
 returns the same record each time.  So which ever record you click 
 first, it
 will bring that window up for each item.

 How do I reset or clear out the value so that when you click a different
 link it brings up the proper record.  You can see what I mean by 
 visiting
 the code at: http://www.coning.com/phptest/73things_view5.php.

Doug, I took a look at your page.  The problem doesn't appear to be with 
your JavaScript, it seems to be a problem with your PHP.  Try directly 
opening the following links in your browser and you'll see what I mean:

http://www.coning.com/phptest/73things_thread.php?threadID=13
http://www.coning.com/phptest/73things_thread.php?threadID=14
http://www.coning.com/phptest/73things_thread.php?threadID=15

Even though the threadID GET value is different in each one, the same 
data is coming up.  So you need to check your back end code.


Erik




Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Display Records in Multiple Pages

2002-06-27 Thread Erik Price


On Thursday, June 27, 2002, at 02:56  AM, Justin French wrote:

 Use the LIMIT function in your SELECT query... check out the MySQL 
 manual...
 and then generate back / forward links depending on your current 
 offset.  It
 should be expandable to 1000 records without any mods to the code.

Justin,

Out of curiosity, why is it only expandable to 1000 records?  What 
happens after that?  I thought that (in theory) you can keep going with 
this kind of scheme.  Or is there a limitation in MySQL that I'm not 
aware of... ?


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Compiling PHP with XML????

2002-06-27 Thread Erik Price


On Thursday, June 27, 2002, at 03:14  AM, René Moonen wrote:

 Compiling and installing Expat and Sablotron works fine (so it seems) 
 but after that I get errors compiling PHP with XSLT options. Compiling 
 without the XSLT options works just fine. These are the PHP options I 
 use:

--prefix=/usr/local/php
--with-config-file-path=/usr/local/php
--with-apxs=/usr/sbin/apxs
--enable-track-vars
--enable-magic-quotes
--enable-debugger
--enable-xslt
--with-xslt-sablot

 The last two are the ones that I have added to allow for XSLT


 Am I missing something?

This is a command history from when I added XSLT to my dist.  It's older 
(PHP 4.1.2) but it should still work with newer PHP distributions:


2002-03-11 XSLT upgrade log for PHP

At this time, the /usr/local/src directory has the following directories 
(all expanded from tarballs):
apache_1.3.22/
expat-1.95.2/
mysql-3.23.46-pc-linux-gnu-i686/
php-4.1.2/
Sablot-0.90/
tarballs/

/usr/local/apache/bin/apachectl stop
/usr/local/mysql/bin/mysqladmin -u root -p shutdown
(shuts down the daemons so we can work on them)

cd /usr/local/src/
(this is where we start)

pushd expat-1.95.2/ (enter the expat source directory)
less README
./configure --help
./configure
make
make install
popd (back to /usr/local/src)
(always good economy to read the docs and see what ./configure options 
there are, though none were actually chosen)

pushd Sablot-0.90/ (enter the Sablotron source directory)
less README
./configure --help
./configure
make
make install
popd (back to /usr/local/src)
(same as for expat)

pushd apache_1.3.22/ (enter the Apache source directory)
rm config.cache
make clean
pushd ./src/modules/php4/ (enter the php4 module source directory within 
the Apache source directory)
rm config.cache
make clean
popd (return to the Apache source directory)
(the rm and make clean commands were probably not necessary, but I 
wanted to be sure not to use any old data)

./configure --prefix=/usr/local/apache
(execute the ./configure script to show Apache where to be installed, 
but do not make yet)

pushd ../php-4.1.2/ (jump out of the Apache source directory to 
/usr/local/src/php-4.1.2)
rm config.cache
make clean
(clean up the php-4.1.2 source directory)
./configure --with-apache=/usr/local/src/apache_1.3.22/ \
--with-mysql=/usr/local/mysql/ \
--enable-sockets \
--with-zlib \
--with-xmlrpc \
--enable-xslt \
--with-xslt-sablot

make
make install
popd (back to the Apache source directory [/usr/local/src/apache_1.3.22])
(create the PHP binary with the ./configure options for using MySQL 
[requires zlib on RH 7.2], socket functions, XML-RPC, and XSLT with 
Sablotron, and then install the binary into the modules source 
directory in the Apache source directory)

./configure --activate-module=src/modules/php4/libphp4.a \
--enable-module=so \
--enable-shared=max

(run the Apache ./configure script again, this time specifying that PHP 
is to be installed as a static module and that Apache should be compiled 
to accept later dynamic shared object modules [no, the libphp4.a file 
does not exist yet but ./configure it anyway])
pushd ./src/modules/php4/
make
(compile the PHP module into Apache, no 'make install' necessary)
popd (back to the Apache source directory, /usr/local/src/apache_1.3.22)
make
make install
(final compile and install of Apache with the now-embedded PHP module)
popd (back to /usr/local/src)
cd /usr/local/mysql/
./bin/safe_mysqld --user=mysqladm 
(start mysql daemon, safe_mysqld can only be executed from 
/usr/local/mysql)
/usr/local/apache/bin/apachectl start
(start Apache)

Then test to make sure that MySQL and Apache are working by requesting a 
phpinfo() page or MySQL-generated page.






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] MySQL fetch data

2002-06-27 Thread Erik Price


On Thursday, June 27, 2002, at 04:20  AM, Jefferson Cowart wrote:

 Is there any way to return all the rows returned by a mysql query with
 one command. Currently I have to run through a for or while loop the
 same number of times as there are rows and take that row and copy it to
 an array. I end up with an array of arrays but it seems like it would be
 a common enough problem that the function would already exist.

You will probably always need to use a looping construct to grab your 
data (otherwise how will you assign each value to a variable?).  But you 
may find it easier to use mysql_fetch_object().
http://www.php.net/manual/en/function.mysql-fetch-object.php

Or maybe not.  It's a matter of preference and performance (I think the 
object version is a bit more expensive).


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] OOP assistance request

2002-06-27 Thread Erik Price


On Thursday, June 27, 2002, at 04:44  AM, Andrew White wrote:

 On Wednesday, June 26, 2002, at 04:48  pm, Erik Price wrote:

 My problem is that I have no way to know which type of object to 
 instantiate in advance -- all I have is this primary key.  Using the 
 primary key to instantiate an object, I can extract the ProjectType 
 primary key, and then I could instantiate a new object of the 
 appropriate type, but then I'd have two objects (and that seems like a 
 lot of overhead).  I'd rather just have the client code instantiate 
 the right type of object from the beginning.

 Use a static function in the project parent class and a column in the 
 table which stores the classname of the project

I did not realize that you could access a class method as a static 
method in this fashion!  (Class::method())  Enlightening.  So I can use 
Project class code without even having any instantiated Project 
objects.  That is really cool.

However, this is really the same thing as if I did the same thing from 
the client code.  In other words, it does require an extra database call 
to determine the type of Project, to help me decide which kind of 
project to instantiate.  This way it just puts that code into the class 
definition to keep my client code from getting cluttered.

I do not believe it is possible to cast an object from one user-defined 
data type to another in PHP -- this is what my own testing has shown, 
though I have not heard confirmation.  This would really be the ultimate 
solution.  But still, the above is a good workaround.  My alternative is 
to simply use the Project class and -not- subclass the different types 
of projects, and then use a big ugly Project::display() method that does 
its own testing of the type of the object and performs certain code 
depending.  That would save me the extra database call at least, so for 
performance it might be worthwhile.

Thanks very much Andrew.


Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Re: PHP and OOP

2002-06-27 Thread Erik Price


On Thursday, June 27, 2002, at 08:10  AM, Kondwani Spike Mkandawire 
wrote:

 I still don't get what the big fuss of OO programming is about
 I do agree that it is stylistic hence helps someone else who
 hasn't written your code to follow up on what you are doing...
 But so far the programs I have been writing in OO supported
 languages have been written and scripted on an as is needed
 basis...  i.e.  I have the basic idea then I simply start scratching
 down methods/functions I have never sat down and drawn
 a single UML diagram on a project that I am about to do...

 How many of us have done so?  Could some one please
 point out another feasible advantage of OO programming
 a part from the fact that I would make someone else's work
 easier by using this style of programming...

I never used UML for the project I'm working on (and am almost finished 
with), but I sure wish that I had.  I just didn't know UML or even OO 
programming when I started.  Basically I started out writing a giant 
application with procedural code, and then as I learned how to use 
objects, I cleaned everything up by using objects to represent most of 
the actors and data.  But because I never properly modeled my project 
(my fault I know, I'm not blaming anyone else but me), it is far uglier 
than I would like.

This assignment is almost done, but I have been learning Java in my free 
time and it is my plan to properly model this project and rewrite it in 
Java as an exercise.  Maybe not implement every single detail, but get 
the bulk of it.

Life is one big learning exercise anyway



Erik







Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Detecting Browser Type/OS from HTTP_USER_AGENT

2002-06-27 Thread Erik Price


On Thursday, June 27, 2002, at 08:57  AM, Patrick Teague wrote:

 Has anyone else done something similar to this?  The main purpose for 
 doing
 this is to find out what clients are using the most so that we can 
 provide
 content more specific to the browsers.  I've noticed things that work 
 on Win
 MSIE don't look half the same on Mac MSIE, not to mention the 
 differences
 between MSIE, Konqueror,  Mozilla.   The other reason is I have people
 developing stuff on Mac, Linux,  Windoze.  I'm trying to put together
 something sane to mesh all of these together.

The best thing you can do is make every attempt to code to the 
standards, and then hope that the browsers do their best to meet those 
standards too.  You could argue with my opinion on this, saying that 
Well that's just not realistic because everyone's using IE or 
whatever, but then something like AOL's decision to use Mozilla as its 
internal browser engine comes along and changes the whole paradigm.  
Boom, you now have to change your entire site because now most people 
aren't using IE.

Coding to the standards is your best option.  In my opinion.  Good luck.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




[PHP] performance, memory objects

2002-06-27 Thread Erik Price

Since we are on the topic of objects with PHP, what is the best way to 
free the memory being used by an object?

A lot of examples use unset($objReference).  But when freeing the memory 
used by a large string, it's best to assign that string's reference 
variable to an empty string, ($str = ;) according to Programming PHP 
by Tatroe and Lerdorf.  I was surprised that this book didn't mention 
freeing memory used by objects (or if I'm wrong, please point me to the 
right page).

Here's a sample from my script I'm working on right now... is assigning 
the object's reference variable to null redundant or not worthwhile?

// $result = a MySQL result resource
$photos_string = ;
while ($row = mysql_fetch_assoc($result)) {
$photo_obj = new PhotoItem($row['photoitem_id']);
$photos_string .= $photo_obj-display();
$photo_obj = null;
unset($photo_obj);
}

// do something with $photos_string


Erik







Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Best Delete Confirmation Script

2002-06-27 Thread Erik Price


On Thursday, June 27, 2002, at 12:48  PM, Shane wrote:

 I would like your opinions on the best way to implement an Are You 
 Sure You Want To Do This? dialog for an Admin user when they go to 
 delete a record in a DB.

 Do you find that a whole page is usually required for this, or does 
 anyone have any nice pop up solutions for such a query.

 Sure... I hate doing these things too, but when Joe Big Boss gets a bit 
 trigger happy and kills some data he mistakenly thought was a different 
 record. You KNOW who is going to hear about it from on high.  :^)

It's such a pain in the ass, isn't it?  Unless you're using JavaScript, 
it's like an extra step, and you probably want to re-display the data 
that's being altered, so you really end up having to make another whole 
page in order to do it.

One way that I like to do it is this:

Most of my scripts are really giant switch() statements, and depending 
on the action variable passed in the querystring, different things 
happen.  So...

http://www.domain.com/addrecord.php?action=intro

The switch statement reads the $_GET['action'] variable and knows to go 
to the intro block, where I display the instructions for the page.  
The next one would be

http://www.domain.com/addrecord.php?action=form

and is accessible from a hyperlink generated in the intro section.  
This displays  a form that lets the user do some data-changing 
operation.  The form is of POST method, and the form's own action 
attribute is

$_SERVER['PHP_SELF'] . ?action=confirm

So now all the user input is in the $_POST array and the action 
variable's value is add, so the master switch() statement sends the 
code to the add section.  What happens here is, some checks are done 
on the data to see if it is valid, and if it is valid, the changes are 
echoed back to the user as a confirm page with a button to resubmit 
one final time (all the values are thrown into hidden variables).  
However, note that if the input is NOT valid, we don't have to re-do the 
code to display the form again, because we can just echo back the error 
messages and use the switch() statement's ability to drop down to the 
next block, which is case 'form':.  That's why I like switch(), and 
disagree with Python's lack of it, but whatever.

Finally, if the user did have the correct data, and the confirm form 
with the hidden vars is submitted, it goes to

$_SERVER['PHP_SELF'] . ?action=commit

and the data is actually inserted into the DB in the commit block of 
the switch statement.

The code looks like this:

switch($_GET['action']) {
case 'commit':
// enter user's data into DB
break;
case 'confirm':
// error check user input
// if valid, display a
// form action=\ . $_SERVER['PHP_SELF'] . ?action=commit;
// if not valid, echo an error message
// and thendrop down to the next
// block of the switch() (case 'form')
// NO BREAK STATEMENT HERE
case 'form':
// display a form with
// form action=\ . $_SERVER['PHP_SELF'] . 
?action=confirm;
break;
default:
// you can also call this one case 'intro' if you want
// display the instructions for this page
}



HTH,

Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] HTTP1.1

2002-06-27 Thread Erik Price


On Thursday, June 27, 2002, at 01:39  PM, Gerard Samuel wrote:

 I was wondering if this is a no no according to http 1.1 specs.
 ie absolute links -
 a href=http://host/correct_path_to_file.php;somefile/a

 I briefly looked through through the specs, but it didn't say that 
 links/urls shouldn't be formatted like the first example above...

I think it is okay as long as you are staying within the same virtual 
host.






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] ok what kind of crack is my computer smoking?

2002-06-27 Thread Erik Price


On Thursday, June 27, 2002, at 05:09  PM, Rick Kukiela wrote:

 SO what do i have to do to get php to acknolege the fact that it has 
 been
 recompiled with new options

Did you rm ./config.cache in the Apache source tree?

If I were you, I'd remove the source trees you have, re-extract the 
tarballs, totally.  Not just for the modules but for Apache too.  It's 
just easier unless you have customized code in your Apache source tree.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Re: One more 'Headers Already Sent' error. :-(

2002-06-26 Thread Erik Price


On Tuesday, June 25, 2002, at 06:07  PM, Brad Melendy wrote:

 Well, I have traced this down to line 4 in the following code
 'include(header.html);' which just includes my navigation bar.  If I
 comment it out, everything works great, if I leave it in, I get the 
 error
 Headers Already Sent.  The file it purely html.  What could be the 
 problem??
 Thanks in advance!

You want this script to redirect twice?  Or do you just want it to 
redirect the first time, but have the second header() function be called 
if the first one doesn't?  Then you should call exit() after the first 
header() function to keep the rest of the script from executing.

This is also generally a good practice after a header('Location: ') call 
because the user-agent doesn't HAVE to respect the header and redirect, 
so it protects your stuff.  Always feature an exit() with a header-based 
redirect.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Passing Form Values

2002-06-26 Thread Erik Price


On Tuesday, June 25, 2002, at 06:56  PM, Phillip S. Baker wrote:

 When the form is submitted I want to values passed to a pop-up window.
 I am aware of the need for Javascript for the pop-up window, but how do 
 I get the values from the form passed to the new window so I can use 
 them in further scripts.
 I can write the javascript to do the popup window and use the onSubmit 
 command, but I cannot figure out how to pass the values with a regular 
 submit button.
 Thanks

Pass them along the querystring, so that when the JavaScript popup 
window opens and it goes to a certain page, those values are part of 
that URL.  As GET variables.

// Your PHP vars:
$var1 = 'Metroid';
$var2 = 'Metal Gear';

// Create a querystring:
$PHPqueryString = var1= . $var1 . var2= . $var2;

// echo the browser string for the popup:
print a href=\\ onclick=\openPopup(
. $PHPqueryString
. \Popup!/a\n;

// here's your JavaScript function
function openPopup(queryString)
{
var detailwindow = window.open('./target.php?' + queryString,
'windowname',
'toolbar=no,directories=no,
status=no,menubar=no,resizable=yes,
copyhistory=no,scrollbars=yes,
width=500,height=300');
detailwindow.moveTo('150', '150');
}

Now in your new script you can access these GET vars from PHP or from JS!


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Security problem?

2002-06-26 Thread Erik Price


On Tuesday, June 25, 2002, at 08:26  PM, Analysis  Solutions wrote:

 I usually run PHP as CGI.  My secure files are kept in a directory 
 that's
 not under the */docroot.  Thus, they can't be gotten to through the web
 server at all.  Plus, the secure files are chmoded 600 (which means they
 can be read/written only by the owner).  Thereby, the only user on the
 server who can read them is me.

Tradeoff, huh?  If I understand it correctly, you can't keep the files 
outside the docroot if you're using mod_php b/c the web server itself is 
what fetches the file (therefore it needs to be in the docroot).  But 
mod_php is faster than CGI PHP and can handle more simultaneous 
requests.  Right?


Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] appending to XML file before closing tag

2002-06-26 Thread Erik Price


On Tuesday, June 25, 2002, at 08:42  PM, Brian White wrote:

 I was actually thinking about this the other
 day - every now and again I find my self
 yearning for SGML, where you could have
 just declared the wrapping element end
 tag omissable, and then you would never
 have to worry about it - basically
 the end of the file would imply the
 existence of the end tag (sigh  )

Yes, but that makes parsing very difficult -- if you're expecting to 
find a closing tag, it should be there.  You'd have to write a special 
set of XML-handling functions or a special library to cover this unique 
breach of the XML rules, since most XML modules (for Perl, PHP, Python, 
Java, whatever) expect well-formed documents.

XML is pretty verbose, yes, but the rewards of this are consistency -- 
as long as the document is well-formed, it should be pretty easy to 
extract the data from it without writing special code to handle these 
kinds of exceptions.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Re: MySQL Problem with PHP

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 08:58  AM, John Holmes wrote:

 I just preg_replace(/\'/,\',$text) and all was good :o)

 That's what addslashes() is for. It handles single and double quotes,
 backslashes, and nulls, so you won't have any problems...

Plus IIRC it's a C extension so it'll run faster anyway.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Seperating presentation from logic

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 09:05  AM, John Holmes wrote:

 I disagree. Maybe I'm just not getting it, or understanding the FULL
 POWER of xml/xslt. It just seems like it's adding in an additional
 layer that you don't need. It seems so dependent on browser versions,
 and parser versions, etc. Just make a plain HTML template and a small
 template parsing script to insert the variables you need. Pattemplate is
 pretty close to XSL, but I haven't seen any speed comparisons on it.

Yeah, but what if you want to output to a format other than HTML?  For 
instance you want to generate a PDF invoice, which is emailed to the 
user, but you also want to display that invoice to the user?  Should you 
have two separate files/sources of data?  You could have one XML file, 
and use XSL to make an HTML document which appears in the user's browser 
and a PDF which is emailed to them.

The point of XML is to look beyond the web browser as a point where the 
user needs data.  PDAs would benefit from non-HTML formatted stuff (too 
small a screen for most web pages), cell phones have their hardly-used 
WML, there are tons of different print formats like PDF or PostScript, 
plus alternative formats like troff (for man pages) and POD (for Perl 
manpages) and others.  XSLT lets you output from one source file to any 
desired format.

If you need versatility in the output of your data, XML can really help 
you.  Plus, it doesn't depend on browser version if that's what you're 
worried about -- it can be done server-side: use PHP to perform the 
transformation before it gets to the user if it's going to their 
browser.  That's why some XML-based sites let you choose whether to view 
the page in HTML or XML (so that if you want to use a spider or script 
to parse the data on the web page instead of looking at it in a browser, 
you can do that much more easily with the XML formatted output than the 
HTML formatted output).  Later on down the road, when (hopefully) all 
browsers incorporate an XSLT processor, the burden of performing the 
transformation can be handled by the client.

Not that client-side technology has been very successful at 
standardizing, in consideration of different JavaScript implementations, 
CSS implementations, and even Java Virtual Machines (witness Microsoft 
consistently refuse to ship a decent JVM with their OS, even though they 
are freely available from the Sun web site).

That's why server side stuff like PHP will probably always be invaluable.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Web Services

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 10:49  AM, Laurent Drouet wrote:

 I would like to know if there is a way to request data from a web 
 services
 for example http://glkev.net.innerhost.com/glkev_ws/Currencyws.asmx
 using php without java ?

If you know the web services API, you just send your request.  It 
shouldn't matter whether you're using Java, PHP, Python, even VB or even 
Telnet to generate your request -- most web services accept an HTTP POST 
message consisting of XML code which is used to perform some kind of 
action.

There are two things you can do -- either use the cURL functions (your 
PHP binary must be compiled with cURL enabled to do this), which give 
you an advanced set of URL accesses, or open a socket to the remote 
machine with the web service and send a stream of POST data that way.  
You can use Rasmus Lerdorf's postToHost function (this may as well 
just become a PHP function, it gets referenced so much), which I have 
appended to this message.

Either way, just generate your XML string and fire it at the remote 
machine.  You will need to write code to handle the response, obviously.

# ===
# PostToHost($host, $path, $data_to_send)
# ---
# It is a trivial little function.
# -Rasmus
# ===

function PostToHost($host, $path, $data_to_send)
{
$fp = fsockopen($host,80);
fputs($fp, POST $path HTTP/1.0\n);
fputs($fp, Host: $host\n);
fputs($fp, Content-type: application/x-www-form-urlencoded\n);
fputs($fp, Content-length:  . strlen($data_to_send) . \n);
fputs($fp, Connection: close\n\n);
fputs($fp, $data_to_send);
while(!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}



Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




[PHP] OOP assistance request

2002-06-26 Thread Erik Price

Hi,

I'm making this request for help because my experience with object 
oriented programming is very limited.  I'd like to describe my situation 
and then ask a question at the end of it, any comments or input are very 
appreciated.


My application needs to keep track of different kinds of projects, and 
display different attributes depending on what kind of project it is.  
Therefore, I have written a base class called Project.

The four kinds of projects are PrintProjects, DesignProjects, 
WebProjects, and PhotoProjects.  Each of these extend the Project class, 
so they are child classes.  I intend to write my code to use 
polymorphism so that a single method call, $object-display(), will 
generate the appropriate output depending on which child class it is 
being called upon.  So really, the Project class is just an abstract 
class and is not really intended to be instantiated, but PHP doesn't 
really enforce a difference between abstract classes and true classes.

And each project has a corresponding record in a MySQL database, so I 
have a convenient primary key for every Project object (regardless of 
what kind of project it is).

HOWEVER --

Because this is PHP/HTTP and not Java, there is no true state.  So the 
way that I instantiate a Project is by passing the primary key of the 
object as an argument to the constructor of the Project.  The 
constructor can then flesh out the object as needed, and ideally there 
will be different flesh out code depending on the type of object.  My 
problem is that I have no way to know which type of object to 
instantiate in advance -- all I have is this primary key.  Using the 
primary key to instantiate an object, I can extract the ProjectType 
primary key, and then I could instantiate a new object of the 
appropriate type, but then I'd have two objects (and that seems like a 
lot of overhead).  I'd rather just have the client code instantiate the 
right type of object from the beginning.

Is there a way to convert a Project object into a PrintProject object -- 
such as casting it?  In other words, I'd like my client code to look 
like:

$obj = new Project('87633');
$type = $obj-getProjectType();
if ($type == '1') {
$obj = (PrintProject)$obj; // re-cast the Project into a PrintProject
} elseif ($type == '2') {
$obj = (DesignProject)$obj; // re-cast the Project into a DesignProject
// etc
}

$obj-display();// now the object will call the appropriate
// overriding method because the object is
// now of the appropriate subtype

Is that possible in PHP   Namely, the casting above?


Or does my client code need to be able to figure out which type of 
project it is (say, from the DB) and then use this to determine which 
object type to instantiate?


Thanks very much,


Erik







Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Compiling PHP with XML????

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 11:57  AM, Scott Fletcher wrote:

 I looked in the ./configure --help for the xml support.  It didn't 
 say but
 show some options such as disabling xml, using xml with different 
 stuffs.
 Nothing is being mentioned about enabling xml or something.  So, is xml 
 in
 php supported automatically?

Yes.  Since 4.1.x at least.  But for XSLT you need to get expat and 
Sablotron and link them into the compile (with the appropriate 
./configure options).


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] dynamically creating variable names

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 01:04  PM, Lee P Reilly wrote:

 Can someone tell me if it's possible to create variable names from
 varaible names? I could work around this problem using some if/else
 statements, but I'm interested to see if there's another solution.

Just try it.

for ($i = 0; $i  10; $i++) {
$var{$i} = $i + 6;
echo \$var$i ==  . $var$i . \n;
}

$var0 = 6
$var1 = 7
$var2 = 8
$var3 = 9
$var4 = 10
$var5 = 11
$var6 = 12
$var7 = 13
$var8 = 14
$var9 = 15


Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] PHP does not work??

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 01:20  PM, Scott Fletcher wrote:

 When I use the hyperlink, test.php?data=yes and I go to this page,
 test.php but there is no data in this variable, $data.  So, the web 
 page I
 have, most of them are all thrown off becuase of this.  I use PHP 
 version
 4.2.1.  Is there a bug in this PHP version???  Or some changes in PHP 
 that
 I'm not aware of?  Let me know!

Use $_GET['data'], not $data.  Or turn register_globals = on in your 
php.ini.

Get to know your php.ini, and read the release notes for any software 
you upgrade -- this is mentioned in the PHP 4.1.x release notes if you 
want to read them for yourself.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] server security

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 01:33  PM, Phil Schwarzmann wrote:

 What else can I do to make this server secure?  What is this SSL
 business all about?  Any extra programs I should add that might help?

Read this from beginning to end.  Then you will know what questions you 
need to ask to make yours system more secure.

http://www.w3.org/Security/Faq/






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Re: PHP does not work??

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 02:13  PM, Scott Fletcher wrote:

 I'm using UNIX, not windows, so there is no php.ini in UNIX.

Sorry, don't take offense if I ask if you've been living under a rock -- 
I only use Linux, and there is definitely a php.ini file that you use.  
I put mine in /usr/local/lib/ .  If you follow the source install 
instructions, you will see that the last step is:

$ cp php.ini-dist /usr/local/lib/php.ini

Yep, that means you're supposed to copy php.ini-dist to a dir on your 
server.  This is your configuration file, where register_globals and a 
million other configuration directives are decided...


?



Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] passing variable arguments from select

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 02:51  PM, Haddad Said wrote:

 Hi, i am having a problem passing variables from a drop down menu in a 
 form;

 from action=test.php action=post
 select name=example
 option selected one/option
 option two/option
 /form

You should do it like this (be sure to properly quote your attributes, 
and use the 'value' attribute of the 'option' tag):

print form action='test.php' method='post'
select name='example'
option selected='yes' value='1'One/option
option value='2'Two/option
/select
  /form\n;

In the test.php page, the selected value will be found in the 
$_POST['example'] variable.


Erik







Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] diffrance : require(); a file from localhost and from a domain.

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 03:19  PM, [EMAIL PROTECTED] wrote:

 tecnically whats the diffrance if I do:

 require(http://localhost/image.gif;);
 or
 require(http://www.domain.com/image.gif;);  ?

The first one requires the file at localhost/image.gif, and the second 
one requires the file at www.domain.com/image.gif.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Re: PHP does not work??

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 02:56  PM, Scott Fletcher wrote:

 I tried that and it worked.  I have
 one question, what about the hyperlink?  People will see the option in 
 the
 hyperlink.  You know.  Is there a way around it to hid that in the
 hyperlink?

If by hyperlink you mean the URL in the URL bar of their browser, 
correct -- people will see it.  That GET data is part of the URL, sort 
of.

Most browsers will not display POST data to their users (easily) but 
it's never truly hidden from view.  Any data that your users are 
sending to you, whether it's GET, POST, or COOKIE, is data that they can 
see.


Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Re: PHP does not work??

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 02:37  PM, Scott Fletcher wrote:

 I didn't know that.  Thanks for the info.  I think it would be best 
 that I
 not use php.ini.

On the contrary, I think it would be best if you read through it and 
read about it at http://www.php.net/manual/en/configuration.php .  
Putting it off will only cause you trouble in the long run.

 I can write the script to register the variable.  What would be a demo
 script that would work?  I'm having a little trouble understanding that 
 on
 the php.net website.  Most of the script that use global variables came 
 from
 hyperlinks.  I have no form method like post or get.

If it doesn't have post or get, then your data is probably in the 
$_GET array.  But you should always use the method attribute of the 
form tag.

 I have one website that use session.  Like session_start(),
 session_register(), etc.  How would this be affected and what is the 
 work
 around to this one.

You now refer to a session variable as $_SESSION['variablename'].


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Java Pop UP...

2002-06-26 Thread Erik Price


On Wednesday, June 26, 2002, at 03:37  PM, Doug Coning wrote:

 I have a php page that return rows from a database.  I then have an href
 link to the individual thread as such:

 a href='73things_thread.php?threadID=.$row-postid.' 
 target='_blank'.


 This works, it opens a new window which has the detailed information 
 needed.
 However, how would I write java code into this to force it to open the
 window at 300 by 255?  I know the java code for this is as follows:

 onclick=MM_openBrWindow('73things_thread.php','Thread','scrollbars=yes,widt
 h=300,height=255')

 How do I merge the java code into PHP?

Make sure the function is defined somewhere above, between script 
type='text/javascript' tags, and then you print this:


print a 
href=\javascript:MM_openBrWindow('73things_thread.php','Thread','scrollbars=
yes,width=300,height=255')\Click here for a new window at 300 x 
255/a;



Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




[PHP] casting user-defined objects

2002-06-26 Thread Erik Price

I have been playing around and am unable to explicitly cast an object 
instance from one user-defined type to another, using the traditional 
type-casting syntax nor with the settype() function.

I feel like I should mention this as an annotation in the man page, but 
I was hoping someone could steer me right if I'm wrong here.  The 
following code doesn't work:

class Apple
{
// some atts and meths
function display() {// do something }
}

class Orange
{
// some atts and meths
function display() {// do something }
}

// this part works fine
$fruit = new Apple;
$fruit-display();

// this part doesn't work like you think it would
$newFruit = (Orange)$fruit;
$newFruit-display();

The confusing thing is that this page
http://www.php.net/manual/en/language.types.type-juggling.php
actually does feature casting to objects, but I am unsure of what 
purpose the object type reference has.



Erik







Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] appending to XML file before closing tag

2002-06-25 Thread Erik Price



On Tuesday, June 25, 2002, at 09:31  AM, William S. wrote:

 I know I need to introduce: fread() and fseek().
 but not sure how to put it all together.

If you know for a fact that the ending tag for each file is consistent 
and always that same tag, here's an idea.  Determine or specify the 
length of the ending tag (in other words /html would be a length of 
7 [characters]).  Now move your file pointer to (file's total 
characters - length) so that it is immediately before the ending tag.  
Append your data, then manually append the ending tag.

If you will deal with varying ending tags, then you'll have to come up 
with a creative method for capturing them and storing them, then 
dynamically determining their length and do the same thing, then append 
the ending tag (whatever it may be).  I would use regexes to do this 
part.


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]



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




Re: [PHP] char function

2002-06-25 Thread Erik Price


On Tuesday, June 25, 2002, at 06:23  AM, Leo wrote:

 i want a logical function (true or false) that search a character into a
 string.(like indexOf() in javascript)
 example: i want to find char '@ ' in the string [EMAIL PROTECTED]

$str = '[EMAIL PROTECTED]';
if (preg_match('/@/', $str)) {
print $str does contain the '@' symbol.\n;
}

Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] [php] How to get request url string and server hostname

2002-06-25 Thread Erik Price


On Tuesday, June 25, 2002, at 02:56  PM, Harriet Xing wrote:

 Would anyone know how to get the http request url string in php?
 i.e., if the request is http://www.myserver.com/test.php?param1=123;, 
 how can I obtain this string in test.php?

$request = http://; . $_SERVER['HTTP_HOST'] . / . 
$_SERVER['PHP_SELF'] . ? . $_SERVER['QUERY_STRING'];


However, I don't like using $_SERVER['QUERY_STRING'] because if there 
are empty GET variables, it grabs them.  So, if you prefer, you can do 
this:

$getVarsArr = array();
foreach ($_GET as $getVarName = $getVarVal) {
$getVars[] = $getVarName . = . $getVarVal;
}
$getVarsStr = implode(, $getVars);
$request = http://; . $_SERVER['HTTP_HOST'] . / . 
$_SERVER['PHP_SELF'] . ? . $getVarsStr;



Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] [php] How to get request url string and server hostname

2002-06-25 Thread Erik Price


On Tuesday, June 25, 2002, at 03:22  PM, Erik Price wrote:

 However, I don't like using $_SERVER['QUERY_STRING'] because if there 
 are empty GET variables, it grabs them.  So, if you prefer, you can do 
 this:

 $getVarsArr = array();
 foreach ($_GET as $getVarName = $getVarVal) {
   $getVars[] = $getVarName . = . $getVarVal;
 }
 $getVarsStr = implode(, $getVars);
 $request = http://; . $_SERVER['HTTP_HOST'] . / . 
 $_SERVER['PHP_SELF'] . ? . $getVarsStr;

Doh, I forgot the part where you test for empty -- amend the above in 
the following fashion:

$getVarsArr = array();
foreach ($_GET as $getVarName = $getVarVal) {
if (!empty($getVarVal)) {
$getVars[] = $getVarName . = . $getVarVal;
}
}
$getVarsStr = implode(, $getVars);
$request = http://; . $_SERVER['HTTP_HOST'] . / . 
$_SERVER['PHP_SELF'] . ? . $getVarsStr;




Why would you care if there were empty GET vars?  Well, if you had a big 
search engine or some other form where the user can specify a bunch of 
criteria or just a little bit, it's up to you.  It's nice if you have to 
grab the GET data for whatever reason (repopulating links, etc) and you 
don't waste time with huge querystrings made up of mostly-empty 
variables.



Erik







Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] I changed my root password and now can't connect to MySQL

2002-06-25 Thread Erik Price


On Tuesday, June 25, 2002, at 03:27  PM, Phil Schwarzmann wrote:

 Now, whenever my script runs a MySQL command, I get this error

 Warning: MySQL Connection Failed: Access denied for user: 'root@MY_PC'
 (Using password: YES) in C:\...\dbconnect.inc on line 3
 Cannot connect to The Database.

You need to grant privileges to log in as root remotely, which is 
probably not recommended.  Basically a GRANT statement that lets people 
access MySQL as root from your IP address.

Better to create a new user (such as phpuser or something) and enable 
that one instead.



Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Security problem?

2002-06-25 Thread Erik Price


On Tuesday, June 25, 2002, at 03:46  PM, Peter wrote:

 When you have the standard

 $link = mysql_connect(localhost,username,secretpassword);

 Would it not be possible for someone to use PHP from another server to
 download your source and find out your MySQL details including password?

Yes.  If they have access to the source, they can see these values.  If 
they don't have some way of seeing those files, though, they won't be 
able to do it.

For this reason it is a good idea to make sure that no one except you 
and the user that the webserver runs as can read your files.  For 
instance, all my files are actually readable to all (their mode is 644), 
except for one.  This one file is readable only to me and members the 
apache group, and it contains all of the database connection 
parameters.  Of course, the only member of the apache group is the 
apache user that the web server runs as, so no one else will be 
reading this file.

It's a luxury of having root access on my server, since this is pretty 
difficult to do without a root user (catch 22 -- how do you change the 
file to the apache group unless you are a member of the apache 
group, but if you are a member of the apache group then you can see 
all of the protected files in that group).

Also I have a directive that prevents Apache from serving any file with 
.inc suffix, and this file does, so Apache (hopefully) won't serve 
this data to the world via port 80.



Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Menu Selections Dynamic from a Database

2002-06-25 Thread Erik Price
 can be sure that it'll work, etc.  I 
personally wouldn't even bother, this kind of coding is pretty technical 
and you may as well just do it in PHP in case the user doesn't have JS 
turned on.  I think it's a lot easier to do it in PHP too.  Sure, the 
user will have to submit the page to update the new listbox, but... not 
so hard, eh?  Essentially it boils down to this pseudocode:

1. use PHP to dynamically generate a main listbox to control the next 
listbox
2. use PHP to dynamically generate possible values for the secondary 
listbox (I would just throw 'em in arrays)
3. determine which array should populate the second listbox based on the 
input in the first listbox using JavaScript event handlers in the first 
listbox



HTH,


Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] More on removing item from cart

2002-06-25 Thread Erik Price


On Tuesday, June 25, 2002, at 04:28  PM, Vicki wrote:

 I have a shopping cart array $cart, with $artID as its key ($artID is an
 integer). $cart is set as a session variable. The cart prints to the
 browser with checkboxes next to each article and instructions to uncheck
 the checkbox and click on the Save Changes button to remove items from
 the cart. (This is the part that doesn't work.) The checkbox input has
 NAME = checkbox[$artID] VALUE = yes, and there is a hidden input with
 NAME = save VALUE = true that are passed when the form is submitted.

Before we even discuss the logic of your code, I need you to confirm 
that you are

1) properly quoting your attributes (some browsers will react badly if 
you don't)
2) not using the actual value checkbox[$artID] in your code

With 2, in other words I am making sure you are not trying to pass an 
array element name via HTTP.  The name of any HTML form input needs to 
be made up of letters, underscores, and numbers, IIRC.

As far as the logic goes, forgive me for being blunt but your 
explanation is confusing me and I can't really follow it.  If you have 
neat, commented code, post the relevant part of it and hopefully someone 
can come up with some good input (I'll take a stab).

Basically checkboxes are tricky, because if a checkbox is NOT checked, 
and then the form is submitted, an empty variable name is NOT sent... 
only checked boxes are sent.  So you need to check for the presence of 
variables if you are going to unset() the unchecked boxes, or determine 
the unchecked values based on what is NOT checked, etc.


Good luck


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] PHP 4.2

2002-06-24 Thread Erik Price


On Sunday, June 23, 2002, at 09:06  AM, Pekka Saarinen wrote:

 Most virtual server users have no means to set PHP.INI to their liking 
 so changes like that should be done in longer time span to let 
 developers update the software _before_ changes in PHP happen.

What about ini_set() ?

http://www.php.net/manual/en/function.ini-set.php






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Whos online at the moment in PHP

2002-06-24 Thread Erik Price


On Sunday, June 23, 2002, at 09:53  AM, Pag wrote:

   Is it possible to code in PHP a small indicator on a site saying 
 how many people are viewing that page at the moment?
   Sorry if its a silly question, but i am a newbie at PHP. If it is, 
 could you point me in the good direction? i mean, some function or 
 something.

Sorry, can't be done.  People aren't really online when they are using 
a web browser.  They request a page, and it gets sent to them, and the 
web server forgets about them.  Unless the web server logged their 
request, but then the web server has no way of knowing when the user 
stops looking at the page, so... you get the picture.

You'd have to write a Java applet or something that can maintain state.  
HTTP can't do this.  Unless you're really creative and you use 
JavaScript and sessions (and even then it won't be very reliable).


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




  1   2   3   4   5   6   7   >