|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
php-general-digest-help
lists.php.net
Date: Fri Mar 21 2008 - 02:44:14 CDT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
php-general Digest 21 Mar 2008 07:44:14 -0000 Issue 5359
Topics (messages 271887 through 271928):
Re: selling gpl software?
271887 by: Larry Garfield
271913 by: Colin Guthrie
Re: Double click problem
271888 by: Lamp Lists
271898 by: Eric Butera
271901 by: Lamp Lists
Re: Fastest way to get table records' number
271889 by: Philip Thompson
Re: Will the progress bar like Xupload add too much weight to the Apache server?
271890 by: Daniel Brown
271927 by: Shelley
Re: php book
271891 by: Lamp Lists
271895 by: Wolf
Re: algorithm of pages beaking
271892 by: tedd
271894 by: Robert Cummings
Re: Checking how many letters are in a string.
271893 by: tedd
271897 by: Edward Kay
Re: Newbie question, Which way is best?
271896 by: Philip Thompson
271900 by: George J
271915 by: Shawn McKenzie
271916 by: George J
271919 by: Philip Thompson
newbie question about one php script passing control to another
271899 by: Rod Clay
271902 by: admin.buskirkgraphics.com
271907 by: Rod Clay
271914 by: Daniel Brown
271917 by: Rick Pasotto
271918 by: tedd
why use {} around vraiable?
271903 by: Lamp Lists
271904 by: Robert Cummings
271905 by: Jason Pruim
271906 by: Nathan Nobbe
271908 by: Ray Hauge
271909 by: Robin Vickery
271911 by: Brady Mitchell
271912 by: Lamp Lists
Re: Playing around with strings
271910 by: Robin Vickery
MCrypt not decrypting simple text
271920 by: Dan
Convert html to pdf with php
271921 by: Robert Burdo
271923 by: Philip Thompson
271924 by: Al
271928 by: Kai Kauer
question about customized error
271922 by: Sudhakar
271925 by: Jim Lucas
Re: fwrite/fclose troubles
271926 by: Mark Weaver
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscribe
lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscribe
lists.php.net
To post to the list, e-mail:
php-general
lists.php.net
----------------------------------------------------------------------
attached mail follows:
On Thursday 20 March 2008, Colin Guthrie wrote:
> Larry Garfield wrote:
> > On Wednesday 19 March 2008, Colin Guthrie wrote:
> >> Also as it's GPL and as you are "supplying" the modifications you make
> >> to your client, you are obliged to release the changes you make to the
> >> community. If this was a 100% internal development (e.g. you are
> >> employed directly by your client, not as a contractor), then you are not
> >> obliged to release the changes.
> >
> > Not true. If you take an open source project, modify it, and give a copy
> > to your client, you are under no obligation to give anyone else in the
> > world a copy of your modified code. What you ARE required to do is give
> > that modified to code to your client under the GPL so that he can, if he
> > wants to, share it with the world, and anyone he gives a copy to can also
> > share it with the world if they want to, etc.
>
> Is that true? I would have thought that by developing under contract and
> then subsequently "supplying" your modifications to your client, this
> constitutes "distribution" of the code. It is this "distribution" of the
> code that I've always considered the trigger for "having" to share it
> back to the community - e.g. if your changes are internal to your
> company you don't need to share it. Earlier I wrote that whether he was
> employed directly or as a contractor would have bearing and this
> statement was based on the above understanding. Am I wrong?
>
> Col
If the code is "work for hire" and the initial ownership is with the
client/company, then there is no distribution and so you are not required to
do anything. That includes if you are a full time employee of the company.
If the code you write is owned by you and given to a client, that is
distribution. You can either give the client a copy of the source at the
same time, in which case you needn't share it with anyone else, or say "you
can get it from this FTP if you want", in which case anyone may access it
because when the client distributes the "runnable version" of the code to
someone else, they will also say "and you can get it from this FTP if you
want".
As PHP is its own source code, the latter is generally not an issue since the
source code is provided automatically.
So in the OP's case, if he takes an existing GPLed project, modifies it in
whatever way (including removing mention of the original project), and gives
a copy to his client, his only legal obligation is to provide the client with
the code under the GPL so that the client can, if he wants, pass the code on
to someone else under the GPL. "Someone else" could be a public FTP server
or not.
--
Larry Garfield AIM: LOLG42
larry
garfieldtech.com ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
attached mail follows:
Larry Garfield wrote:
> If the code is "work for hire" and the initial ownership is with the
> client/company, then there is no distribution and so you are not required to
> do anything. That includes if you are a full time employee of the company.
OK, that's more or less my understanding.
It is my understanding that, by default, contracting law states that any
work done under contract is your (the contractor's) copyright (e.g. on a
very loose contract that is the default case). Many employers of
contractors will typically change this default stance.
> So in the OP's case, if he takes an existing GPLed project, modifies it in
> whatever way (including removing mention of the original project), and gives
> a copy to his client, his only legal obligation is to provide the client with
> the code under the GPL so that the client can, if he wants, pass the code on
> to someone else under the GPL. "Someone else" could be a public FTP server
> or not.
I was half assuming the stance of the employer here was that he did not
want the changes shared.
So assuming this and the above note about contract law etc., then my
original statement is correct.
Whether these assumptions are correct in themselves (and this my whole
thread of assumption breaks down!), I'll leave for future research and
happily live in my bubble of ignorance ;)
Col
attached mail follows:
the way I solved the "click back button" issue (simplified vresion):
confirmation page (conf.php) -> transfer page (tp.php) -> thank you page (typ.php)
#conf.php
# after the form is submitted and confirmed
header('location: tp.php?url=typ.php');
exit;
#tp.php
header('location:$_GET['url']);
exit;
and, if visitor clicks on back button on thakyou page he will go actually to the transfer page - which will send him back to thankyou page
;)
-ll
----- Original Message ----
From: tedd <tedd.sperling
gmail.com>
To: php-general
lists.php.net
Sent: Wednesday, March 19, 2008 11:43:06 AM
Subject: Re: [PHP] Double click problem
At 4:19 PM +0000 3/19/08, Richard Heyes wrote:
>tedd wrote:
>// ...
>
>Your first (and the quickest by far) method to employ would be to
>disable the submit button using Jabbascript when the form is
>submitted. That will stop the vast majority of occurrences. You
>could also employ an intermediary page which actually does the card
>processing and when complete redirects to the "thank you" page. ie.
>
> Form --> "Please wait..." page --> "Thank you" page
That's in place. The person clicks the "confirm purchase" and they
are taken to a "confirm and thank you page".
The problem here is two fold -- 1) clicking the "confirm
purchase"button twice, which I think js will stop; 2) and clicking
the back-button which the token should stop.
Now, I just need to develop a test for this. Sometime writing a test
is more of a problem than writing the solution.
Thanks for everyone's help.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
attached mail follows:
On Thu, Mar 20, 2008 at 10:39 AM, Lamp Lists <lamp.lists
yahoo.com> wrote:
> the way I solved the "click back button" issue (simplified vresion):
>
> confirmation page (conf.php) -> transfer page (tp.php) -> thank you page (typ.php)
>
> #conf.php
> # after the form is submitted and confirmed
> header('location: tp.php?url=typ.php');
> exit;
>
> #tp.php
> header('location:$_GET['url']);
> exit;
>
> and, if visitor clicks on back button on thakyou page he will go actually to the transfer page - which will send him back to thankyou page
> ;)
>
> -ll
>
>
>
>
>
> ----- Original Message ----
> From: tedd <tedd.sperling
gmail.com>
> To: php-general
lists.php.net
> Sent: Wednesday, March 19, 2008 11:43:06 AM
> Subject: Re: [PHP] Double click problem
>
> At 4:19 PM +0000 3/19/08, Richard Heyes wrote:
> >tedd wrote:
> >// ...
> >
> >Your first (and the quickest by far) method to employ would be to
> >disable the submit button using Jabbascript when the form is
> >submitted. That will stop the vast majority of occurrences. You
> >could also employ an intermediary page which actually does the card
> >processing and when complete redirects to the "thank you" page. ie.
> >
> > Form --> "Please wait..." page --> "Thank you" page
>
> That's in place. The person clicks the "confirm purchase" and they
> are taken to a "confirm and thank you page".
>
> The problem here is two fold -- 1) clicking the "confirm
> purchase"button twice, which I think js will stop; 2) and clicking
> the back-button which the token should stop.
>
> Now, I just need to develop a test for this. Sometime writing a test
> is more of a problem than writing the solution.
>
> Thanks for everyone's help.
>
> Cheers,
>
> tedd
>
>
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> ____________________________________________________________________________________
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
Allowing unscrubbed user data in a header is a really bad idea.
- http://en.wikipedia.org/wiki/HTTP_response_splitting
- http://www.owasp.org/index.php/Open_redirect
attached mail follows:
----- Original Message ----
From: Eric Butera <eric.butera
gmail.com>
To: Lamp Lists <lamp.lists
yahoo.com>
Cc: tedd <tedd.sperling
gmail.com>; php-general
lists.php.net
Sent: Thursday, March 20, 2008 11:00:19 AM
Subject: Re: [PHP] Double click problem
On Thu, Mar 20, 2008 at 10:39 AM, Lamp Lists <lamp.lists
yahoo.com> wrote:
> the way I solved the "click back button" issue (simplified vresion):
>
> confirmation page (conf.php) -> transfer page (tp.php) -> thank you page (typ.php)
>
> #conf.php
> # after the form is submitted and confirmed
> header('location: tp.php?url=typ.php');
> exit;
>
> #tp.php
> header('location:$_GET['url']);
> exit;
>
> and, if visitor clicks on back button on thakyou page he will go actually to the transfer page - which will send him back to thankyou page
> ;)
>
> -ll
>
>
>
>
>
> ----- Original Message ----
> From: tedd <tedd.sperling
gmail.com>
> To: php-general
lists.php.net
> Sent: Wednesday, March 19, 2008 11:43:06 AM
> Subject: Re: [PHP] Double click problem
>
> At 4:19 PM +0000 3/19/08, Richard Heyes wrote:
> >tedd wrote:
> >// ...
> >
> >Your first (and the quickest by far) method to employ would be to
> >disable the submit button using Jabbascript when the form is
> >submitted. That will stop the vast majority of occurrences. You
> >could also employ an intermediary page which actually does the card
> >processing and when complete redirects to the "thank you" page. ie.
> >
> > Form --> "Please wait..." page --> "Thank you" page
>
> That's in place. The person clicks the "confirm purchase" and they
> are taken to a "confirm and thank you page".
>
> The problem here is two fold -- 1) clicking the "confirm
> purchase"button twice, which I think js will stop; 2) and clicking
> the back-button which the token should stop.
>
> Now, I just need to develop a test for this. Sometime writing a test
> is more of a problem than writing the solution.
>
> Thanks for everyone's help.
>
> Cheers,
>
> tedd
>
>
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> ____________________________________________________________________________________
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
Allowing unscrubbed user data in a header is a really bad idea.
- http://en.wikipedia.org/wiki/HTTP_response_splitting
- http://www.owasp.org/index.php/Open_redirect
I agree with you to use exactly this way is bad idea.
But, as I said on the begining of my post it's "simplified version", to get my point. My code on tp.php actually use sveral validations before forward to thank you page :D
-ll
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
attached mail follows:
On Mar 19, 2008, at 11:55 PM, Shelley wrote:
> Nathan Nobbe wrote:
>> On Wed, Mar 19, 2008 at 9:42 AM, Andrew Ballard
>> <aballard
gmail.com> wrote:
>>
>>
>>> That works; I'm just wondering why you went with a count on an
>>> 'ID' column
>>> rather than COUNT(*).
>>>
>>
>>
>> ouch, it looks like im horribly wrong :O
>> mysql> select count(*) from table;
>> +----------+
>> | count(*) |
>> +----------+
>> | 361724 |
>> +----------+
>> 1 row in set (0.90 sec)
>>
>> mysql> select count(id) from table;
>> +------------+
>> | count(did) |
>> +------------+
>> | 361724 |
>> +------------+
>> 1 row in set (4.56 sec)
>>
>> -nathan
>>
>>
> The archive of my results was saved here:
> http://phparch.cn/index.php/mysql/35-MySQL-programming/126-fastest-way-to-get-total-records-from-a-table
Just an FYI about your article. "Evan" is supposed to be spelled
"even". ;)
> --
> Regards,
> Shelley ( PHP Architecture: http://phparch.cn )
attached mail follows:
On Thu, Mar 20, 2008 at 2:32 AM, Shelley <myphplist
gmail.com> wrote:
> Hi all,
>
> Here is the Xupload progress bar link:
> http://www.sibsoft.net/xupload.html
>
> My question is:
> Will the upload progress bar like that add too much weight to the Apache
> server, especially to a server with millions of visitors each day?
You consistently ask irrelevant questions here. Not only is
Xupload not written in PHP, your question relates to Perl and Apache
--- not at all to PHP.
Please select the correct list when asking questions.
--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283
attached mail follows:
Sorry. I won't. :(
On Thu, Mar 20, 2008 at 11:01 PM, Daniel Brown <parasane
gmail.com> wrote:
> On Thu, Mar 20, 2008 at 2:32 AM, Shelley <myphplist
gmail.com> wrote:
> > Hi all,
> >
> > Here is the Xupload progress bar link:
> > http://www.sibsoft.net/xupload.html
> >
> > My question is:
> > Will the upload progress bar like that add too much weight to the
> Apache
> > server, especially to a server with millions of visitors each day?
>
> You consistently ask irrelevant questions here. Not only is
> Xupload not written in PHP, your question relates to Perl and Apache
> --- not at all to PHP.
>
> Please select the correct list when asking questions.
>
> --
> </Daniel P. Brown>
> Forensic Services, Senior Unix Engineer
> 1+ (570-) 362-0283
>
--
Regards,
Shelley
attached mail follows:
opinions of "good book is almost the same as opinion of "good car".
I can suggest you to go to barnes and noble or borders or any other bookstore, buy cup of coffee or tea, grab all php books from shelf and read some chapters. you are no going to learn anything, rather to compare "styles". some authors use a lot of code, some to much code, some explain to details some throw just links where to find more info, some explain functions with examples, some just "in general"... you know what I mean.
spend 2-3 hours going through the books and then pick one you like (the style) the most.
my 2 cents.
-ll
----- Original Message ----
From: alexus <alexus
gmail.com>
To: php-general
lists.php.net
Sent: Wednesday, March 19, 2008 9:50:23 AM
Subject: [PHP] php book
what book would you guys suggest for someone who's new and wants to learn php?
--
http://alexus.org/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
attached mail follows:
---- Lamp Lists <lamp.lists
yahoo.com> wrote:
> opinions of "good book is almost the same as opinion of "good car".
<!-- Snip -->
I myself prefer books along the lines of the "Sam's teach yourself * in * hours/minutes" series. I picked up the PHP/MySQL/Apache book when I first started learning PHP and still keep it around. I have looked at the "Bibles" around for PHP and other languages but prefer books that give you the entire chunk of code they are talking about instead of piece-mealing it together, It's the Context that is important to me.
But I generally keep a browser pointed to php.net and search the functions on the site while trying to get a particularly irritating bit of code to mesh with the rest.
YMMV,
Wolf
attached mail follows:
At 11:35 PM +0000 3/19/08, George J wrote:
>Hi,
>
>I'm trying to resolve an issue with a pagination routine. Sounds like we're
>working on a similar routine. I have a query returning products from a
>database and then display the results in a defined number of products per
>page.
>
>Checkout - 'Newbie question, Which way is best?' in this newsgroup.
>
>George
George:
Which is the "best" way? Well of course, my way. :-)
Here's a demo (with code):
http://webbytedd.com/bbb/paging/
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
attached mail follows:
On Thu, 2008-03-20 at 11:32 -0400, tedd wrote:
> At 11:35 PM +0000 3/19/08, George J wrote:
> >Hi,
> >
> >I'm trying to resolve an issue with a pagination routine. Sounds like we're
> >working on a similar routine. I have a query returning products from a
> >database and then display the results in a defined number of products per
> >page.
> >
> >Checkout - 'Newbie question, Which way is best?' in this newsgroup.
> >
> >George
>
> George:
>
> Which is the "best" way? Well of course, my way. :-)
>
> Here's a demo (with code):
>
> http://webbytedd.com/bbb/paging/
Your page pops up my JavaScript error console...
Reference to undefined variable: startup
>:)
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
attached mail follows:
At 9:10 AM +0200 3/20/08, Dotan Cohen wrote:
>On 20/03/2008, tedd <tedd.sperling
gmail.com> wrote:
> > At least, that's my understanding.
>>
>>
>> Cheers,
>>
>> tedd
>
>Thank you Tedd, that was very helpful. After reading your mail from
>yesterday I went to wikipedia to learn what graphemes and ligatures
>are. Your example of "fi" was there, otherwise I would have had no
>idea that those letters can be combined. In Hebrew and Arabic,
>especially, I can see how the vowel points (Hebrew) and combinations
>like "LA" (Arabic) can confuse the ASCII function. Thanks.
>
>Dotan Cohen
Dotan:
No problem -- if you want a great book on the subject, try:
Building Scalable Web Sites by Henderson
Chapter 4 is all about l16n, L10n, and Unicode. Makes a good read.
Plus, there's a lot more good stuff in that book.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
attached mail follows:
> -----Original Message-----
> From: tedd
> Chapter 4 is all about l16n, L10n, and Unicode. Makes a good read.
What's l16n?
Did you mean i18n (internationasation)?
(I'm not being a pedant; just wondered if I was missing something) :)
Edward
attached mail follows:
On Mar 19, 2008, at 5:13 PM, George J wrote:
> Hi Jason,
>
> Hope this helps -
> my 'display_products.php' script
> ----------
> <form method='post' action='display_products.php'>
> ...
> <input type='hidden' name= 'query' value=$query>
> <input type='submit' Value='Go'></td>
> ...
> // pagination routine
> conditional code...
> }else{
> echo("<a href=\"display_products.php?page=$i\"><img src=$st border=
> \"0\"
>> </a> ");
> }
> -----------
>
> So calling the script via the form works i.e it passes the neccessary
> variables to constrct the sql query for the next call. If the user
> clicks
> one of the pagination links, that calls itself, all that is passed
> is the
> page=$i variable. I need to include the 'SELECT * FROM...' query
> either as a
> string or an array of seperate values for the changed query.
>
> So, as I see it, the pagination links won't POST the form variables.
> How do
> I pass the 'SELECT * FROM mytable WHERE selection=option LIMIT
> start, range'
> query
> to the called script?
>
> George
I don't know if anyone has answered the question you have asked at
least twice... "How do I pass the query to the next page?" Here's how
I would approach it. Don't pass the query - all you need is the page
number. This code hasn't been tested, but I think you'll get the idea.
<?php
// thispage.php
if (isset ($_POST['submitted'])) {
$resultsPerPage = 50; // or whatever value
$page = mysql_real_escape_string ($_POST['page']);
$start = ($page * $resultsPerPage) - $resultsPerPage;
$length = $start + $resultsPerPage;
// Notice how you don't send the query in the POST or GET, just
the page number
$sql = "SELECT `field` FROM `table` WHERE (`field_a` =
'someValue') LIMIT $start, $length";
$results = mysql_query ($sql);
}
// Go to next page
$page = $_POST['page'] ? (int) $_POST['page'] + 1 : 1;
?>
...
<form method="post" action="thispage.php">
<input type="submit" value="Go" />
<input type="hidden" name="page" value="<?php echo htmlentities
($page); ?>" />
<input type="hidden" name="submitted" value="1" />
</form>
...
<?php
while ($row = mysql_fetch_array ($results, MYSQL_ASSOC)) {
// Display results
}
?>
Hopefully that helps a little bit.
~Philip
attached mail follows:
""Thiago Pojda"" <thiago.pojda
softpartech.com.br> wrote in message
news:004701c88a8a$eaab6480$0201a8c0
softpartech...
> De: George J [mailto:georgejamieson
btconnect.com]
>
>> So calling the script via the form works i.e it passes the
>> neccessary variables to constrct the sql query for the next
>> call.
>
> As Shawn said, if you really need the query again add it to session,
> never,
> NEVER give the user the ability to see/execute queries by himself
> (remember
> POST data could be easily manipulated). Remember what Daniel said, adding
> a
> DELETE FROM is not hard and veeery bad>
OK. I see the logic.
> Ok, let me ask you something. Why post to itself? You could have a script
> only to do form actions, that way you can:
> 1 Separate huge php validations with your html form.
> 2 Use functions to handle the incoming data and writing the new query (or
> the old one again).
I suspect that most folk in my position start the learning process by
finding a script that does a similar task and adapting it. This is basically
what I've done. I started by finding a form example and then added a
pagination routine then... Several deadends later... Not the best way to
write anything but the simplest of scripts. However, the numerous changes to
the code has entailed lots of learning during the process. So in answer to
your question. I didn't set out with any idea of the best way to write the
script. Just a broad idea of what I wanted to end up with.
> As it's built at server side, the user is never going to see your query or
> [1]manipulate it as you're writing it all over again, just using your old
> parameters (they could be added as hidden fields in the form if strictly
> necessary).
>
>
>> So, as I see it, the pagination links won't POST the form
>> variables. How do I pass the 'SELECT * FROM mytable WHERE
>> selection=option LIMIT start, range'
>> query to the called script?
>
> You should try building a default query where you only add the parameters
> given by the user. If you can't seem to recover that, add them to
> $_SESSION
> and you'll be fine next time you want them (if you don't overwrite it
> =] ).
>
My query code-
-------SQL query construction block
$query = "SELECT * FROM prods ";
if($catagory != 0){ //
if category != 0
$where="WHERE c = $catagory ";
if ($manu != 0){ // check
manu != 0
$and = "AND m = $manu ";
if ($searchstring != 0){
$and = $and."AND description LIKE \"%$searchstring%\" "; //
check like != 0
}
}else{
...
$query=$query.$where.$and.$like
-----------
Can you please explain your suggestion above in laymans terms. I can't see
what you have in mind. Is it your suggestion to use one script, containing a
from, that calls another script that handles my query construction? That far
I follow you but what happens next?
attached mail follows:
George J wrote:
> ""Thiago Pojda"" <thiago.pojda
softpartech.com.br> wrote in message
> news:004701c88a8a$eaab6480$0201a8c0
softpartech...
>> De: George J [mailto:georgejamieson
btconnect.com]
>>
>>> So calling the script via the form works i.e it passes the
>>> neccessary variables to constrct the sql query for the next
>>> call.
>> As Shawn said, if you really need the query again add it to session,
>> never,
>> NEVER give the user the ability to see/execute queries by himself
>> (remember
>> POST data could be easily manipulated). Remember what Daniel said, adding
>> a
>> DELETE FROM is not hard and veeery bad>
> OK. I see the logic.
>
>> Ok, let me ask you something. Why post to itself? You could have a script
>> only to do form actions, that way you can:
>> 1 Separate huge php validations with your html form.
>> 2 Use functions to handle the incoming data and writing the new query (or
>> the old one again).
>
> I suspect that most folk in my position start the learning process by
> finding a script that does a similar task and adapting it. This is basically
> what I've done. I started by finding a form example and then added a
> pagination routine then... Several deadends later... Not the best way to
> write anything but the simplest of scripts. However, the numerous changes to
> the code has entailed lots of learning during the process. So in answer to
> your question. I didn't set out with any idea of the best way to write the
> script. Just a broad idea of what I wanted to end up with.
>
>> As it's built at server side, the user is never going to see your query or
>> [1]manipulate it as you're writing it all over again, just using your old
>> parameters (they could be added as hidden fields in the form if strictly
>> necessary).
>>
>>
>>> So, as I see it, the pagination links won't POST the form
>>> variables. How do I pass the 'SELECT * FROM mytable WHERE
>>> selection=option LIMIT start, range'
>>> query to the called script?
>> You should try building a default query where you only add the parameters
>> given by the user. If you can't seem to recover that, add them to
>> $_SESSION
>> and you'll be fine next time you want them (if you don't overwrite it
>> =] ).
>>
> My query code-
>
> -------SQL query construction block
> $query = "SELECT * FROM prods ";
> if($catagory != 0){ //
> if category != 0
> $where="WHERE c = $catagory ";
> if ($manu != 0){ // check
> manu != 0
> $and = "AND m = $manu ";
> if ($searchstring != 0){
> $and = $and."AND description LIKE \"%$searchstring%\" "; //
> check like != 0
> }
> }else{
> ...
> $query=$query.$where.$and.$like
>
> -----------
> Can you please explain your suggestion above in laymans terms. I can't see
> what you have in mind. Is it your suggestion to use one script, containing a
> from, that calls another script that handles my query construction? That far
> I follow you but what happens next?
>
>
>
What file is this? is the pagination code in this file also? If not
where? Post you pagination code and this is a simple explanation.
Build your query as you've done and stick it in a session var. It is
now available to future calls to this page or other pages.
-Shawn
attached mail follows:
Hi Shawn,
>> My query code-
>>
>> -------SQL query construction block
>> $query = "SELECT * FROM prods ";
>> if($catagory != 0){
>> //
>> if category != 0
>> $where="WHERE c = $catagory ";
>> if ($manu != 0){ //
>> check
>> manu != 0
>> $and = "AND m = $manu ";
>> if ($searchstring != 0){
>> $and = $and."AND description LIKE \"%$searchstring%\" ";
>> //
>> check like != 0
>> }
>> }else{
>> ...
>> $query=$query.$where.$and.$like
>>
>> -----------
>> Can you please explain your suggestion above in laymans terms. I can't
>> see
>> what you have in mind. Is it your suggestion to use one script,
>> containing a
>> from, that calls another script that handles my query construction? That
>> far
>> I follow you but what happens next?
>>
>>
>>
> What file is this? is the pagination code in this file also? If not
> where? Post you pagination code and this is a simple explanation.
>
> Build your query as you've done and stick it in a session var. It is
> now available to future calls to this page or other pages.
>
> -Shawn
The above code was included in post to show how query is constructed.
Heres my pagination code.
-------------------
if($page > 1){ // if number of pages > 1 then display 'Previous' button
$pageprev = $page-1;
echo("<a href=\"display_products.php?page=$pageprev\"><img
src=\"btnprevenabled.gif\" ALT=\"Previous\" border=\"0\" ></a> ");
}else{
echo("<img src=\"btnprevdisnabled.gif\" ALT=\"Previous\"border=\"0\"
> ");
}
//----
$numpages = $totalrows / $show; //$show holds number of items to display per
page
// display a button for each page with current page showing disabled button
for($i = 1; $i <= $numpages; $i++){
$str1="btn_";
$str2=$i;
if($i == $page){
$str3=$str1.$str2."disabled.gif";
echo("<img src=$str3 border=\"0\"> ");
}else{
$str3=$str1.$str2."_enabled.gif";
echo("<a href=\"displayproducts.php?page=$i\"><img src=$str3
border=\"0\" ></a> ");
}
}
// if last page is less than full
if(($totalrows % $show) != 0){
$str2=$i;
if($i == $page){
$str3=$str1.$str2."disabled.gif";
echo("<img src=$str3 border=\"0\"> ");//$i ");
}else{
$str3=$str1.$str2."enabled.gif";
echo("<a href=\"displayproducts.php?page=$i\"><img src=$str3
border=\"0\" ></a> ");//$i</a> ");
}
}
// Display the enabled or disabled 'Next' button
if(($totalrows - ($show * $page)) > 0){
//$str3=$str1.$str2."disabled.gif";
$pagenext =$page+1;
echo("<a href=\"displayproducts.php?page=$pagenext\"><img
src=\"btnnextenabled.gif\" border=\"0\" ></a>");//$i</a> ");
}else{
$pagenext =$page+1;
echo("<img src=\"btnnextdisabled.gif\" ALT=\"Next\"border=\"0\" >
");
}
?>
</td></font></tr></table>
---------------
Thanks for sticking with me.
George
attached mail follows:
On Mar 20, 2008, at 12:05 PM, George Jamieson wrote:
>
> Hi Philip,
>
> Hope you don't mind me sending this to you direct. Thanks for the
> answer
> but... I'm sorry I don't follow you.
>
> My form sets up the query parameters. It works.
>
> My pagination code passes the page no. It works.
>
> What it doesn't do is provide the next execution of my script with the
> query. I pass the page no. but how do I either use the same query
> but with
> new LIMIT parameters or reconstruct the entire query with the new
> LIMIT.
>
> My form gives the user options to search by manufacturer, gategory
> or search
> string. sorted by description, finish or price. I've just added a
> drop down
> box for number of items to be displayed at a time.
>
> I want to use my pagination script to scroll, page by page, through
> the
> resultset. So if I call my script again, with the new page number, I
> have no
> way of reusing the same query as the user is not required to rePOST
> the form
> with its parameters.
>
> I can't see how your code allows me to do that.
Because I increment the page count ($page) each time... So, each time
you hit Go, then it finds the next page. Of course, this is not really
made for production - you would want to find a more user-friendly way
to accomplish showing a result set.
You could change it up to use _GET instead:
<a href="thispage.php?page=3">Go to Page 3</a>
Then modify your PHP code to accept _GET values along with/instead of
_POST values:
<?php
if (isset ($_POST['submitted']) || !empty ($_GET['page'])) {
$page = $_POST['page'] ? (int) $_POST['page'] : (int)
$_GET['page'];
...
}
?>
I feel like we've explained this fairly well, but you may not
completely understand. Let us know if we need to break it down a
little bit more. We would be happy to point you to some materials that
can assist you.
~Philip
> Regards
> George
>
>> to the called script?
>>>
>>> George
>>
>> I don't know if anyone has answered the question you have asked at
>> least twice... "How do I pass the query to the next page?" Here's how
>> I would approach it. Don't pass the query - all you need is the page
>> number. This code hasn't been tested, but I think you'll get the
>> idea.
>>
>> <?php
>> // thispage.php
>> if (isset ($_POST['submitted'])) {
>> $resultsPerPage = 50; // or whatever value
>> $page = mysql_real_escape_string ($_POST['page']);
>>
>> $start = ($page * $resultsPerPage) - $resultsPerPage;
>> $length = $start + $resultsPerPage;
>>
>> // Notice how you don't send the query in the POST or GET, just
>> the page number
>> $sql = "SELECT `field` FROM `table` WHERE (`field_a` =
>> 'someValue') LIMIT $start, $length";
>> $results = mysql_query ($sql);
>> }
>>
>> // Go to next page
>> $page = $_POST['page'] ? (int) $_POST['page'] + 1 : 1;
>> ?>
>> ...
>> <form method="post" action="thispage.php">
>> <input type="submit" value="Go" />
>> <input type="hidden" name="page" value="<?php echo htmlentities
>> ($page); ?>" />
>> <input type="hidden" name="submitted" value="1" />
>> </form>
>> ...
>>
>> <?php
>> while ($row = mysql_fetch_array ($results, MYSQL_ASSOC)) {
>> // Display results
>> }
>> ?>
>>
>>
>> Hopefully that helps a little bit.
>>
>> ~Philip
attached mail follows:
Hello. I am new to php programming, but have spent many years
programming in many other languages, most recently perl (with which php
seems to have much in common!). In every other language I've worked
with there is a way for one program to pass control to another.
However, so far in all of the books and other documentation I've looked
at for php, I cannot find a way for one php program to pass control to
another. Is this possible in php, and, if so, please let me know how.
Thank you.
Rod Clay
clay.1
osu.edu
attached mail follows:
Im not sure I understand the question.
Pass control from index.php to welcome.php ???
index.php : <? echo "<form action=welcome.php method=post><input type=hidden name=tagme value=yes><input type=submit value='Continue'></form>"; ?>
welcome.php <? if($_POST['tagme'] == "yes"){
echo "Congrats you are there";}ELSE{echo "You failed";}
?>
That kind of pass control?
Hello. I am new to php programming, but have spent many years
programming in many other languages, most recently perl (with which php
seems to have much in common!). In every other language I've worked
with there is a way for one program to pass control to another.
However, so far in all of the books and other documentation I've looked
at for php, I cannot find a way for one php program to pass control to
another. Is this possible in php, and, if so, please let me know how.
Thank you.
Rod Clay
clay.1
osu.edu
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
attached mail follows:
Yes, let me try to say more about exactly what I'm trying to do. I have
a php script running in a browser window (opened specifically for this
purpose) in which the user keys a blog item, then hits 'submit.' After
this script has successfully added the new blog item to the database,
what I'd like to do is automatically close this window, and pass control
to the php script that displays the updated list of blog items (with of
course the newly added blog item) in the original browser window (the
window the user was looking at when s/he clicked on the 'Add a blog'
link).
admin
buskirkgraphics.com wrote:
> Im not sure I understand the question.
>
> Pass control from index.php to welcome.php ???
>
>
> index.php : <? echo "<form action=welcome.php method=post><input type=hidden name=tagme value=yes><input type=submit value='Continue'></form>"; ?>
>
> welcome.php <? if($_POST['tagme'] == "yes"){
> echo "Congrats you are there";}ELSE{echo "You failed";}
> ?>
>
> That kind of pass control?
>
>
>
> Hello. I am new to php programming, but have spent many years
> programming in many other languages, most recently perl (with which php
> seems to have much in common!). In every other language I've worked
> with there is a way for one program to pass control to another.
> However, so far in all of the books and other documentation I've looked
> at for php, I cannot find a way for one php program to pass control to
> another. Is this possible in php, and, if so, please let me know how.
> Thank you.
>
> Rod Clay
> clay.1
osu.edu
>
>
attached mail follows:
On Thu, Mar 20, 2008 at 12:37 PM, Rod Clay <rclay
columbus.rr.com> wrote:
> Yes, let me try to say more about exactly what I'm trying to do. I have
> a php script running in a browser window (opened specifically for this
> purpose) in which the user keys a blog item, then hits 'submit.' After
> this script has successfully added the new blog item to the database,
> what I'd like to do is automatically close this window, and pass control
> to the php script that displays the updated list of blog items (with of
> course the newly added blog item) in the original browser window (the
> window the user was looking at when s/he clicked on the 'Add a blog'
> link).
That would be more of a JavaScript issue, really. Have the user
click a link to refresh the parent and close the child.
On a different note, you probably got made fun of pretty often for
you name (especially last-name-first), eh? My father's name was Dick
--- no joke. Yeah.... he got hell all the time. ;-P
--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283
attached mail follows:
On Thu, Mar 20, 2008 at 12:08:39PM -0400, Rod Clay wrote:
> Hello. I am new to php programming, but have spent many years
> programming in many other languages, most recently perl (with which
> php seems to have much in common!). In every other language I've
> worked with there is a way for one program to pass control to
> another. However, so far in all of the books and other documentation
> I've looked at for php, I cannot find a way for one php program to
> pass control to another. Is this possible in php, and, if so, please
> let me know how. Thank you.
This may be what you are looking for:
include('next_program');
exit();
If you do this, you have to keep in mind that all the variables you set
in the first program are *still* set in the second.
This is useful when your first program needs to choose which of two or
more programs to run next depending on its calculations. For example, if
your first program does error checking then it might want to run an
all_ok program or an edit program.
--
"To be without a plan is the true genius and glory of the antislavery
movement. The mission of that movement is to preach eternal truths, and
to bear witness to everlasting testimony against the giant falsehoods
which bewitch and enslave the land." -- Nathaniel Peabody Rogers
Rick Pasotto rick
niof.net http://www.niof.net
attached mail follows:
At 12:08 PM -0400 3/20/08, Rod Clay wrote:
>Hello. I am new to php programming, but have spent many years
>programming in many other languages, most recently perl (with which
>php seems to have much in common!). In every other language I've
>worked with there is a way for one program to pass control to
>another. However, so far in all of the books and other
>documentation I've looked at for php, I cannot find a way for one
>php program to pass control to another. Is this possible in php,
>and, if so, please let me know how. Thank you.
>
>Rod Clay
>clay.1
osu.edu
Rod:
If what you mean is one program to launch another, then look at this:
http://webbytedd.com/bb/php-run-php/
If you want to pass variables, there's several ways to do that --
but, that's a different question.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
attached mail follows:
hi,
I saw several times that some people use this
$parameters = array(
'param1' => "{$_POST["param1"]}",
'param2' => "{$_POST["param2"]}"
);
or
$query = mysql_query("SELECT * FROM table1 WHERE id='{$session_id}'");
I would use:
$parameters = array(
'param1' => $_POST["param1"],
'param2' => $_POST["param2"]
);
and
$query = mysql_query("SELECT * FROM table1 WHERE id=' ".$session_id." ' ");
does it really matter? is there really difference or these are just two "styles"?
thanks.
-ll
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
attached mail follows:
On Thu, 2008-03-20 at 09:22 -0700, Lamp Lists wrote:
> hi,
> I saw several times that some people use this
>
> $parameters = array(
> 'param1' => "{$_POST["param1"]}",
> 'param2' => "{$_POST["param2"]}"
> );
Ignorance.
> or
>
> $query = mysql_query("SELECT * FROM table1 WHERE id='{$session_id}'");
Ignorance/Habit since you only need to do that if the context of the
variable is ambiguous... for instance:
$something = "Something blah $blehblah blah blah".
When what was really wanted was:
$something = "Something blah {$bleh}blah blah blah".
One would hope that in the example you provided the developer properly
escaped $session_id.
> I would use:
>
> $parameters = array(
> 'param1' => $_POST["param1"],
> 'param2' => $_POST["param2"]
> );
I sure would too (although I'd use single quotes for the array indices).
I'd also append a dangling , to that last array entry to make it
simplistic to add another entry and never worry about having to add a ,
to the previous entry. The following is perfectly legal in PHP and is an
intentional feature:
$parameters = array
(
'param1' => $_POST['param1'],
'param2' => $_POST['param2'],
);
> and
>
> $query = mysql_query("SELECT * FROM table1 WHERE id=' ".$session_id."
> ' ");
That's broken unless you're relying on a MySQL type conversion trick to
match the session ID since you've prepended and appended the id match
with spaced. You probably meant to type:
"SELECT * FROM table1 WHERE id='".$session_id."' "
In that case, I normally do similar for queries, except mine look more
like:
"SELECT * FROM table1 WHERE id=".$db->quote( $session_id )." "
Where the quote() method performs both the quoting and the escaping.
> does it really matter? is there really difference or these are just two "styles"?
It matters greatly if it's incorrect :) Otherwise it matters less so but
one is more efficient than the other. There's absolutely no reason to
interpolate a value if the value is the variable's value itself.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
attached mail follows:
On Mar 20, 2008, at 12:22 PM, Lamp Lists wrote:
> hi,
> I saw several times that some people use this
>
> $parameters = array(
> 'param1' => "{$_POST["param1"]}",
> 'param2' => "{$_POST["param2"]}"
> );
>
> or
>
> $query = mysql_query("SELECT * FROM table1 WHERE id='{$session_id}'");
>
> I would use:
>
> $parameters = array(
> 'param1' => $_POST["param1"],
> 'param2' => $_POST["param2"]
> );
>
> and
>
> $query = mysql_query("SELECT * FROM table1 WHERE id=' ".
> $session_id." ' ");
I may have been the one you were talking about so I figured I should
reply. I picked up the habit doing that for stuff that was being
displayed using HEREDOC. When I asked for some help awhile back on a
project I was working on and they said to use HEREDOC, and gave an
example of how to do it and they had all the variables surrounded with
{} So I assumed you had to do it that way...
Anyone care to correct me?
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
japruim
raoset.com
attached mail follows:
On Thu, Mar 20, 2008 at 12:22 PM, Lamp Lists <lamp.lists
yahoo.com> wrote:
> hi,
> I saw several times that some people use this
>
> $parameters = array(
> 'param1' => "{$_POST["param1"]}",
> 'param2' => "{$_POST["param2"]}"
> );
>
> or
>
> $query = mysql_query("SELECT * FROM table1 WHERE id='{$session_id}'");
>
> I would use:
>
> $parameters = array(
> 'param1' => $_POST["param1"],
> 'param2' => $_POST["param2"]
> );
>
> and
>
> $query = mysql_query("SELECT * FROM table1 WHERE id=' ".$session_id." '
> ");
>
>
> does it really matter? is there really difference or these are just two
> "styles"?
the short answer is yes.
i think you can find a sufficient explanation here,
http://us.php.net/manual/en/language.types.string.php#language.types.string.parsing.simple
and here
http://us.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex
-nathan
attached mail follows:
Lamp Lists wrote:
> hi,
> I saw several times that some people use this
>
> $parameters = array(
> 'param1' => "{$_POST["param1"]}",
> 'param2' => "{$_POST["param2"]}"
> );
>
> or
>
> $query = mysql_query("SELECT * FROM table1 WHERE id='{$session_id}'");
>
> I would use:
>
> $parameters = array(
> 'param1' => $_POST["param1"],
> 'param2' => $_POST["param2"]
> );
>
> and
>
> $query = mysql_query("SELECT * FROM table1 WHERE id=' ".$session_id." ' ");
>
>
> does it really matter? is there really difference or these are just two "styles"?
>
> thanks.
>
> -ll
>
>
> ____________________________________________________________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
The brackets are used to enforce that the entire contents between them
is a variable. It helps when you're using class members.
$example = "this is an {$example->text}";
It's also handy when you're putting variables in a heredoc.
I would suggest not using "{$_POST["param1"]}", like you said. It's
just going to make PHP figure out the string, then put the value in that
string. If you really wanted to make sure it's a string type then you
can do (string)$_POST['param1'].
The short answer is you can do it the way you're doing and everything
will work out just fine :)
--
Ray Hauge
www.primateapplications.com
attached mail follows:
On 20/03/2008, Lamp Lists <lamp.lists
yahoo.com> wrote:
> hi,
> I saw several times that some people use this
>
> $parameters = array(
> 'param1' => "{$_POST["param1"]}",
> 'param2' => "{$_POST["param2"]}"
> );
>
> or
>
> $query = mysql_query("SELECT * FROM table1 WHERE id='{$session_id}'");
>
> I would use:
>
> $parameters = array(
> 'param1' => $_POST["param1"],
> 'param2' => $_POST["param2"]
> );
>
> and
>
> $query = mysql_query("SELECT * FROM table1 WHERE id=' ".$session_id." ' ");
>
>
> does it really matter? is there really difference or these are just two "styles"?
yes, it matters when you're trying to include a complex variable
"this is a $variable"; # ok
"this is an $array[12]"; # ok
"this is an $array[word]"; # warning under E_STRICT
"this is an $array[two words]"; # not ok, can't have whitespace
"this is an {$array[two words]}"; # not ok, indexes should be quoted
"this is an {$array['two words']}"; # ok
"this is an $object->property"; # ok if you're after the property
"this is an {$object}->property"; # but you need brackets if you want
the object as a string
etc...
attached mail follows:
On Mar 20, 2008, at 922AM, Lamp Lists wrote:
> $query = mysql_query("SELECT * FROM table1 WHERE id='{$session_id}'");
For a non-array value, the curly braces are unnecessary:
$query = mysql_query("SELECT * FROM table1 WHERE id='$session_id'")
WIth an array element, you have to either use the curly braces or do
as you have and end the string, concat the value and start the string
again as needed.
$query = mysql_query("SELECT * FROM table1 WHERE id='{$clean['id']}'")
When dealing with array elements, I use the curly braces method. IMO
it's cleaner and easier to read.
> I would use:
>
> $parameters = array(
> 'param1' => $_POST["param1"],
> 'param2' => $_POST["param2"]
> );
This is how I do it as well.
> does it really matter? is there really difference or these are just
> two "styles"?
IMO, it's a matter of preference and style. There may be performance
differences between the two, but I doubt that either one is so much
worse than the other that it would have a noticeable impact on your
script in most situations.
Brady
attached mail follows:
----- Original Message ----
From: Nathan Nobbe <quickshiftin
gmail.com>
To: Lamp Lists <lamp.lists
yahoo.com>
Cc: php-general
lists.php.net
Sent: Thursday, March 20, 2008 11:35:42 AM
Subject: Re: [PHP] why use {} around vraiable?
On Thu, Mar 20, 2008 at 12:22 PM, Lamp Lists <lamp.lists
yahoo.com> wrote:
> hi,
> I saw several times that some people use this
>
> $parameters = array(
> 'param1' => "{$_POST["param1"]}",
> 'param2' => "{$_POST["param2"]}"
> );
>
> or
>
> $query = mysql_query("SELECT * FROM table1 WHERE id='{$session_id}'");
>
> I would use:
>
> $parameters = array(
> 'param1' => $_POST["param1"],
> 'param2' => $_POST["param2"]
> );
>
> and
>
> $query = mysql_query("SELECT * FROM table1 WHERE id=' ".$session_id." '
> ");
>
>
> does it really matter? is there really difference or these are just two
> "styles"?
the short answer is yes.
i think you can find a sufficient explanation here,
http://us.php.net/manual/en/language.types.string.php#language.types.string.parsing.simple
and here
http://us.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex
-nathan
ok. I got it.
actually, my question was about: these two examples
$fruits = array('strawberry' => 'red', 'banana' => 'yellow');
echo "A banana is {$fruits['banana']}.";
echo "A banana is " . $fruits['banana'] . ".";
are the same.
Though, learned few more other things too :D
Thanks guys.
-ll
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
attached mail follows:
On 20/03/2008, Robin Vickery <robinv
gmail.com> wrote:
> Hiyah,
>
> Here's a trick you can use to evaluate expressions within strings. It
> may not be particularly useful, but I thought it was interesting.
>
> It exploits two things:
>
> 1. If you interpolate an array element within a string, the index of
> the element is evaluated as a php expression.
>
> 2. You can can make your own magic arrays by extending arrayObject.
>
>
> <?php
> class identityArrayObject extends arrayObject
> {
> public function offsetGet($index)
> {
> return $index;
> }
> }
>
> $eval = new identityArrayObject;
>
> print "The square root of {$eval[pow(2,2)]} is {$eval[sqrt(4)]} \n";
>
> print "Price: $price GBP ({$eval[$price * 1.175]} GBP including tax) \n";
>
> ?>
>
> You can extend it to add your own formatting elements:
>
> <?php
> class uppercaseArrayObject extends arrayObject
> {
> public function offsetGet($index)
> {
> return strtoupper($index);
> }
> }
>
> $U = new uppercaseArrayObject;
> $city = 'edinburgh';
>
> print "The capital of Scotland is $U[$city] \n";
> ?>
>
More generic:
<?php
class transformArrayObject extends arrayObject
{
protected $transform;
public function __construct($transform = null)
{
$this->transform = is_null($transform) ? array($this, 'identity')
: $transform;
}
public function offsetGet($index)
{
return call_user_func($this->transform, $index);
}
public function identity($index)
{
return $index;
}
}
$eval = new transformArrayObject;
$U = new transformArrayObject('strtoupper');
$u = new transformArrayObject('ucfirst');
$L = new transformArrayObject('strtolower');
$GBP = new transformArrayObject(create_function('$index', 'return
money_format("%n", $index);'));
$price = 50;
$tax = 1.175;
$city = 'EdInBurGH';
print "A ticket to $U[$city] is: $GBP[$price] ({$GBP[$price * $tax]}
including VAT)\n";
// A ticket to EDINBURGH is: £50.00 (£58.75 including VAT)
?>
attached mail follows:
I'm using MCrypt and I have two very simple functions. All I'm doing is
giving the function some text and a password, it encrypts the text and saves
it as a text file on the server. Then I at some later time run another php
file which decrypts using the decrypt function given the text and the SAME
password as the first time and all I get is garbage. What am I doing wrong?
What do I need to change so that I can get this to work the way I described?
function aes_128_encrypt($text,$password) {
$size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
$text .= chr(3).chr(3).chr(3);
return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $password, $text,
MCRYPT_MODE_ECB, $iv));
} // End of function
and
function aes_128_decrypt($encrypted_text,$password) {
$size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, pack("H*",
$encrypted_text), MCRYPT_MODE_ECB, $iv);
} // End of function
- Dan
attached mail follows:
Does anyone know how to convert an HTML form to a pdf with php?
--
Robert Burdo
nuschooldesign.com
attached mail follows:
On Mar 20, 2008, at 4:42 PM, Robert Burdo wrote:
> Does anyone know how to convert an HTML form to a pdf with php?
Have you STFW? =D http://www.google.com/search?q=php+html+to+pdf
I use dompdf. Unfortunately, the guy who created it isn't intending to
upgrade it. Nonetheless, for most things, it does a good job - just
send it the HTML.
I've also use fpdf before. If you really want to draw out the PDF
yourself, this is the way to go. It's kinda tedious for me.
~Philip
attached mail follows:
I think Imagemagick will do it.
Philip Thompson wrote:
> On Mar 20, 2008, at 4:42 PM, Robert Burdo wrote:
>> Does anyone know how to convert an HTML form to a pdf with php?
>
>
> Have you STFW? =D http://www.google.com/search?q=php+html+to+pdf
>
> I use dompdf. Unfortunately, the guy who created it isn't intending to
> upgrade it. Nonetheless, for most things, it does a good job - just send
> it the HTML.
>
> I've also use fpdf before. If you really want to draw out the PDF
> yourself, this is the way to go. It's kinda tedious for me.
>
> ~Philip
attached mail follows:
Am Donnerstag, 20. März 2008 22:42:59 schrieb Robert Burdo:
> Does anyone know how to convert an HTML form to a pdf with php?
Do you know "FPDF"? This can be a possibility. www.fpdf.org
Kai
--
Mit freundlichen Grüßen
Kai Kauer
Bruno - Taut - Ring 60
39130 Magdeburg
Tel.: 0391 - 506 99 76
Mobil: 0171 - 498 17 62
web: http://www.spoekertier.de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
iD8DBQBH42dOvH/u9RGemjURAurVAKCb51ZBc/CJ1THBvtoYHn8N7aaCsgCeMtk5
ZVFjGnrueYBbo2NNl+PAnD0=
=xYI9
-----END PGP SIGNATURE-----
attached mail follows:
if a user by mistake types the wrong url directly in the address bar ex=
www.website.com/abou.php instead of
typing www.website.com/aboutus.php instead of the browser displaying File
not found or a 404 error message i would like to display a customized page
which will still have the same look and feel of my website in terms of the
layout and i would like to
a) display a message such as = "Page could not be found" and b) the url that
the user originally typed should remain in the browser = I guess this would
be the case anyway but i was wondering if something needs to be done in
order to reatin the original address the user typed.
Does this have to be done from apache perspective or can it be done using
php. please suggest the procedure in either case apache OR php.
please advice.
thanks.
attached mail follows:
Sudhakar wrote:
> if a user by mistake types the wrong url directly in the address bar ex=
> www.website.com/abou.php instead of
> typing www.website.com/aboutus.php instead of the browser displaying File
> not found or a 404 error message i would like to display a customized page
> which will still have the same look and feel of my website in terms of the
> layout and i would like to
> a) display a message such as = "Page could not be found" and b) the url that
> the user originally typed should remain in the browser = I guess this would
> be the case anyway but i was wondering if something needs to be done in
> order to reatin the original address the user typed.
>
> Does this have to be done from apache perspective or can it be done using
> php. please suggest the procedure in either case apache OR php.
Both will be involed.
You will use what is referred to as the ErrorDocument entry.
Have apache enforce a customer ErrorDocument for a 404 error.
Then create a php script that is referred to by the ErrorDocument entry.
error404.php
<?php
echo "Page not found, check your spelling and try again.";
?>
>
> please advice.
>
> thanks.
>
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
attached mail follows:
Peter Ford wrote:
> Mark Weaver wrote:
>> Hi all,
>>
>> I've been lurking and reading now for some time, but have decided to
>> come out of the shadows cause I've got an issue that's gonna drive me
>> crazy!
>>
>> I'm developing an application and within this application is a class
>> that is very simple and only serves a singular purpose - to make log
>> entries to help with debugging. Problem is, now I'm debugging the damned
>> logging class that is supposed to be helping me debug the application as
>> I'm putting it together! <sigh> I've looked and looked all over the
>> place, but I don't seem to be able to find an answer to this problem.
>> The only information that I have found so far deals with permissions and
>> I don't think that's the problem. At first I was getting an access
>> denied error but since setting dir perms and log file perms so that both
>> apache and my user can right to both the directory and the file that one
>> has gone away.
>>
>> Log Directory permissions: /mystuff/logs rwx-rwx-rwx
>> (777)
>> Log file permissions : /mystuff/logs/run.log rwx-rwx-rwx
>> (777)
>>
>> At any rate, the following is the information I'm getting in the apache
>> error_log while working on this particular portion of the application:
>>
>> PHP Warning: fwrite(): supplied argument is not a valid stream resource
>> in /mystuff/inc/Log.inc on line 22,
>> PHP Warning: fclose(): supplied argument is not a valid stream resource
>> in /mystuff/inc/Log.inc on line 23,
>>
>> The Log class:
>> -----------------------------
>> class Log{
>> public $path, $entry, $logfile;
>> public function Log(){}
>> public function setLog($path,$file){
>> $this->path = $path;
>> $this->logfile = $file;
>> }
>> public function writeLog($entry){
>> // open the file, in this case the log file
>> $h = "$this->path/$this->logfile";
>> fopen($h, 'a+');
>> fwrite($h,$entry);
>> fclose($h);
>> }
>> }
>>
>> Code snippet where attempting to write log entry from program:
>> --------------------------------------------------------------------------------------------
>>
>> $pl_log = new Log;
>> $pl_log->setLog($logpath,"run.log");
>> $usernanme = $_POST['username'];
>> $password = $_POST['secret'];
>> /**
>> * (debugging) logging incoming values from form:
>> */
>> $pl_log->writeLog("getDateTime(): Incoming values from Login
>> Form:
>> blah...blah...blah\n");
>>
>> Any help with this would be most appreciated. (be gentle... I'm a PERL
>> program learning PHP OOP)
>>
>
>
> As Stut pointed out, you've misunderstood the difference between a file
> resource and a file name.
>
> Try something like:
>
>
> public function writeLog($entry)
> {
> // open the file, in this case the log file
> $fileName = $this->path.'/'.$this->logfile;
> $h = fopen($fileName, 'a+');
> fwrite($h,$entry);
> fclose($h);
> }
>
> The file resource that fwrite and fclose need is the *result* of opening
> the file, not the file name as you were doing.
> Ideally, you would check the value of $h after the fopen call, to make
> sure that it had successfully opened the file.
>
> Also, I changed the way you were constructing the file name:
> interpolating the variables in a string is slightly less efficient than
> concatenating the bits together, and there are possible gotchas when
> using the $this->variable structure in a string like that.
> An alternative syntax is to escape the variables with braces:
>
> $fileName = "{$this->path}/{$this->logfile}";
Hi Peter,
Thank you for that information. I'm rather new at this sort of PHP
coding and a bit embarrassed at the amount of OOP I've forgotten since
college. Clearly there's a lot to learn. Like this concept of escaping
you've mentioned. Until now the only type of "escaping" I'm familiar
with from PERL is something like this: \$$some_dollar_amount, but I have
a feeling escaping things in PHP oop is quite a bit different. I
haven't quite gotten my head around some of the stuff I've been reading
about, but it's coming.
--
Mark
"If you have found a very wise man, then you've found a man that at one
time was an idiot and lived long enough to learn from his own stupidity."
==============================================
Powered by CentOS5 (RHEL5)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]