php-general Digest 13 Jul 2006 13:51:56 -0000 Issue 4237
Topics (messages 239400 through 239417):
Re: How do I prevent a session from rebuilding itself?
239400 by: Ford, Mike
239404 by: Andrew Brampton
239412 by: tedd
Re: Language Translation and PHP...
239401 by: Sameer N Ingole
Re: Searching and storing results index in cookies or session variables
239402 by: Shafiq Rehman
session_start/session_write_close creates multiple session cookie headers. How
to fix this.
239403 by: Mathijs
Re: When is a global not a global?
239405 by: Nick Wilson
Silly varible question
239406 by: Ed Curtis
239407 by: Brad Bonkoski
239408 by: Jochem Maas
239410 by: Dave Goodchild
239414 by: Ford, Mike
239415 by: Ed Curtis
Re: Debugging Log
239409 by: tedd
Upload a big file.
239411 by: João Cândido de Souza Neto
239413 by: Dave Goodchild
239416 by: Jay Blanchard
239417 by: Jochem Maas
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
On 13 July 2006 00:20, Daevid Vincent wrote:
> > Sequence of events:
> > script starts
> > you rm -rf /tmp/sess_*
> > script writes out data
> > script ends
> >
> > Exactly WHAT do you think "should" happen in this case?...
>
> I expect this to work like it USED TO WORK! Bug or not.
>
> I expect:
> Script starts
> Calls session_start(1234)
> No existing sess_1234 file.
> Creates a new EMPTY sess_1234
> I make $_SESSION['authorized'] = true and PHP writes at that time
Bad assumption there -- the session file isn't necessarily written at this
point, only the value in the $_SESSION array.
> I rm /tmp/sess_1234
> Script ends
... and the session file is written as part of script shutdown. Boink!
If you really want the session file to be written (and closed) at the point of
setting $_SESSION['authorized'], you need a call to session_write_close() [aka
session_commit() since PHP 4.3.11].
> Page load again.
> Calls session_start(1234).
> No existing sess_1234 file.
> Creates a new EMPTY sess_1234
> Therefore $_SESSION['authorized'] doesn't exist == false
>
> But what happens is that PHP actually is writing a new sess_1234
> WITH ALL THE SHIT IT HAD IN RAM
>
> *sigh*
>
> Why is this so complicated for anyone to understand?
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
To view the terms under which this email is distributed, please go to
http://disclaimer.leedsmet.ac.uk/email.htm
--- End Message ---
--- Begin Message ---
If anyone reads DailyWTF, then you might remember this post:
http://thedailywtf.com/forums/thread/78892.aspx
Explaining the dangers of "rm -rf /tmp"
I'm sure you won't fall victim to this, but it is a fun read :)
Andrew
----- Original Message -----
From: "Daevid Vincent" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, July 11, 2006 10:27 PM
Subject: [PHP] How do I prevent a session from rebuilding itself?
I would expect that if I 'rm -rf /tmp/sess_*' that the user would get
prompted to re-login (since the flag is not set).
--- End Message ---
--- Begin Message ---
At 11:58 AM +0100 7/13/06, Andrew Brampton wrote:
>If anyone reads DailyWTF, then you might remember this post:
>http://thedailywtf.com/forums/thread/78892.aspx
>Explaining the dangers of "rm -rf /tmp"
>
>I'm sure you won't fall victim to this, but it is a fun read :)
>
>Andrew
Fun read. But the technique would make an interesting backdoor for clients who
use your code, but don't pay.
Not advocating, just thinking out loud. :-)
tedd
--
------------------------------------------------------------------------------------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
tedd wrote:
At 2:09 PM -0400 7/12/06, Russell Jones wrote:
Anyone know of any language translation APIs or anything of that sort out
there? Looking to translate quite a bit of content and would rather not do
it by hand.
I'm not sure as to what you want, but perhaps this might help:
http://www.weberdev.com/get_example-4049.html
Check out http://babelfish.altavista.com/
--
Sameer N. Ingole
http://weblogic.noroot.org/
---
Better to light one candle than to curse the darkness.
--- End Message ---
--- Begin Message ---
Hello Brian,
Storing the result set in session or cookie is not a good idea. You can
implement some caching mechanism in your search results. I implemented this
in my project and it works simply great.
Its very simple, You have to write two functions
1- writeCache($id, $data, $ttl)
This routine will write data (serialized result set) in cache (file system)
with ttl (time to live as timestamp). $id is the file name on disk. you can
use md5 of your sql query.
Example:
$query = "select * from table limit 0, 100"
$id = md5($query);
$data = serialize(resultSet)
$ttl = time()+ 600; ////10 minutes
When you executes your page first time, the above routine will generate a
cache file on disk (data from SQL)
When you execute your page 2nd time the getCache() will check the validity
of cache, if its valid then displays data from cache and if invalid creates
the new cache for next 10 minutes
2- getCache($id)
This function will checks the validity of cache and return false or
unserialized record set from cache
This mechanism will save your lot of MySQL queries in searching becoz you
are not querying every time. If your data is static you can increase the
$ttl accordingly.
--
Shafiq Rehman
Sr. Web Engineer
http://www.phpgurru.com
On 7/13/06, Brian Anderson <[EMAIL PROTECTED]> wrote:
Hello,
I have a question about how I am searching through a products database.
What I am wanting to do is store the result set so that I can provide a
link to go back to previous searches quickly, and also manipulate it
quickly. If I had a flat catalog of pages I could index the content in
a few tables and go with that, but I want the results to be
customizable, and more flexible than ten links to ten items on ten
different pages. I want the results delivered and recombined in one page.
Currently what I am doing is the following:
1. I open an SQL statement with delimiters
2. I circulate through the entries and append to a array called
$pageset both the item number and a ranking based on keywords etc.
3. I sort the array by relevance ranking
4. I figure out what my limit and offset are in my array and paginate
based on user input.
5. I grab the 20 or so array elements within the range and create a
new array called $display set.
6. For each of the current page items I pull the full item details
from the database and propagate the array to my html template
I wonder if instead of propagating the $pageset (results index) array
every time I could store the $pageset array as a cookie or session
variable.
It is a small array with a few hundred elements and rankings, but if I
could store it, I wouldn't have to build the array and do a relevancy
sort every time I paginate to the next page. I would just take the
current stored search array which is already sorted, and grab element x
through element y. Would this be an efficient way using a session
variable?
Does anybody else handle search results in a similar way?
-Brian Anderson
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Hello again,
I Use session_write_close() so the page loads quicker because i use session on
multiple place.
This because session has protection for race conditions.
Now it works very well and i don't have any problems at all.
I only see that there are multiple session cookie headers set.
I Personally think that one is enough :P.
How can i make it so that it just sets just one and not set this header every
time i call session_start or session_write_close.
Because i don't know when the cookie is set.
Thx in advance.
--- End Message ---
--- Begin Message ---
* and then Robert Cummings declared....
> On Wed, 2006-07-12 at 18:52, Nick Wilson wrote:
> > hi all,
> >
> > After upgrading a CMS, im having a problem with global variables not
> > showing up anymore -- configs and things could have changed, but search
> > as i have, i cannot find anything to help me work out what the problem
> > is.
> >
> > This should work of course:
> >
> > $foo = 'bar';
> >
> > function foobar() {
> > global $foo;
> > print(" ------ " . $foo);
> > exit;
> > }
> >
> > foobar();
> >
> > It prints *nothing*. Does anyone have an idea as to what might stop this
> > from functioning as expected?
>
> The above code is probably being included, and probably being included
> by a function and so $foo does not have global scope. To ensure global
> scope:
>
> <?php
> $GLOBALS['foo'] = 'bar';
>
> function foobar()
> {
> global $foo;
> print( " ------ " . $foo );
> exit;
> }
>
> foobar();
> ?>
>
> Try that and let us know what happend.
No, it didn't work. It's odd, becuase it worked just fine in the
previous version, and this is a module, so that module is exactly the
same as the previous one -- ie i've not made any changes to do with
includes to it (just a few upgrades to form functions and stuff).
I have fixed the issue, but the mystery will probably have to remain as
there is a lot more to do in the upgrade :( In the end i just manually
set $GLOBALS as you suggested and did a search and replace on the var to
do $GLOBALS[var] instead of global var; do_stuff($var);
crap i know, but thanks for the response!
--
Nick Wilson
http://performancing.com/user/1
--- End Message ---
--- Begin Message ---
I know this is probably simple as all get out but it's early and I can't
find an answer anywhere after searching for a while....
I need to assign a number to a variable and then use that variable in a
session to store an array. It's for a shopping cart system I'm building.
What I've got is:
$count = 1; //First item in the cart passed from form to form
$item = array();
$item[] = $_POST['phone'];
$item[] = $_POST['category'];
$item[] = $_POST['copy'];
$item[] = $_POST['pic_style'];
$item[] = $cost;
$item[] = $image;
session_register('item');
In the session the item is known as 'item'. What I need for it to be is
'item1' so when the customer chooses another product I can increase $count
by 1 and have the next array with values stored as 'item2'.
Thanks for any help,
Ed
--- End Message ---
--- Begin Message ---
Why not just have another array...
$bag = array();
$item[] ....
array_push($bag, $item);
then store the bag in the session.
so, you would have count($bag) items in your shopping cart, and you
would be able to easily access them.
Just a thought, instead of munging variable names.
-B
Ed Curtis wrote:
I know this is probably simple as all get out but it's early and I can't
find an answer anywhere after searching for a while....
I need to assign a number to a variable and then use that variable in a
session to store an array. It's for a shopping cart system I'm building.
What I've got is:
$count = 1; //First item in the cart passed from form to form
$item = array();
$item[] = $_POST['phone'];
$item[] = $_POST['category'];
$item[] = $_POST['copy'];
$item[] = $_POST['pic_style'];
$item[] = $cost;
$item[] = $image;
session_register('item');
In the session the item is known as 'item'. What I need for it to be is
'item1' so when the customer chooses another product I can increase $count
by 1 and have the next array with values stored as 'item2'.
Thanks for any help,
Ed
--- End Message ---
--- Begin Message ---
Brad Bonkoski wrote:
> Why not just have another array...
>
> $bag = array();
> $item[] ....
>
> array_push($bag, $item);
>
> then store the bag in the session.
> so, you would have count($bag) items in your shopping cart, and you
> would be able to easily access them.
> Just a thought, instead of munging variable names.
>
> -B
>
use the $_SESSION super global instead of using session_register()
(read the manual for the fine print regarding $_SESSION and why
session_register() is no longer recommended)
e.g.:
function addItemToBag($item)
{
if (!isset($_SESSION['bag'])) $_SESSION['bag'] = array();
$_SESSION['bag'][] = $item;
}
>>
>> session_register('item');
>>
>> In the session the item is known as 'item'. What I need for it to be is
>> 'item1' so when the customer chooses another product I can increase
>> $count
>> by 1 and have the next array with values stored as 'item2'.
>>
>> Thanks for any help,
>>
>> Ed
>>
>>
>>
>
--- End Message ---
--- Begin Message ---
On 13/07/06, Ed Curtis <[EMAIL PROTECTED]> wrote:
I know this is probably simple as all get out but it's early and I can't
find an answer anywhere after searching for a while....
I need to assign a number to a variable and then use that variable in a
session to store an array. It's for a shopping cart system I'm building.
What I've got is:
$count = 1; //First item in the cart passed from form to form
$item = array();
$item[] = $_POST['phone'];
$item[] = $_POST['category'];
$item[] = $_POST['copy'];
$item[] = $_POST['pic_style'];
$item[] = $cost;
$item[] = $image;
session_register('item');
In the session the item is known as 'item'. What I need for it to be is
'item1' so when the customer chooses another product I can increase $count
by 1 and have the next array with values stored as 'item2'.
Thanks for any help,
Ed
First off, don't use session_register, use the $_SESSION superglobal
array, that way you can create:
$_SESSION['count'] = 1
and increment like so:
$_SESSION['count']++
then you can create the cart like so:
$item{$_SESSION['count']} = array();
does this make sense. Maybe not, but then again I've had far too much
coffee. Make sense to the php gurus out there?
--
http://www.web-buddha.co.uk
http://www.projectkarma.co.uk
--- End Message ---
--- Begin Message ---
On 13 July 2006 13:53, Ed Curtis wrote:
> I know this is probably simple as all get out but it's early and I
> can't find an answer anywhere after searching for a while....
>
>
> I need to assign a number to a variable and then use that variable
> in a session to store an array. It's for a shopping cart system I'm
> building.
>
> What I've got is:
>
> $count = 1; //First item in the cart passed from form to form
>
> $item = array();
>
> $item[] = $_POST['phone'];
> $item[] = $_POST['category'];
> $item[] = $_POST['copy'];
> $item[] = $_POST['pic_style'];
> $item[] = $cost;
> $item[] = $image;
>
> session_register('item');
>
> In the session the item is known as 'item'. What I need for it to be
> is 'item1' so when the customer chooses another product I can
> increase $count by 1 and have the next array with values stored as
> 'item2'.
Just make $item a 2-dimensional array, with the first diemnsion addressed by
$count; so:
$item[$count][] = $_POST['phone'];
$item[$count][] = $_POST['category'];
$item[$count][] = $_POST['copy'];
$item[$count][] = $_POST['pic_style'];
$item[$count][] = $cost;
$item[$count][] = $image;
$count += 1;
$item[$count][] = ...;
$item[$count][] = ...;
// etc.
Incorporating the (good) advice to use $_SESSION, this becomes:
$_SESSION['item'][$count][] = $_POST['phone'];
$_SESSION['item'][$count][] = $_POST['category'];
$_SESSION['item'][$count][] = $_POST['copy'];
$_SESSION['item'][$count][] = $_POST['pic_style'];
$_SESSION['item'][$count][] = $cost;
$_SESSION['item'][$count][] = $image;
$count += 1;
$_SESSION['item'][$count][] = ...;
$_SESSION['item'][$count][] = ...;
// etc.
Personally, I'd be inclined to use string indexes that indicate what's in each
element, to avoid having to remember somehow which numeric index corresponds to
which attribute; so:
$_SESSION['item'][$count]['phone'] = $_POST['phone'];
$_SESSION['item'][$count]['category'] = $_POST['category'];
$_SESSION['item'][$count]['copy'] = $_POST['copy'];
$_SESSION['item'][$count]['pic_style'] = $_POST['pic_style'];
$_SESSION['item'][$count]['cost'] = $cost;
$_SESSION['item'][$count]['image'] = $image;
$count += 1;
$_SESSION['item'][$count]['phone'] = ...;
$_SESSION['item'][$count]['category'] = ...;
// etc.
HTH
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
To view the terms under which this email is distributed, please go to
http://disclaimer.leedsmet.ac.uk/email.htm
--- End Message ---
--- Begin Message ---
> Just make $item a 2-dimensional array, with the first diemnsion addressed by
> $count; so:
>
> $item[$count][] = $_POST['phone'];
> $item[$count][] = $_POST['category'];
> $item[$count][] = $_POST['copy'];
> $item[$count][] = $_POST['pic_style'];
> $item[$count][] = $cost;
> $item[$count][] = $image;
>
> $count += 1;
>
> $item[$count][] = ...;
> $item[$count][] = ...;
> // etc.
>
> Incorporating the (good) advice to use $_SESSION, this becomes:
>
> $_SESSION['item'][$count][] = $_POST['phone'];
> $_SESSION['item'][$count][] = $_POST['category'];
> $_SESSION['item'][$count][] = $_POST['copy'];
> $_SESSION['item'][$count][] = $_POST['pic_style'];
> $_SESSION['item'][$count][] = $cost;
> $_SESSION['item'][$count][] = $image;
>
> $count += 1;
>
> $_SESSION['item'][$count][] = ...;
> $_SESSION['item'][$count][] = ...;
> // etc.
>
>
> Personally, I'd be inclined to use string indexes that indicate what's in
> each element, to avoid having to remember somehow which numeric index
> corresponds to which attribute; so:
>
> $_SESSION['item'][$count]['phone'] = $_POST['phone'];
> $_SESSION['item'][$count]['category'] = $_POST['category'];
> $_SESSION['item'][$count]['copy'] = $_POST['copy'];
> $_SESSION['item'][$count]['pic_style'] = $_POST['pic_style'];
> $_SESSION['item'][$count]['cost'] = $cost;
> $_SESSION['item'][$count]['image'] = $image;
>
> $count += 1;
>
> $_SESSION['item'][$count]['phone'] = ...;
> $_SESSION['item'][$count]['category'] = ...;
> // etc.
>
Thanks for all the help guys. I now have a better understanding of multi
dimensional arrays and can use it for what I'm trying to accomplish. This
list is the greatest!!
Thanks,
Ed
--- End Message ---
--- Begin Message ---
At 6:19 PM -0400 7/12/06, Michael B Allen wrote:
>On Wed, 12 Jul 2006 22:44:23 +0100
>Stut <[EMAIL PROTECTED]> wrote:
>
>> Michael B Allen wrote:
>> > Thanks for the tip dipshit.
>>
>> Maybe I'm in a sensitive mood, but that was uncalled for. Michael, meet
>> /dev/null, I hope you live happily ever after.
>
>Oh, no. What am I going to do now? You're like "The Man" on this
>list. I'll never figure out how to write to a logfile now. I might as
>well just give up and use VB or something.
I don't know about you using VB or something, but for Stut being "The Man" I
would support that claim.
tedd
ps: When there's no enemies about, it's not a good idea to burn bridges.
--
------------------------------------------------------------------------------------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
Hello gang.
I´ve got a e-commerce system where one can import data from his management
system.
This importation files sometimes has a size about 8Mb. Unfortunatly, when
one try to put this file into e-commerce, generaly one gets any error
because your connection speed is very slow and can´t send this file.
There´s any way to increase this wait time and get big files?
Thanks.
--- End Message ---
--- Begin Message ---
On 13/07/06, João Cândido de Souza Neto <[EMAIL PROTECTED]> wrote:
Hello gang.
I´ve got a e-commerce system where one can import data from his management
system.
This importation files sometimes has a size about 8Mb. Unfortunatly, when
one try to put this file into e-commerce, generaly one gets any error
because your connection speed is very slow and can´t send this file.
There´s any way to increase this wait time and get big files?
Thanks.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
First of all, use set_time_limit(0) in your script, which gives an
unlimited execution time. Then amend the max files size limit in php.ini, or
locally.
--
http://www.web-buddha.co.uk
http://www.projectkarma.co.uk
--- End Message ---
--- Begin Message ---
[snip]
> First of all, use set_time_limit(0) in your script, which gives an
unlimited execution time. Then amend the max files size limit in php.ini, or
locally.
[/snip]
You will likely have to do the same thing in Apache (or whatever your web
server software is) as there will be a time-out built into that as well.
--- End Message ---
--- Begin Message ---
João Cândido de Souza Neto wrote:
> Hello gang.
>
> I´ve got a e-commerce system where one can import data from his management
> system.
>
> This importation files sometimes has a size about 8Mb. Unfortunatly, when
> one try to put this file into e-commerce, generaly one gets any error
> because your connection speed is very slow and can´t send this file.
>
> There´s any way to increase this wait time and get big files?
take note of what the other respondents wrote regardless upload and timeout
limits
(in both apache and php)
but ....
you might also consider that it may be better to automate the process somewhat
by
having the back office system (S)FTP the 'import file' and using an automated
job
(e.g. php script set to run regularly via cron) to check for the existence of
said 'import file' and process it if it exists. basically the idea being to
remove the requirement for user and browser interaction from the import
process completely.
>
> Thanks.
>
--- End Message ---