From phillip.powell at adnet-sys.com Sat May 1 16:38:11 2004
From: phillip.powell at adnet-sys.com (Phillip Powell)
Date: Sat, 01 May 2004 16:38:11 -0400
Subject: [nycphp-talk]
Problem with $_SESSION, PHP 4.3.2, register_globals off,
class methods
Message-ID: <40940AB3.6090507@adnet-sys.com>
Very first lines of index.php:
[PHP]
session_start(); // USED FOR ANY STORED SESSION VARIABLES (ONLY
HAS TO BE SET HERE)
echo "PHPSESSID = $PHPSESSID
";
echo "SESSION the moment you first enter this script of $PHP_SELF is: ";
print_r(array_keys($_SESSION)); echo'
';
[/PHP]
This is what you see the moment you first go into index.php and have not
yet submitted a search query:
[QUOTE]
PHPSESSID = a964d0d6683757cafbe5576737ea5bf9
SESSION the moment you first enter this script of
/image_catalog/index.php is: Array ( [0] => search [1] => sql )
[/QUOTE]
Ok, now you submitted a search query. You entered some form stuff and
submitted. You're now at the search results page (which is also
"index.php"); this is what you see:
[QUOTE]
PHPSESSID = a964d0d6683757cafbe5576737ea5bf9
SESSION the moment you first enter this script of
/image_catalog/index.php is: Array ( [0] => search [1] => sql )
GET: Array ( )
POST: Array ( [0] => image_name [1] => allAlbums [2] => album [3] =>
boolword [4] => keywords [5] => persons [6] => events [7] => image_alt
[8] => image_creation_start_month [9] => image_creation_start_day [10]
=> image_creation_start_year [11] => image_creation_end_month [12] =>
image_creation_end_day [13] => image_creation_end_year [14] =>
image_location_city [15] => image_location_state [16] =>
image_location_country [17] => sortBy [18] => search [19] =>
isFromSearch [20] => section )
SESSION: Array ( [0] => search [1] => sql )
PHPSESSID = a964d0d6683757cafbe5576737ea5bf9
SESSION after setting it is: Array ( [0] => search [1] => sql [2] =>
hidden )
[/QUOTE]
(note: to save space and sensitive info I am not doing:
[PHP]print_r($_POST);[/PHP] but instead I'm using
[PHP]print_r(array_keys($_POST));[/PHP], and the same with $_GET)
$_SESSION['sql'] is set via an instance of SearchPerformer object that
runs the generateSearchSQL() method:
[PHP]
class SearchPerformer extends DBActionPerformer {
function SearchPerformer () { // CONSTRUCTOR
$this->doSearch(); // THIS METHOD RUNS generateSearchSQL()
}
function &displayResults() { // STATIC HTML STRING METHOD
$html = SearchView::retainFormElements($html); // SEE BELOW FOR
CODE DETAIL
// DO MORE STUFF TO $html
return $html;
}
function generateSearchSQL() { // SQL STRING METHOD
// BUILD $sql HERE WITH STUFF
$_SESSION['sql'] = $sql;
// DO MORE STUFF
return $sql;
}
}
$performer =& new SearchPerformer(); // CONSTRUCTOR
[/PHP]
So everything is fine so far; I have $_SESSION['sql'] and I even have
$_SESSION['hidden'] which is set via the displayResults() method in the
SearchPerformer object, it running this class method (class SearchView
is *NOT* instantiated here!!!):
[PHP]
class SearchView extends View {
function SearchView() {} // CONSTRUCTOR (you will be
instantiating SearchView objects elsewhere, just not in
SearchPerformer's methods)
function &retainFormElements(&$html) { // STATIC
HTML METHOD
print_r("
");
if ((!is_array($_POST) || @sizeof(array_values($_POST)) == 0) &&
$_SESSION['hidden']) {
$html .= $_SESSION['hidden'];
} else {
/*--------------------------------------------------------------------------------------------------------------------
Set $collection to either $_POST (if form post variables
exist in $_POST) or default to $_GET
to parse through either/or and produce HTML hidden elements
in either case
---------------------------------------------------------------------------------------------------------------------*/
$collection = ($_POST && is_array($_POST) &&
@sizeof(array_values($_POST)) > 0) ? $_POST : $_GET;
foreach ($collection as $key => $val) {
if (!is_array($val)) {
$hiddenHTMLRetainer .= "\n";
$html .= "\n"; // ADD FROM QS TO PASS BACK
} else {
foreach ($val as $innerKey => $indivVal) {
if ($indivVal) {
$hiddenHTMLRetainer .= "\n"; // PUT IN
INDIVIDUAL ARRAY ELEMENTS
$hiddenHTMLRetainer .= "]\" value=\"$indivVal\">\n";
}
}
}
}
$_SESSION['hidden'] = $hiddenHTMLRetainer;
global $PHPSESSID;
print_r("PHPSESSID = "); print_r($PHPSESSID); print_r("
");
print_r('SESSION after setting it is: ');
print_r(array_keys($_SESSION));
}
return $html;
}
}
[/PHP]
Now, in the search results page I click a link to sort my results. The
link takes me back to, you guessed it, index.php (in fact, every single
portion of my application literally has only one address: "index.php"
and nowhere else). The moment I do that, this is what I see:
[QUOTE]
PHPSESSID = a964d0d6683757cafbe5576737ea5bf9
SESSION the moment you first enter this script of
/mu-spin/image_catalog/index.php is: Array ( [0] => search [1] => sql )
GET: Array ( [0] => section [1] => search [2] => isSort [3] => sortBy )
POST: Array ( )
SESSION: Array ( [0] => search [1] => sql )
PHPSESSID = a964d0d6683757cafbe5576737ea5bf9
SESSION after setting it is: Array ( [0] => search [1] => sql [2] =>
hidden )
[/QUOTE]
This is totally wrong!!! The $_SESSION['hidden'] variable is gone!!! It
is, in fact, erroneously RESET once again (with the wrong values),
whereas it was supposed to have been retained within $_SESSION
superglobal array, yet it is not.
I hope this makes it a bit more clear as to what is literally going on.
Synopsis:
1) I go to index.php
2) I see $_SESSION
3) I submit form elements
4) I see $_SESSION
5) I add $_SESSION['sql'] in generateSearchSQL() method
6) I add $_SESSION['hidden'] in SearchView::retainFormElements() method
7) I see $_SESSION with both elements
8) I click a link to go back to index.php
9) I see $_SESSION.. with just 'sql' and NOT 'hidden'
10) I tear my hair out, what little I have left!
Phil
--
---------------------------------------------------------------------------------
Phil Powell
Multimedia Programmer
ADNET Systems., Inc.
11260 Roger Bacon Drive Suite 403
Reston, VA 20191
#: (703) 709-7218 x107
Fax: (703) 709-7219
From cwf at axlotl.net Sat May 1 18:50:33 2004
From: cwf at axlotl.net (chris)
Date: Sat, 1 May 2004 18:50:33 -0400
Subject: [nycphp-talk] confused by classes
Message-ID: <200405011850.34004.cwf@axlotl.net>
The first program I wrote a couple months ago was (of course) an email program
and now I feel it's time to try to learn the OOP aspects, so I thought I'd
rewrite that program. After a few days, I've become utterly confused. I've
been trying to figure out which question to ask; this one seems to capture
several of the issues confusing me.
Each user can have several mail servers, and it seemed useful to start once a
user logged into a session by constructing an object containing server
addresses and passwords, and then maybe add in methods as needed. So I made
this class (stripped down):
class mailUser{
? ? ? ? var $user;
function mailUser ($user){
? ? $dsn = 'mysql://username:pass at localhost/db';
? ? $dbh = DB::connect($dsn);
? ? $user = $dbh->quote($user);
? ? $this->user = $dbh->getAssoc("SELECT server, m_user, m_pass, pop, smtp,
u.name
? ? ? ? FROM servers s, users u, server_pass sp
? ? ? ? WHERE sp.user_id = u.id
? ? ? ? AND sp.server_id = s.id
? ? ? ? AND u.username LIKE $user");
? ? }
}
And then when a user is logged in (returns $user ) I go:
$cur_user = new mailUser($user);
This gives me an object with an array of servers, each of those having an
array of parameters. But I guess what I really need, maybe, is a class that
returns
$this->server
with a few methods (seperate queries?) to extract the parameters specific to
the currently active server? I'm trying that now, but it's maybe my twelfth
scheme, and it'd be nice once it fails to pan out to check this list to see
if anyone has some pointers.
So, I realize it's a rather broad query; anyone in a pedagogical frame of mind
today?
Ending my lurking ways,
Chris
From jonbaer at jonbaer.net Sat May 1 21:17:05 2004
From: jonbaer at jonbaer.net (jon baer)
Date: Sat, 1 May 2004 21:17:05 -0400
Subject: [nycphp-talk] [ot] open source "Security" is amazing to watch ...
Message-ID: <004e01c42fe3$40cffa30$6500a8c0@thinkpad>
if you are on bugtraq or other "security" related lists, its amazing how
fast things go from discovery to exposure to exploit code to viruses in
literally hours ...
http://www.microsoft.com/security/incident/sasser.asp
what in the world can the point be to post virus code when you *know* it
will always be used for bad purposes in the end?
- jon
pgp key: http://www.jonbaer.net/jonbaer.asc
fingerprint: F438 A47E C45E 8B27 F68C 1F9B 41DB DB8B 9A0C AF47
From Rafi.Sheikh at Ingenix.com Sun May 2 21:17:25 2004
From: Rafi.Sheikh at Ingenix.com (Rafi Sheikh)
Date: Sun, 2 May 2004 20:17:25 -0500
Subject: [nycphp-talk] RE: [tcphp] Hella fun project I'm about to throw at
some tech col lege students
Message-ID:
Hi List. A quick question. I have some categories that are really long
and I would like to re-word or re-format them when I am bring data in from a
DB. Now which would be better:
Do it with PHP
or
Do it with MySQL
Any suggestions as to how to?
Example:
A column name: Customer --> VARCHAR
Values in Customer: "USA-North Upper ABVDFR Co. and Sons"
I would like to re-word it for example: ABVDFR Co.
I know I could use SUBSTRING or MID, or replace but the issue is since the
column is a VARCHAR, the length of the value may change from row to row, for
example: one row it maybe 20, in the next 13 and so on so forth. I also
thought that if I could use a length statement and come up with a
formula...but so far no success....any suggestions?
Thx in Adv.
RS
This e-mail, including attachments, may include confidential and/or
proprietary information, and may be used only by the person or entity to
which it is addressed. If the reader of this e-mail is not the intended
recipient or his or her authorized agent, the reader is hereby notified that
any dissemination, distribution or copying of this e-mail is prohibited. If
you have received this e-mail in error, please notify the sender by replying
to this message and delete this e-mail immediately.
From danielc at analysisandsolutions.com Sun May 2 23:10:49 2004
From: danielc at analysisandsolutions.com (Daniel Convissor)
Date: Sun, 2 May 2004 23:10:49 -0400
Subject: [nycphp-talk] confused by classes
In-Reply-To: <200405011850.34004.cwf@axlotl.net>
References: <200405011850.34004.cwf@axlotl.net>
Message-ID: <20040503031049.GA22394@panix.com>
On Sat, May 01, 2004 at 06:50:33PM -0400, chris wrote:
First, your coding style needs improvement. See
http://pear.php.net/manual/en/standards.php
> class mailUser{
> ? ? ? ? var $user;
> function mailUser ($user){
> ? ? $dsn = 'mysql://username:pass at localhost/db';
> ? ? $dbh = DB::connect($dsn);
Assign the return by reference in order to conserve memory, etc:
? ? $dbh =& DB::connect($dsn);
> ? ? $user = $dbh->quote($user);
quote() is deprecated. Use quoteSmart().
> ? ? $this->user = $dbh->getAssoc("SELECT server, m_user, m_pass, pop, smtp,
... snip ...
So, there can be multiple rows of data returned for a given user? If it's
only one row, use getRow().
>? ? ? ? AND u.username LIKE $user");
Don't you mean "= $user" rather than "LIKE $user"?
> And then when a user is logged in (returns $user ) I go:
> $cur_user = new mailUser($user);
Again, do that with "=&" to assign by reference instead of assigning a
copy.
> This gives me an object with an array of servers, each of those having an
> array of parameters. But I guess what I really need, maybe, is a class that
> returns
> $this->server
> with a few methods (seperate queries?) to extract the parameters specific to
> the currently active server?
It's not clear what you're looking for here.
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
From shiflett at php.net Mon May 3 02:37:21 2004
From: shiflett at php.net (Chris Shiflett)
Date: Sun, 2 May 2004 23:37:21 -0700 (PDT)
Subject: [nycphp-talk] [ot] open source "Security" is amazing to watch ...
In-Reply-To: <004e01c42fe3$40cffa30$6500a8c0@thinkpad>
Message-ID: <20040503063721.47469.qmail@web14311.mail.yahoo.com>
--- jon baer wrote:
> what in the world can the point be to post virus code when you
> *know* it will always be used for bad purposes in the end?
While posting a virus definitely seems to cross an ethical boundary of
some sort, I think an exploit is an essential piece of a security
vulnerability announcement. It really helps developers to both clearly
understand the vulnerability and gauge the danger. However, this is
frequently debated.
Chris
=====
Chris Shiflett - http://shiflett.org/
PHP Security - O'Reilly
Coming Fall 2004
HTTP Developer's Handbook - Sams
http://httphandbook.org/
PHP Community Site
http://phpcommunity.org/
From yury at heavenspa.com Mon May 3 09:44:06 2004
From: yury at heavenspa.com (yury at heavenspa.com)
Date: Mon, 3 May 2004 09:44:06 -0400
Subject: [nycphp-talk] dynamic jump menu from flatfile
References: <40926961.90608@ceruleansky.com> <20040430150050.GA27073@panix.com>
Message-ID: <00a401c43114$b4551bc0$0400a8c0@heavenspanyc>
Hiya folks.. was juts sitting here wondering if there was a way to make a
jump menu that got its info from a flat file.
This way you can just drop the jump menu into your web pages and have 1 file
( text/php/include) which changes the
jump menu details accross the whole website..
any ideas? and is this even possible.
regards
yury
From danielc at analysisandsolutions.com Mon May 3 10:00:21 2004
From: danielc at analysisandsolutions.com (Daniel Convissor)
Date: Mon, 3 May 2004 10:00:21 -0400
Subject: [nycphp-talk] dynamic jump menu from flatfile
In-Reply-To: <00a401c43114$b4551bc0$0400a8c0@heavenspanyc>
References: <40926961.90608@ceruleansky.com> <20040430150050.GA27073@panix.com>
<00a401c43114$b4551bc0$0400a8c0@heavenspanyc>
Message-ID: <20040503140020.GA22575@panix.com>
Hola:
On Mon, May 03, 2004 at 09:44:06AM -0400, yury at heavenspa.com wrote:
> Hiya folks.. was juts sitting here wondering if there was a way to make a
> jump menu that got its info from a flat file.
I use an array contained in a separate for navigation items on some sites.
The array's key is the name of the file and the value is the text to
appear in the hyperlink.
Later,
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
From yury at heavenspa.com Mon May 3 10:09:36 2004
From: yury at heavenspa.com (yury at heavenspa.com)
Date: Mon, 3 May 2004 10:09:36 -0400
Subject: [nycphp-talk] dynamic jump menu from flatfile
References: <40926961.90608@ceruleansky.com>
<20040430150050.GA27073@panix.com><00a401c43114$b4551bc0$0400a8c0@heavenspanyc>
<20040503140020.GA22575@panix.com>
Message-ID: <00d101c43118$445df180$0400a8c0@heavenspanyc>
Dan, can you please reply with a simple/easy to follow example
thanks
yury
----- Original Message -----
From: "Daniel Convissor"
To: "NYPHP Talk"
Sent: Monday, May 03, 2004 10:00 AM
Subject: Re: [nycphp-talk] dynamic jump menu from flatfile
> Hola:
>
> On Mon, May 03, 2004 at 09:44:06AM -0400, yury at heavenspa.com wrote:
> > Hiya folks.. was juts sitting here wondering if there was a way to make
a
> > jump menu that got its info from a flat file.
>
> I use an array contained in a separate for navigation items on some sites.
> The array's key is the name of the file and the value is the text to
> appear in the hyperlink.
>
> Later,
>
> --Dan
>
> --
> T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
> data intensive web and database programming
> http://www.AnalysisAndSolutions.com/
> 4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>
From danielk at us.ibm.com Mon May 3 10:13:49 2004
From: danielk at us.ibm.com (Daniel Krook)
Date: Mon, 3 May 2004 10:13:49 -0400
Subject: [nycphp-talk] dynamic jump menu from flatfile
In-Reply-To: <00a401c43114$b4551bc0$0400a8c0@heavenspanyc>
Message-ID:
>Hiya folks.. was juts sitting here wondering if there was a way to make a
>jump menu that got its info from a flat file.
Certainly is possible, try something like this...
';
foreach ($lines as $line) {
$items = explode('|', $line);
$html .= sprintf('');
}
echo ($html . '');
}
The JavaScript function in the select tag is:
/**
* Jumps to the selected item in the dropdown list .
*/
function go (dropdown) {
location.href =
dropdown.options[dropdown.selectedIndex].value;
}
Daniel Krook, Application Developer
WW Web Production Services North 2, ibm.com
1133 Westchester Avenue, White Plains, NY 10604
Personal: http://info.krook.org/
Persona: http://w3.ibm.com/eworkplace/persona_bp_finder.jsp?CNUM=C-0M7P897
From danielc at analysisandsolutions.com Mon May 3 10:17:12 2004
From: danielc at analysisandsolutions.com (Daniel Convissor)
Date: Mon, 3 May 2004 10:17:12 -0400
Subject: [nycphp-talk] dynamic jump menu from flatfile
In-Reply-To: <00d101c43118$445df180$0400a8c0@heavenspanyc>
References: <40926961.90608@ceruleansky.com> <20040503140020.GA22575@panix.com>
<00d101c43118$445df180$0400a8c0@heavenspanyc>
Message-ID: <20040503141712.GA23559@panix.com>
Yuri:
On Mon, May 03, 2004 at 10:09:36AM -0400, yury at heavenspa.com wrote:
> Dan, can you please reply with a simple/easy to follow example
> thanks
See http://nyphp.org/content/presentations/bikesummer/navigation.php
and the frame after it as well.
The example doesn't show the foreach loop used to extract the data from
the array and print out the stuff, but here's a summary:
foreach ($Nav1 as $Page => $Title) {
echo '' . $Title . "\n";
}
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
From danielk at us.ibm.com Mon May 3 10:18:38 2004
From: danielk at us.ibm.com (Daniel Krook)
Date: Mon, 3 May 2004 10:18:38 -0400
Subject: [nycphp-talk] dynamic jump menu from flatfile
In-Reply-To:
Message-ID:
Sorry, Monday morning. My example should have looked like this:
';
foreach ($lines as $line) {
$items = explode('|', $line);
$html .= sprintf('', $items[0],
$items[1]);
}
echo ($html . '');
}
Daniel Krook, Application Developer
WW Web Production Services North 2, ibm.com
1133 Westchester Avenue, White Plains, NY 10604
Personal: http://info.krook.org/
Persona: http://w3.ibm.com/eworkplace/persona_bp_finder.jsp?CNUM=C-0M7P897
From danielc at analysisandsolutions.com Mon May 3 10:18:54 2004
From: danielc at analysisandsolutions.com (Daniel Convissor)
Date: Mon, 3 May 2004 10:18:54 -0400
Subject: [nycphp-talk] dynamic jump menu from flatfile
In-Reply-To:
References: <00a401c43114$b4551bc0$0400a8c0@heavenspanyc>
Message-ID: <20040503141854.GB23559@panix.com>
Folks:
On Mon, May 03, 2004 at 10:13:49AM -0400, Daniel Krook wrote:
>
> function drawNav () {
... snip ...
> $html = '';
Of course, don't forget to embed that in a