Re: [PHP] session / garbage collection problem

2003-12-19 Thread Tony Crockford
On Fri, 19 Dec 2003 13:37:06 -0800, Anthony Kaufman  wrote:

PHP Version 4.2.2
Apache 2
RH 9
The problem is that session files in the /tmp directory are completely
cleared out at "random" intervals of time.  We assume that the 
randomness is
due to our session.gc_probability setting of "1" causing it to run for 
1% of
new sessions.  What we don't understand is why the garbage collector is
removing valid sessions.  session.gc_maxlifetime is set to 86400 (24 
hours)
so it should keep them around for a good long time.  However, it seems 
that
ALL session files are deleted when the garbage collector runs.  In some
cases session files were deleted for sessions that had been around for 
less
than a minute.  We've thought of several hacks that would control the
problem but we can't come up with any way to fix it.
I'd be interested to hear of the hacks..

I've got a hosted application that has started losing session state since 
they upgraded PHP and they're blaming me and I know it isn't because I 
have the same spec locally and the same script on different servers.

is there something I can add to my script or in an htaccess file to keep 
my sessions away from their garbage collection, as it seems likely that I 
have a similar situation to you.

TIA

Tony

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


[PHP] Losing Sessions.

2003-12-04 Thread Tony Crockford
I hope someone can help.

I have a simple login process that someone wrote for me.

It uses two stored variables which it checks on each new page, if it can't 
get them it assumes you should login first and sends you to a login page.

Everything was okay.

I used the same script on a different server (with almost identical PHP 
setup) and now I'm getting randomly logged out. (it works fine locally and 
remotely on a different server)

Can some-one suggest some useful things I could check to try and track 
down the problem?

Many thanks

Tony

This is the check that gets called from each page:


//check to see if the session is set. (the session is set when the user 
logs in)
//if the session is set, then it must have some data in it... in this case 
we have the user_ref and the group_ref, so that we can see who is logged 
in and what group they belong to.
//if the session isnt set, then we redirect the user to the login.php page 
so that they can log in or if they cant log in they get an error message.

if (isset($_SESSION[$xebitsession])) {

$user_ref=$_SESSION[$xebitsession]['user']["user_ref"];
$group_ref=$_SESSION[$xebitsession]['user']["group_ref"];
}   else {

header("location:logged.php");
}
?>
this is the login:

mysql_connect($db_Hostname, $db_UserName, $db_Password);
mysql_select_db($db_Database);
session_start();
session_register("xebitsession");
function displaylogin() {

include("includes/header.html");
// open content body table
include("includes/contentheader.html");
include("includes/title.html");
include("includes/contentheader2.html");
include("includes/contextheader.html");
include("includes/contentbody.html");
?>

User Login







Login
Please enter your username and password below.


Username:


echo '' .  "\n";
echo '' . "\n";
?>



Password:



 




 







//close content table section
include("includes/contentfooter.html");   
//close page section
include("includes/footer.html");
}
$username=$_POST[user];
$pass=$_POST[pass];
$username = addslashes($username);
if (!$username) {
displaylogin();
} else {
$sql="SELECT * FROM duser WHERE upass='$pass' AND username='$username'";
$result = mysql_query($sql);
// Start the login session
if (! isset ($_SESSION[$xebitsession])) {
  while ( $row = mysql_fetch_array($result) )
  {
$_SESSION[$xebitsession]['user']["user_ref"] =$row['user_ref'];
$_SESSION[$xebitsession]['user']["group_ref"]=$row['group_ref'];
   }
header("location:index.php");
}
else {
header("location:index.php");
}
}
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Locking mysql tables with PHP

2003-11-25 Thread Tony Crockford
On Tue, 25 Nov 2003 07:47:58 -0600, Jay Blanchard 
<[EMAIL PROTECTED]> wrote:

[snip]
[snip]
is there a way I can get a number and increment it all in one query
then?
[/snip]
UPDATE tblFoo SET value = (value+1) WHERE conditions

Hmm.. my bad - I get that bit, but can I do:

SELECT value WHERE conditions UPDATE tblfoo SET value= (value+1)
[/snip]
Essentially that is what the UPDATE statement is doing, you are
selecting values to be updated with the where condition. Your way is two
queries The SELECT (which locks, then releases) and the UPDATE (which
locks, the releases). In the split second between the select and update
the row is not locked, an undesirable conditions.
Ah.

Sorry, I'm being particularly dense today.

What I want to do is get the value from mysql for use in the PHP page, but 
update the value once i've got it.

How do I give the rest of my PHP script the original value to use with an 
SQL update?

e.g.

get counter value & increment counter value (so my number can't be used 
again)
use original counter value as *part* of unique reference number to save 
user input details in a different table.

TIA

Tony

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


Re: [PHP] Locking mysql tables with PHP

2003-11-25 Thread Tony Crockford
On Tue, 25 Nov 2003 07:15:10 -0600, Jay Blanchard 
<[EMAIL PROTECTED]> wrote:

[snip]
is there a way I can get a number and increment it all in one query
then?
[/snip]
UPDATE tblFoo SET value = (value+1) WHERE conditions

Hmm.. my bad - I get that bit, but can I do:

SELECT value WHERE conditions UPDATE tblfoo SET value= (value+1)

Thanks

Tony

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


Re: [PHP] Locking mysql tables with PHP

2003-11-25 Thread Tony Crockford
On Tue, 25 Nov 2003 13:50:36 +0100, Marek Kilimajer 
<[EMAIL PROTECTED]> wrote:

Tony Crockford wrote:

get a numeric value from a MySQL table, do a calculation, then on 
another PHPpage update the numeric value in the table.

what I don't want is anyone else getting the same number from the table 
before I've updated it.

what PHP would you use to do this?


LOCK TABLES will not work because the lock is released when the first 
page is finished. You could use a file that will you will use as a lock, 
but this could lock your table for minutes and eventualy, if the user 
desides not to take any action, forever. I would suggest to use a 
temporary table to hold taken numbers.
Oh, okay.

is there a way I can get a number and increment it all in one query then?

TIA

Tony

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


[PHP] Locking mysql tables with PHP

2003-11-25 Thread Tony Crockford
Hi

bit confused!

here's what I want to do:

get a numeric value from a MySQL table, do a calculation, then on another 
PHPpage update the numeric value in the table.

what I don't want is anyone else getting the same number from the table 
before I've updated it.

what PHP would you use to do this?

Sorry for what is probably a really basic question - I did look at the 
MySQL manual, but I'm not sure how exactly to issue an SQL query LOCK 
TABLES using PHP.

TIA

Tony

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


[PHP] PHP/MySQL best practice tutorial

2003-07-29 Thread Tony Crockford
I have a mySQL database containing items that are categorised four
levels deep.

when I'm getting the data out (in a tree structure) I'm nesting SQL
queries inside array traversing loops (select distinct category, while
$row= echo stuff select distinct subcat, while $row= echo stuff etc)

I'm sure this isn't the best way and I oought to be selecting all the
items and then doing some sort of sorting and then traversing the whole
lot, doing one thing until the category changes and then doing something
else until the category changes again and so on.

can anyone point me to a tutorial that would help me switch from nested
select statements to something more elegant?

Thanks

Tony


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



RE: [PHP] Is this possible?

2003-07-23 Thread Tony Crockford

> Umm, you mean like:
>
> select i.id,d.description from items i, descriptions d where
> d.itemid =
> i.id;
>
> ?

Of course I do!

How stupid am I?

No, don't answer that - it's been a long week working on the wrong
stuff!


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



[PHP] Is this possible?

2003-07-23 Thread Tony Crockford
Hi


Thanks for the help on previous questions, I now have an in principle
type question.

I have a MySQL database - "items" in one table and "descriptions" in
another with a common key: item_ref
It is used to create a sort of categorised directory of the items.
(http://www.torbytes.co.uk)


each table has a status field the "items" have a default description and
the "descriptions" have a level classification.

up to now been working through all the items and printing out the
descriptions at each level printing the default if I don't have a
matching description, but I now need to do the following:

for a particular level print only the items (and their matching
description) where there is a matching description. (I hope you see what
I mean)

since the items are categorised and I don't want any dead ends in my
tree structure I have to know if there's a description before I start
working through the items.

I thought that this might be the way to do it:

select all the item-ref values from the description table.

step through this select array selecting the required fields from the
item table where item_ref=item_ref and adding them to another array.

then step through that array building up the tree structure

The trouble with it as I see it is:

it's a lot of select calls to the database (one for every description
found) and I'm not sure how to add the fields found in the item table to
a new array.


Am I going at this the wrong way?

Any help, clues or abuse accepted.

Thanks

Tony



--
NEO organizes my Outlook - check it out:
http://www.caelo.com/a/rl.php3?i=3NTVV


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



[PHP] changing the name of a variable by another variable.

2003-07-22 Thread Tony Crockford
I really am having a difficult day.

I want to do an incrementing while loop that will echo out the values of
$variable1 , $variable2, $variable3 which exist previously.

so how do I get the incrementing number onto the word variable? to make
a new variable that matches thename of the existing ones..

I tried echo $variable$increment ; but $variable doesn't exist alone so
all I get is $increment.

I'm not sure what I should be looking for in the manual - google's not
much help either.

anyone give me a clue?

TIA

Tony


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



RE: [PHP] Re: Newbie lost in array

2003-07-22 Thread Tony Crockford
 
> hi tony,
> how is your table structured? is is a csv-file, a database, a 
> html-table,
> ...?
> ciao SVEN

Ooops!

MySQL sorry

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



[PHP] Newbie lost in array

2003-07-22 Thread Tony Crockford
I've got brain fade today and am in need of a clue, please accept
apologies if this is obvious.

I have a data table:

 P_ref P_code P_Value

I want to read the data out where P_ref='somevalue' and create variables
for the content of P_Code with a value of P_Value

what should I be looking for in the manual?

TIA

Tony



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



[PHP] condensing a list from MySQL

2003-06-09 Thread Tony Crockford
Hi all,

not sure where to start with this.

I have a keywords field in a mysql database - allows up to 100
characters of words seperated by spaces.

at a late stage in the development process the client would now like a
summary list of keywords that they've entered.

I guess what I need to do is open each keyword field, extract the words,
add them to an array, remove duplicates and sort alphabetically.

sounds easy but I'm still finding my way - anyone got a sample script or
some helpful hints they'd care to share?

thanks

Tony


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



RE: [PHP] Re: Using register_globals

2003-06-05 Thread Tony Crockford
On this topic, could anyone point me to a good tutorial on how to
convert from sloppy code that assumes register_globals is on to good,
secure code that assumes register_globals is off.

something that covers what to look for and what to change it to would be
a great help.

I've been learning by working with someone else's (we bought it) code
and it won't run with register_globals off and I'd like it too.

it makes use of sessions (an area I'm still struggling with) and passes
a lot of variables from form to form, sometimes with post and sometimes
with get.

any suggestions would be much appreciated.

I looked at the manual and googled a lot, but can't find a plain english
guide to doing it right!

Thanks

Tony


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



[PHP] File manipulation tutorials / helpful resources

2003-03-24 Thread Tony Crockford
Hi

What I'd like to do is open an html file, strip out the content between
the  tags so that I can insert it into my own template.

Has anyone got any good resources or tutorials I could read to help me
accomplish this simple sounding task.

I have no idea where to start! ;o)

Thanks everyone.

Tony


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



RE: [PHP] File handling

2003-02-13 Thread Tony Crockford
> How do i delete all file in a directory???
> 

You could use a function like this:
(html code at end)


function delFiles($filter, $sDir) {
$cDirectory = includeTrailingSlash($sDir);

$handle = opendir($cDirectory);
while ($file = readdir($handle)) 
{
if ($file == '.' || $file == '..') 
{
continue;
}
if (is_dir($cDirectory . $file)) 
 {  
 echo "ignoring $cDirectory$file ";
delFiles($filter, $cDirectory . $file);
continue;
}

if (eregi($filter, $file)) 
 {

echo " deleting $cDirectory$file ";
  unlink($cDirectory . $file);
 
}
}
  closedir($handle);
}

function includeTrailingSlash($path) 
{
if (!eregi("/$", $path)) 
{
$path .= "/";
}
return $path;
}

// delete all the .htm files in this directory and it's sub directories

$sDir="the directory you want to delete files in";

delFiles("\.htm$", $sDir);

//where\.htm$ is the filter you are applying

echo "done deleting old files ";


hth

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




RE: [PHP] PHP Trouble-Ticket-Systems?

2002-12-01 Thread Tony Crockford
 
> So the question is, does anyone know any good 
> troubleticket/helpdesk-systems written in PHP?
> 
> 
> Thanks,
> 
> Thomas


This would seem to fit the bill:

(I've used it and can recommend it)

http://helpdesk.oneorzero.com/

HTH

Tony 

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




RE: [PHP] Logic headache, please help.

2002-11-11 Thread Tony Crockford




> -Original Message-
> From: Marco Tabini [mailto:marcot@;tabini.ca]
> Sent: 11 November 2002 14:46
> To: Tony Crockford
> Cc: Php-General@Lists. Php. Net
> Subject: Re: [PHP] Logic headache, please help.
>
>
> How about building an array of all the levels:
>
> $a = array();
>
> for ($i = 1; $i <= $maxlevels; $i++)
>   $a[] = $i;
>
> then for each level you can create a new array that is the difference
> between the original array and an array that contains the
> current level:
>
> for ($i = 1; $i <= $maxlevels; $i++)
>   $a1 = ;
>   echo 'Level ' . $i;
>
> I'm not 100% that this will work right off the bat, but it should at
> least put you on the right track... if not out of your misery :-)
>
> Hope this helps.

It looks like it might, but I note this warning in the manual
re:array_diff

Warning
This was broken in PHP 4.0.4!

http://www.php.net/manual/en/function.array-diff.php

is it fixed in 4.06 do you know? (host uses 4.06, I have 4.2.2)

TIA

Tony



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




[PHP] Logic headache, please help.

2002-11-11 Thread Tony Crockford
Hi all,

brief explanation:

I'm building a select list, to exclude certain directories from a search
(with Ht://dig).

The structure is like this:

All levels
Level 1
Level 2
Level 3
Level 4


for four levels, where the option value should be all lv's except the
current option level.

I have a variable $maxlevels to count up to however many levels are
required and  I want to make this select list work based on the value of
$maxlevels.

How would you approach the building of the list?

I was going to use a while loop or two, but I'm stuck at the point of
creating the value "string" which should contain all the levels from 1
to $maxlevels except the current level. which would seem to require some
sort of conditional "if $thislevel string is" type of approach, but I
can't get my head round it.

Anyone put me out of my misery?

Thanks

Tony





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




RE: [PHP] Error?

2002-10-27 Thread Tony Crockford
> 
>  if($new)
>   {
> $details =  get_product_details($new);
> if($details["catid"])
>   $target = "show_cat.php?catid=".$details["catid"];
> //line 55 is the bracket below.
> }
>   $path = $PHP_SELF;
>   $path = str_replace("show_cart.php", "", $path);
> 
> 
> Error:
> 
>  Warning: Can only count STRING and INTEGER values! in
> /www/u1255/shop_testing/show_cart.php on line 55
> 
> Any ideas? all I'm trying to do is pass a qty from a form?


Maybe it's me, but shouldn't there be a { on or around this line:

if($details["catid"]) ?
>   $target = "show_cat.php?catid=".$details["catid"];
 

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




RE: [PHP] Re: Script optimisation

2002-10-16 Thread Tony Crockford


> As I said at the start, it very much depends on what is required for a
> particular script...
>

Here's an area I'm struggling with:

(it's a breadcrumb trail building ";
getcat1name($cat1_ref);
echo "";
//subcat1
echo "";
getsub_cat1name($sub_cat1_ref);
echo "";
//cat2
echo "";
getcat2name($cat2_ref);
echo "";
//subcat2
echo "";
getsub_cat2name($sub_cat2_ref);
echo "";
?>

every time I mess with the "--" and '--' I end up getting an error or no
output.

from what you're saying this would be a slow part of the script and as
I'm generating nearly 4000 pages atm it would be good to speed this bit
up.

how would you do it?

TIA

Tony




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




[PHP] Script optimisation

2002-10-16 Thread Tony Crockford

Hi,

I'm sure this is an RTFM, but I'm not sure where I should be looking.

is it quicker for PHP to execute  in blocks of html or to
echo all of the html and only have one 

I'm using a PHP script to write a lot of html files to hard disk and the
script execution time is climbing beyond the maximum set in PHP.ini
(I've changed the setting, but...)

I'm looking to shave milliseconds of each execution, any ideas, pointers
or tutorials you could point me to.

Thanks


Tony


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




RE: [PHP] formatting / beautifying PHP code

2002-10-07 Thread Tony Crockford

 
> Is there a utility that formats / beautifies PHP code like 
> indent does for C
> code?

something like this?

http://tools.phpedit.net/phpCodeBeautifier/

HTH

Tony

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




RE: [PHP] document_root

2002-10-01 Thread Tony Crockford


> Check out:
> http://www.php.net/manual/en/function.getcwd.php
>
> HTH
> -Brad

Certainly does, thanks.

I suppose if I'd thought to look at the manual contents rather than
trying to construct a *search* I might have found that

Oh well, so much to learn so little time.

Thanks

Tony


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




[PHP] document_root

2002-10-01 Thread Tony Crockford

Hi

what exactly does document_root do?

Does it give to path to the file from the server root?

or does it give the path to the server root?

has something changed in 4.2.2

If I want the path to the document I'm in how do I get it?

looked everywhere (manual, books and archive), but the answer is
probably so simple I'm not looking in the right place.

help and abuse gratefully received.

Thanks

Tony


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




[PHP] FW: Generating Static files

2002-04-01 Thread Tony Crockford


>Hi
>
>what's the best way to generate static files using PHP/MySQL?
>
>I've read a couple of tutorials and got a bit lost.
>
>What I'd like to do is use PHP to generate static pages in 
>the way that GDIdb pro does (run a script/template 
>combination, output html files all linked up)
>
>this is where I'm using GDIdb Pro:  
>http://www.boldfish.co.uk/resorces.htm
>
>can anyone point me in the right direction?
>
>Thanks
>
>Tony
>
>
>-- 
>If you're suffering from email overload, check out NEO:
>http://www.caelo.com/a/rl.php3?i=3NTVV 

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




RE: [PHP] which php book 2 buy ?

2002-03-26 Thread Tony Crockford

>
>I thought this would have been a great book if it weren't for the
>numerous errors in the code sections.  I highly recommend
>it if you know
>PHP well enough to bang out a few forms and if you know MySQL well
>enough to write some INSERT and SELECT statements -- if
>this is the case
>then you will have no problem noticing the errors, and can
>use the book
>as a guide to writing complex web applications.  In my
>case, though, I
>started learning PHP with this book, and the frustration with code
>errors drove me to return it to the store.


Nothing like a bit of debugging to get to know a language!

The CD code is different too, so maybe they put it right?

Oh well

(I'll ask Jay, he's a regular on evolt's TheList!


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




RE: [PHP] which php book 2 buy ?

2002-03-26 Thread Tony Crockford


>I wanna buy a book from amazon . . .but don't know which one..
>Do you know where I will find examples of shopping carts ?
>(which book ?)


MySQL/PHP Database applications by Greenspan and Bulger  ISBN
0764535374

Good book.

Also has a 40 page chapter on how to build a shopping cart complete
with design rationale and working code (on CD)

HTH

Tony


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




[PHP] Generating Static files

2002-03-19 Thread Tony Crockford

Hi

what's the best way to generate static files using PHP/MySQL?

I've read a couple of tutorials and got a bit lost.

What I'd like to do is use PHP to generate static pages in the way
that GDIdb pro does (run a script/template combination, output html
files all linked up)

this is where I'm using GDIdb Pro:
http://www.boldfish.co.uk/resorces.htm

can anyone point me in the right direction?

Thanks

Tony


--
If you're suffering from email overload, check out NEO:
http://www.caelo.com/a/rl.php3?i=3NTVV


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