Re: [PHP] Problems creating images

2006-04-05 Thread Philip Hallstrom
I added image confirmation to a guestbook and even though it works greate for 
most people, some people have problem and I can't seem to figure out why this 
happens. Note that I'm not talking about the same guestbook on one server but 
the guestbook is on people's own hosting server.


The php code to create the image can't be simpler:

*confirm_image.php:*
$datekey = date(F j);
	$rcode = hexdec(md5($_SERVER[HTTP_USER_AGENT] . $cfg_sitekey . 
$random_num . $datekey));

$code = substr($rcode, 2, 6);
$image = ImageCreateFromJPEG(images/code_bg.jpg);
$text_color = ImageColorAllocate($image, 80, 80, 80);
Header(Content-type: image/jpeg);
ImageString ($image, 5, 12, 2, $code, $text_color);
ImageJPEG($image, '', 75);
ImageDestroy($image);

Most people get a nice image but some people get only, what appears to be, 
garbage:


JFIF;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), 
quality = 75 C    $.' 
,#(7),01444'9=82.342C  
2!!22

...snip...

For the complete output have a look here:
http://www.samuel-area.de/phpbook/confirm_image.php

Do you know what is going wrong here?


Not entirely, but when I go to that URL and check the headers (Live HTTP 
header extension in firefox) I get this:


HTTP/1.x 200 OK
Date: Wed, 05 Apr 2006 20:02:02 GMT
Server: Apache/2.0.53 (Fedora)
X-Powered-By: PHP/4.3.11
Content-Length: 1501
Connection: close
Content-Type: text/html; charset=iso-8859-1

Notice that last one... I see you set it up above, but it isn't 
sticking


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

Re: [PHP] int to string

2006-04-05 Thread Philip Hallstrom

I don't think it's built in, so I was wondering ya'll would recommend as the
best way to convert int to string, not basic type casting, but converting to
the english word the int represents.

Something like this:

5 = Five or 20 = Twenty


If you wanted a full solution (well maybe, I didn't read it closely) I'd 
search google and take the second link.


http://www.google.com/search?q=convert+number+to+words

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



Re: [PHP] Need a CRM recommendation

2006-04-04 Thread Philip Hallstrom

I need recommendations for a good CRM done in PHP, thanks!


http://www.opensourcecms.com/

Lots of options, ratings, reviews, demos, etc.

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



RE: [PHP] Need a CRM recommendation

2006-04-04 Thread Philip Hallstrom

[snip]

I need recommendations for a good CRM done in PHP, thanks!


http://www.opensourcecms.com/

Lots of options, ratings, reviews, demos, etc.
[/snip]


Lot's of good CMS's there, only one, maybe two CRM's.


Woops.  That's what happens when you read too fast...

No experience with it, but there's http://www.sugarcrm.com/crm/

-p

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



Re: [PHP] Strtodate() bug?

2006-04-03 Thread Philip Hallstrom

I've got some weird behavior using PHP 4.3.9.  I use the function of
strtotime(last Sunday); and it's returning the timestamp for last
Saturday.  However, if I use strtotime(-1 day); (I'm running this program
on a Monday) it returns the correct timestamp for Sunday.

Is this a bug in PHP 4.3.9?


Probably.  5.1.2 says:

$x = strtotime(last Sunday);
print ( date('r', $x) );
Sun, 02 Apr 2006 00:00:00 -0800

4.3.9 is *really* old.

-philip

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



Re: [PHP] Multidimentional array problems

2006-04-03 Thread Philip Hallstrom
I am trying to read form a database and place everything in a 
multi-dimentional array


This is what I am doing and the output (for testing) seems correct
while($row=mysql_fetch_array($result))
{
$banner= array($arrayIndex = $row);

echo $banner[$arrayIndex][image]. br;
echo $banner[$arrayIndex][url]. br;
echo $banner[$arrayIndex][display_type]. br;
$arrayIndex++;
}


What are you setting $arrayIndex to initially (before the while loop 
starts?)



When I try and use
$value=0;
while($value  $number_of_banners_db )
{
  echo $banner[$value][url]. br;
  echo $banner[$value][image]. br;
  echo $banner[$value][display_type]. br;
}

I only get the last set of values that where entered into the array.  I want 
to be able to pull all the values out


$banner[0]['url']
$banner[1]['url']
$banner[2]['url']  etc.

I don't use arrays much and I have been going thru my books but I still can't 
seem to get it to work.


Try a print_r($banner) and see what it looks like

-philip

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



Re: [PHP] XML-RPC or SOAP

2006-03-30 Thread Philip Hallstrom
I am at the beginning of creating a web service. As I am not very familar 
with both SOAP and XML-RPC it would not make much difference in which one I 
learn.


Which one would you guys recommend for a web app that has to be transformed 
into a white lable solution.


I just did one using SOAP.  Seems to work just fine.  Just be sure to get 
the WSDL generator from here:


http://www.schlossnagle.org/~george/php/WSDL_Gen.tgz

We did it using PHP5's soap extension.

good luck!

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



Re: [PHP] Database connections

2006-03-30 Thread Philip Hallstrom

I have almost finished making a set of scripts that would communicate with
maybe 1k sites to start with...

I'm sorry I cannot give you more details about the scripts but this guy is
really nervious and had me sign an NDA etc etc

but what i would like to know is; would there be a problem with connecting
to the database many hundred/thousand times a minute? (esp on a shared
server as this guy and I cannot afford a dedicated at this point)
Mostly the normal/usual queries...eg: select, update, delete very little
JOIN or sub-selects


There's no problem doing that... 1,000 times a minute is only 16 queries a 
second.  That's not that bad from a technical point of view, but from a 
political point of view you'd have to ask your ISP what they think.


ISP's have been known to get upset about this sort of stuff... just 
depends on what their rules are.


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



Re: [PHP] validating ereg patterns

2006-03-29 Thread Philip Hallstrom

How do I detect the difference between a bad ereg pattern and no matches?

I've got a UI that allows the user to enter an ereg expression.   Clearly, 
the user may enter an invalid expression (for example, the expression may not 
have matching [] brackets).  ereg returns false if there are no matches or if 
an error occurred.


I need to distinguish between no matches and an error, so I can present a 
meaningful message to the user.  Any suggestions on how to do this?


Maybe try preg_match.  The docs say it will return false for an error, 
otherwise the number of times it matched.


-philip

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



Re: [PHP] $i vs. $r

2006-03-27 Thread Philip Hallstrom
I simplified the code a bit, and I am guessing that it was too much. Below is 
the complete code that works fine. The weird part is, the part that I have 
the question on, is if I change $r to $i, it doesn't work anymore. $i doesn't 
count up as it should and instead gives me some unpredictible results. as 
it goes down the list sometimes its sequential (1,2,3 but never more than 3), 
other times its just the number 2 over and over).



$r = 1;

while ($row = mysql_fetch_array($website_result))
{
if (is_int(($r+2)/3))
{   echo (\ntr);}
echo (\ntd align=\center\ valign=\bottom\);

include($site_path/common/code/directory_format_name.php);


I'm going to guess that $site_path/common/code/directory_format_name.php 
uses $i to do something else on it's own and is therefore messing up your 
$i.  At least that's where I'd start looking.




// Gets the name Formatter
		echo (\na href=\/directory/.$row['sup_link']./\img 
src=\/images/directory/.$row['sup_picture'].\ border=\0\/a);
		echo (bra 
href=\/directory/.$row['sup_link']./\$full_name/a);


echo (\n/td);
if (($r = $website_total) AND 
(is_int(($r+2)/3)))

{   echo (tdnbsp;/tdtdnbsp;/td/tr);   }
elseif (($r = $website_total) AND (is_int(($r+1)/3)))
		{	echo (tdnbsp;/td/tr);	} 
elseif (is_int(($r)/3))

echo (\n/tr);

$r++;

}
echo (/table);


--
Kevin Murphy
Webmaster - Information and Marketing Services
Western Nevada Community College
www.wncc.edu
(775) 445-3326


On Mar 27, 2006, at 3:11 PM, Jasper Bryant-Greene wrote:


Kevin Murphy wrote:

Does anyone have a clue why using this code doesn't work:


Please specify what doesn't work means in this case :)


$i = 0;
while ($row = mysql_fetch_array($result))
   {   echo (Blah blah blah);
   $i++;
   }



$r = 0;
while ($row = mysql_fetch_array($result))
   {   echo (Blah blah blah);
   $r++;
   }


Those two blocks of code are for all intents and purposes identical, and 
indeed probably end up as exactly the same opcodes.


Jasper

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



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



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



Re: [PHP] Security in php/ajax scripts

2006-03-20 Thread Philip Hallstrom

I am slowly converting my webapps to use the 'ajax' technology.  I'd like to
know what 'best practices' should I use when it comes to authenticate,
identify the requests in a more restricted context.

So far I've migrated some 'open' areas where the user, without having to
identify himself can perform searches. But I need to allow/deny him to do
insert/delete/update actions.

In the traditional webapp I'd create a login page where the user. password
would be checked against a database and a session variable would be set with
a authenticate code.  Further access to restricted pages are allowed/denied
based on the existance of this authenticate code.

What would be a good alternative in my ajax-enabled webapp?  I cant use
session in my php scripts (those called by the XMLHttpRequest.open) right?


Why not?  Not that I've tried it, but your browser is going to be making 
the call and I would imagine it would send along any cookies it has just 
like it normally does...


Try it and see if it sends the session cookie along...

-philip

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



Re: [PHP] GD2 gif resizing problem

2006-03-15 Thread Philip Hallstrom

I'm trying to resize GIF images and up with very large files

For example:
Original width = 720
New width = 980
Original height = 1008
New height = 1274
Original filesize = 80kb
After resizing = 235kb

Based on the area increase; I'd expect the file size to about double, not be 
4x as large.


$src_img = imagecreatefromgif($filename);

$dest_img = imagecreatetruecolor($new_width, $new_height);

imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $new_width, $new_height, 
$org_width, $org_height);


imagegif($dest_img, $filename);

I tried using imagetruecolortopalette() and it helped a little; but screwed 
up the image quality.


Can anyone explain or have a solution?


What's the image?  If it's photo-like, save it as a PNG or JPEG and you'll 
get much smaller files.  GIF's don't do very well with some images as it 
can't encode them very efficiently.


I don't remember which way it goes, but a 1x500 gif of a solid color will 
be much much much larger than a 500x1 gif of a solid color.  The latter it 
can compress by sayign something like x color for the next 500 columns on 
this row.


If it were me, I'd try jpeg/png first.

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



Re: [PHP] CLI versus apache module

2006-03-15 Thread Philip Hallstrom
I have a.php includes b.php .  b.php is used by other pages that are served 
through apache.  a.php used to be started through apache, but now  need to be 
started from command line.  How do I know if a php file is running as apache 
module or as CLI ?


http://us3.php.net/manual/en/function.php-sapi-name.php

-philip

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



Re: [PHP] Hostname Filtering

2006-03-14 Thread Philip Hallstrom
I have a few PHP scripts where I log hit to a page i.e. IP and hostname via a 
look up.


What I want to do is create essentially a blacklist to prevent bots and other 
hosts and IP from being logged and skewing my stats.  My local IP/host and 
the MSN and Googlebot hits should not be in my stats or at least I can flag 
them to hide them.


For example:

$blacklist = array(
'*.wavefront.ca',
'*.googlebot.com',
'msnbot.msn.com',
'*.inktomisearch.com',
'68.146.96.245'
);

So lets say I have my host:

$host = 'lj602144.inktomisearch.com';

I want to quickly parse this array and return a simple boolean if I am in the 
blacklist.  I could create a loop and cycle through the array valves and to a 
regex on each but I was hoping someone would have a more elegant solution.


http://us3.php.net/in_array

You might want to rethink things though... if you list hostnames you're 
going to have to do a DNS lookup for *every* request to that script. 
That's going to take some time.


So you might want to log everything, then after the fact prune the 
results.  Just be sure to use some sort of dns caching strategy...


-philip

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



Re: [PHP] moving data from mssql to mysql on linux

2006-03-14 Thread Philip Hallstrom

I have a project where I need to connect to a remote SQL Server and move
data from their to my localy MySQL server.  On the remote SQL Server, I only
have access to a few views but need to get their data and move it to my
local MySQL db.  What is the best way to do this?  I have freetds compiled
and configured for php on my server and currently connect to the SQL Server,
do my query and then loop through the result inserting into MySQL a row at a
time but this just takes to longis there a better way?


Look at disabling indexes until the inserts are done.  Also insert 
delayed or insert ignored... (don't remember the exact specifics).  If 
it's innodb, wrap the inserts in a transaction and commit every 100 rows 
or so.


Also, before spending too much time on it, you'll never get faster than 
you can query out of sqlserver... so if that's the bottleneck not much you 
can do about it.


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



Re: [PHP] Zoomable map

2006-03-08 Thread Philip Hallstrom

I have been searching for this, but maybe one of you has seen it before
and can save me some time. I need a class that will allow me to create a
zoomable map application. I have a map, I just need folks to be able to
zoom and scroll,etc. TIA!


http://script.aculo.us/

might have what you need...

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



RE: [PHP] Zoomable map

2006-03-08 Thread Philip Hallstrom

[snip]

I have been searching for this, but maybe one of you has seen it

before

and can save me some time. I need a class that will allow me to create

a

zoomable map application. I have a map, I just need folks to be able

to

zoom and scroll,etc. TIA!


http://script.aculo.us/

might have what you need...
[/snip]

No zoomable maps here, a bunch of Ajax and Javascript stuff though.


Right.  If you have a map, this will give you tools to zoom and scroll...

-philip

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



RE: [PHP] max unique number

2006-03-07 Thread Philip Hallstrom

[snip]
How do i get a unique max number from a mysql table column?
[/snip]

SELECT MAX(number) FROM table LIMIT 1;


That might not be unique though... I'm wondering if the original poster is 
looking for AUTO_INCREMENT (ie. sequences) to ensure a unique id to use 
for insertion...?


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



Re: [PHP] Sessions in PHP... where to start???

2006-02-27 Thread Philip Hallstrom
Hi everybody! I have a problem and I was told to check out the sessions 
part in PHP. What I want to deal with is the following : I have a PHP 
page with a form, where the user writes some data. These data are then 
written into a file which is then used in a system command as input for 
an external program (NOTE: The data MUST be written into a file, it 
cannot be done elsewhise, because the external program takes a file as 
input). The thing is that I must somehow create a file everytime a user 
enters data into the form, so I must learn something on sessions I 
think. My question is, since I don't have a login system or something 
like that, but just want to create a different file each time (with the 
session_id being part of it, so that the file is unique), which session 
commands do I need?


If it were me I'd use tempnam() to create a unique file for that 
particular user and then use sessions to store the name of that file in 
the user's cookies...


http://us2.php.net/tempnam
http://us2.php.net/manual/en/ref.session.php

-philip

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



Re: [PHP] defined

2006-02-25 Thread Philip Hallstrom



I'm having kind of a weird problem I want $MailSubject to contain a the value 
prayer unless I tell it other wise.

// on a form processor.
$MailSubject = Praise;
include_once(mailit.php);

// then in mailit.php
include form2mail.php;

// and in formtomail.php
if(!defined($MailSubject)) // This is the problem line
{
  $MailSubject = Prayer;
}

The problem I believe is with the defined function check. (I think) the 
value of $MailSubject is maintained to the end so I'm don't think it to 
be a scope issue, but also, if I don't assign a value to it it should be 
running the if() statement, but it's not.


Any thoughts?


Try...  if (empty($MailSubject)

-philip

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



Re: [PHP] Conceptional question on dealing with different languages

2006-02-22 Thread Philip Hallstrom

Hello list,
it has been a while since I've posted the last time, but now I need your
help/ opinion again.  I'm re-designing an existing page for an online
shop which is supposed to be used in different languages. The former
design was just a plan echo for an output since the page was only
intended for the German market. But now the output depends  on the
language the user selected. Currently we think of two languages, but
that might change sooner or later (management decision...).

Of course I don't want to ad an case of $language for every former echo.
I want to export the content to one central file/ object / table...
The infrastructure is PHP5 MySQL.

Now my ideas, where I would need your opinion:
1. a XML File which I read via SimplXML
2. a plan Text file
3. a PHP class where I delviver the content out of arrays
4. or a table in MySQL

Do you have other options, that might be useful? Which would you prefer?


Haven't used it, but see it everywhere...

http://us3.php.net/gettext

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



Re: [PHP] Looping from A to Z

2006-02-19 Thread Philip Hallstrom
Good afternoon.  I'm having trouble getting PHP to loop from A through Z. 
Here is what I tried, coming from a C background:


for ($l = A; $l = Z; $l++)
   echo $l;

// Returns A, B, C, ..., X, Y, Z, AA, AB, AC, AD, AE, ... YX, YY, YZ.  (26 * 
26 results!)


Interestingly, if I make it a less than operation instead of less than or 
equal to, it works correctly (except for the Z):


for ($l = A; $l  Z; $l++)
   echo $l;

// Returns A, B, C, ..., W, X, Y  (25 results)

Anyone know why PHP would do that?


Nope... but try...

for ( $l = ord(A); $l = ord(Z); $l++ )
echo $l;

Also maybe check out the range() function.

-philip

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



Re: [PHP] PHP job postings?

2006-02-16 Thread Philip Hallstrom
Just wondering if anyone know of a mailing list of forum specifically 
dedicated to soliciting for programmers to fill PHP programming 
positions?


I see people post to this list periodically but it really doesn't seem 
like the right place.  Our project is going to be expanding quite a bit 
and we are probably going to be hiring more on-site programmers probably 
in the near future.


Specifically we're looking for people (or lists/forums) in the MD/DC/VA 
area.


Just kind of pre-scouting for my boss before we resort to going through 
headhunters and recruiters and the big job posting sites.


I think it's a reasonable place as long as you clearly mark the subject 
JOB with the *location*.


Also...

http://www.zend.com/jobs/
http://craigslist.org/

Seems craiglist.org has much better stuff than monster, etc.

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



Re: [PHP] string size in bytes

2006-02-12 Thread Philip Hallstrom

i need to know how many bytes are in a string

example:

$string = blah;

string == how many bytes


Well, if you're willing to ignore all the unicode stuff, you can use 
strlen() since 1 byte = 1 character.  Check that manpage to see if there's 
a unicode safe version.



also i need to know how to find out how fast a page renders

example;

page rendered in 1.114 seconds


microtime().

Call it at the beginning of your script, then at the end, and substract 
the two values to see how long it took.


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



Re: [PHP] how to learn php

2006-02-10 Thread Philip Hallstrom

i have been trying to learn php.

what is the best approach to learning php for someone who has no programming 
experience?


i am very familiar with html, xhtml, and css. i'm not an idiot when it comes 
to using computers.
i have bought several books and have subscribed to a couple of the php 
mailing lists, but i feel that i could be doing more to learn php.


what approach (and steps) did you take in learning this really cool scripting 
language? should i look into taking classes or stick with an autodidact 
approach?


well, this is free...

http://www.hudzilla.org/phpbook/

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



Re: [PHP] Re: [Off] Cheap SSL certificates?

2006-02-03 Thread Philip Hallstrom

Jim Moseby wrote:

Well said.  If you're going to buy a $15 Cert from billy-joe-bob's CA and
carwash, you might as well sign your own cert.  Thats free...



That might work in an intranet setting, but in an internet setting, you will 
get the security warnings.  :)


Only once per user/browser though.  Firefox will ask if you want to accept 
it permanently.  With IE you have to ask that they download your root 
certificate (click click, installed)


Not ideal for certain applications, but for somethings (like a groupware 
app for a small/medium company) it's totally fine.


-philip

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



Re: [PHP] Re: [Off] Cheap SSL certificates?

2006-02-03 Thread Philip Hallstrom

On Fri, February 3, 2006 11:06 am, Philip Hallstrom wrote:

it permanently.  With IE you have to ask that they download your root
certificate (click click, installed)


I've never gotten that to work, actually...

It always keeps asking me over and over to install the cert and I
do, and next time I go back, it asks again.


Hmm... it's been awhile since I've done it, but my memory is that you just 
upload your ca.crt file to the web and have them click on it.  As they go 
through the steps it should add it to the root store.


Somewhere I've got info on it, but it might take me awhile to find.  Bug 
me offlist if you're interested.


-philip

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



Re: [PHP] How can I dynamically place a small on a large image?

2006-01-30 Thread Philip Hallstrom
I'm working on an application using the html map tag where I'd like to 
automatically place a small image on a larger image automatically.


For example, I've got a table of map coordinates such as:
map name=Map
 area shape=rect coords=469,188,488,205 
href=/courses/Start_Locs/Loc_Maps/baes.jpg


Where I've got about 40 area coordinates stored in a DB that changes often.

I don't want to have to manually edit the main image every time a new 
coordinate is added or moved.


Anyone know of a way to do this, other than having to use GD or ImageMagick?


CSS?

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



Re: [PHP] A black thumbnail.

2006-01-27 Thread Philip Hallstrom

(skip down)


I'm trying to create a thumbnail from a jpeg stored in a long blob in mySQL.
What's wrong here? I get an image that's the correct size, but it's black.

Any ideas?

code

$dbQuery = SELECT image_type, image, image_width, image_height ;
$dbQuery .= FROM pictures ;
$dbQuery .= WHERE image_Id = $pic_id;
$result = mysql_query($dbQuery) or die(Couldn't get file list);

if(mysql_num_rows($result) == 1)
{
$fileType = @mysql_result($result, 0, image_type);
$fileContent = @mysql_result($result, 0, image);
$width_orig = @mysql_result($result, 0, image_width);
$height_orig = @mysql_result($result, 0, image_height);

// Set a maximum height and width
$width = 200;
$height = 200;

if ($width  ($width_orig  $height_orig))
  {
  $width = ($height / $height_orig) * $width_orig;
  }
else
  {
  $height = ($width / $width_orig) * $height_orig;
  }

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($fileContent);


imagecreatefromjpeg takes a *filename* not the actual contents of the file 
itself.  So $image is going to be invalid so your next command isn't going 
to do what you think which means you're going to get black as that's 
probably the first/default color of $image_p.


-philip


imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, 
$width_orig, $height_orig);


// Output
imagejpeg($image_p, null, 100);
}

/code
--

http://sperling.com/

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




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



Re: [PHP] header WWW-Authenticate Question

2006-01-26 Thread Philip Hallstrom

I have been looking for this in several areas and I can't seem to find it.
I'm new to PHP (any programming since FORTRAN, really :) so please forgive
my ignorance.

I am trying to send username/password credentials to a web server using a
PHP script.  This is done to automatically log into a web camera from my
workstation.  I don't know if the header www-authenticate option is the
correct one (or if it's even possible) to use for this.


Depending on what you're doing it might be as easy as:

http://user:[EMAIL PROTECTED]/path?query=string

If all you need to do is suck down a page that would do it.  If your 
POSTING check the HTTP RFC for what headers to send...


-philip

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



Re: [PHP] Get timestamp?

2006-01-25 Thread Philip Hallstrom

How would I go about getting the timestamp of a day of the week from 7 weeks
ago?

In my case I'm getting the timestamp of last Sunday (no matter what day of
the week it is currently) and I want to get the timestamp of the Sunday that
happened 7 weeks ago.

$lastSunday = strtotime(last Sunday);
$Sunday7Weeks = $lastSunday - ???;


$Sunday7Weeks = $lastSunday - 86400 * 7 * 7; // 86400 seconds in a day

-philip

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



Re: [PHP] Get text from funky url?

2006-01-20 Thread Philip Hallstrom

I am trying to get xml from AIM's new presence API.

The url is unusual, it has quotes in it.

Anyone know a way to get the text from this?

http://api.oscar.aol.com/SOA/key=PandorasBoxGoodUntilJan2006/resource-lists/
users/*anonymous*/presence/~~/resource-lists/list[name=\users\]/[EMAIL 
PROTECTED]
=\user:screenname\]

Insert your own screen name to see what it returns

I tried include(); but the quotes in the url broke it. Tried escaping them
too, still no luck.???


Why can't you wrap it up in single quotes?

-p

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



Re: [PHP] Speed

2006-01-11 Thread Philip Hallstrom

Assume that I save data about an object and it has 10.000 observations of
the object stored in a MySQL database. I want calculate the average value of
a column, is it faster done by using PHP on the result array or using the
MySQL function to do that?


MySQL.

You don't have to transfer all 10,000 records to PHP for one thing.

-philip

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



Re: [PHP] Reading large files via PHP?

2006-01-11 Thread Philip Hallstrom
I'm reading in a 66MB file into php so I can parse it and load it into a 
database.  However, it is taking a long time for php to read the file. 
So long that the script times out.  I know about the 
ini_set(max_execution_time, 120) or whatever length I want to set the 
time out for the script, but my question is as follows.


Is it possible to read in a file and at the same time echo out a status 
of how far along the file has been read?


The code I have right now is below.  Just wondering if what I'm trying 
to do is possible and how to do it.


// set script timeout
ini_set(max_execution_time, 120);

// import file name
$log_file_name = access_log.1;
echo Reading access log!br/;
if (!$ac_arr = file(./$log_file_name)) {
echo Couldn't load access log!;
die;
}

Thanks!


Even if you get around the execution time the above code is going to use 
up 66megs of memory to store that file in $ac_arr.


You'd be much better off doing something like:

$fd = fopen(./$log_file_name, r);

while ( !feof($fd) ) {
$buf = fread($fd, 32768);
// process buffer here
}
fclose($fd);

That will let you do your progress thing as well as not eat up so much 
memory.  Play around with values of 32768 to see if smaller or larger 
makes any different on your system.


Good luck!

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



RE: [PHP] Reading large files via PHP?

2006-01-11 Thread Philip Hallstrom

I'm reading in a 66MB file into php so I can parse it and load it into a
database.  However, it is taking a long time for php to read the file.
So long that the script times out.  I know about the
ini_set(max_execution_time, 120) or whatever length I want to set the
time out for the script, but my question is as follows.

Is it possible to read in a file and at the same time echo out a status
of how far along the file has been read?

The code I have right now is below.  Just wondering if what I'm trying
to do is possible and how to do it.

// set script timeout
ini_set(max_execution_time, 120);

// import file name
$log_file_name = access_log.1;
echo Reading access log!br/;
if (!$ac_arr = file(./$log_file_name)) {
echo Couldn't load access log!;
die;
}

Thanks!


Even if you get around the execution time the above code is going to use
up 66megs of memory to store that file in $ac_arr.

You'd be much better off doing something like:

$fd = fopen(./$log_file_name, r);

while ( !feof($fd) ) {
$buf = fread($fd, 32768);
// process buffer here
}
fclose($fd);

That will let you do your progress thing as well as not eat up so much
memory.  Play around with values of 32768 to see if smaller or larger
makes any different on your system.

Good luck!


Ahhh.. Okay that's very cool and I did not know that.  I knew that it 
was chewing up a lot of memory reading it all at once.


I guess the only thing I have to worry about now is if I do a read like 
that will it truncate a whole line instead of getting the whole line? 
The reason why I ask is that if possible I would rather have it read 
line by line for X lines and then process that buffer then go and grab 
more lines until end of file.  Is that possible?


Sure.  If it's a text file you could do something like this:

$i = 0;
$buf = ;
while ( !feof($fd) ) {
$buf .= fgets($fd);
if ( $i++ % 10 == 0 ) {
// process buf here
$buf = ;
}
}

Or you could turn buf into an array with $buf[] = fgets($fd) if that's 
easier...


All kinds of options :)

-philip

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



Re: [PHP] Re: array of checkbox values

2006-01-11 Thread Philip Hallstrom

Would it be enough to set a key for each checkbox, for example explicitly
say:
checkbox[1]
checkbox[2]
checkbox[3]
then a non checked box will have an empty string as a value, whereas the
checked ones will have a value of 'Y'.


Nope.  That's the problem.  If a checkbox is unchecked the browser doesn't 
need to send it all when it submits the server...


an example: 
http://www.pjkh.com/~philip/test/check.php




Sjef

David Dorward [EMAIL PROTECTED] schreef in bericht
news:[EMAIL PROTECTED]

Sjef Janssen wrote:


I have a form with a number of checkboxes grouped together. The value of
these boxes is stored in an array: $used[]. Now I found that the value of
checked boxes (value = 'Y') are stored in the array while non checked
boxes are not stored at all. This makes the array incomplete as I want to
have all checkbox values in the array.


That's how HTML forms work. The general solution is to set the value of
the
checkbox to describe what the checkbox is (for example, the row id of the
database record that the checkbox is associated with). Then you can loop
through and see which values were submitted.

--
David Dorward   http://blog.dorward.me.uk/   http://dorward.me.uk/
Home is where the ~/.bashrc is


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




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



Re: [PHP] Executing a string

2006-01-09 Thread Philip Hallstrom

If I have

$myStr = $a * $b;

and I pass it as an argument

$result = myFunction($myStr);

function myFunction($var) {
 $a = getData(1);
 $b = getData(2);

 return // Use $var
}

Is there a way to use $var to process $a and $b?


http://us2.php.net/eval

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



Re: [PHP] Strange problem with overlapping names

2006-01-06 Thread Philip Hallstrom

the page shown below works fine on my own machine, but on another (remote)
server, it gives me a strange result.

Here's what happens: The first time I view the page it says array(0) { }
as I'd expect, but on the second it says object(kurv)(0) { } where I
expected another array. The problem seems to be that the object has the
same name as the key in $_SESSION -- if I call it $foobar the problem
disappears. But that explanation doesn't really make much sense to me.

As I see it there's something wrong on the server. Can anybody tell me
anything about this problem?


Compare the output of phpinfo() on your machine with the output on the 
server.  Look at any differences.


BTW - the script works fine on my server.

-philip

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



Re: [PHP] web app in my portflio

2005-12-29 Thread Philip Hallstrom
I have a web application I've just completed, and I want to present it as 
part of my online portfolio, most of which hi-lights my work as a front end 
developer. My question is this: How do I go about showing off all of the 
hard-work I've done on the back-end? Do I simply describe the structure of 
the program, or should I present the ERD, code samples, screen-shots, etc? Is 
there such a thing as a code portfolio ? Does anyone have examples of their 
own work to share? Thanks.


First... be careful if it's your employers application.  They might not 
want their database schema posted for the world to see.  If that's not an 
issue then...


I'd write up an overview document.  Include some screenshots.  Basically a 
resume for your app.  Make it long enough so it's clear that it's complex 
and clear what you did, but short enough so that the person can understand 
what it is the app does and what you did.


If you can, host a private copy of the application for demoing purposes 
that you can show on a case by case basis.


And if you're releasing the code, by all means post it (tgz or zip) so 
those curious can glance through it...


-philip

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



Re: [PHP] Filtering URLs problem..

2005-12-20 Thread Philip Hallstrom
I'm writing a filter/parsing function for texts entered by users, and I've 
run into a problem...
What I'm trying to do is to parse URLs of different sorts, ftp, http, mms, 
irc etc and format them as links, that part was real easy..


The hard part is when a user has already entered a complete link..
In short:

http://www.server.tld/page.html
should be converted to:
a href='http://www.server.tld/page.html'http://www.server.tld/page.html/a

That part works fine, but if the user enters:

a href='http://www.server.tld/page.html'click here/a

it all becomes a mess...  Can somebody please make a suggestion on this?


Skip anything inside  tags... then you're last line would come through 
completely unchanged...


-philip

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



Re: [PHP] duplicate filenames but different .extention

2005-12-18 Thread Philip Hallstrom

hello again
I am trying to figure out how i can read the list of files in a directory 
using the opendir() and readdir() functions.  Normally this goes fine but 
within the loop, what i am wanting to do is echo the filename if it is a jpg 
file, but if its a .gif, just continue.

I have several files i wish to seperate based on the basename of the file.
i read the basename help file and know how to use it even to exclude the 
.3letterextention.  I am however wanting to skip if it happens to be a .gif, 
is there some sort of way to i guess, do the basename function in reverse, 
e.g if it comes across xx.gif it would skip it but not skip over the 
xxx.jpg files?
that is my latest problem, it skips everything when i have a line like this 
in my loop


if($file = basename('.gif',$file))
continue;
else go on with code



if ( ereg(\.gif$, $file) ) {
continue;
}

would do it.. so would

if ( substr($file, -4) == .gif ) {
continue;
}

Don't forget about .GIF though if that might be an issue for you...

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



Re: [PHP] Is it possible to use header() to POST form data?

2005-12-15 Thread Philip Hallstrom

Does anyone know if it's possible to use the
header() function to POST form data to a URL?

If so what syntax needs to be used?


No, but a quick search for HTTP POST PHP example will get you the code 
you need.


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



Re: [PHP] Accessing photos outside the web folder

2005-12-10 Thread Philip Hallstrom
I'm writing a content management application which saves file paths in a 
database and allows users to search the database for those files. Problem I'm 
having is that although the PHP script that handles the database queries 
works fine, when the search results get to the browser, all the paths are off 
limits.


I can't just move the photos inside the web folder as we're talking tens of 
thousands of images that are already organized into a folder structure that 
must be maintained as is.


Is there a way to allow the web page to see these photos?

The images are stored on a Windows box and all the web server stuff is on a 
G5 Macintosh running OS 10.4 3 (in case that has any bearing on the matter).


Depending on security issues you have two options.

Put a webserver on the Windows box and modify your search results to link 
to the images using something like this:


img src=http://windowsbox/getimage.php?path=/path/to/img.jpg;

Then put a getimage.php script on the windows box that does something 
like:


?php
 readfile($_GET[path]);
?

If you can't (or don't want to) put the windows box on the internet, then 
still do the above and then also do the same on the mac.  Assuming the mac 
can get to the windows box.  If that mac can't, then you're hosed.


good luck

-philip

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



Re: [PHP] Re: Server Client Architecture, best parctice

2005-11-19 Thread Philip Hallstrom
Reading this, a question arose me: is it possible to read a shared memory 
area with php, supposing than both programs are in the same machine? does php 
support ipc? that would be greatly useful.



yes.

http://us3.php.net/manual/en/ref.sem.php




Mariano.



James Benson wrote:

Each has its own benefits, if on a shared server then a database would be 
the most secure I think, if its a dedicated server then tmpfs or just plain 
old files will probably be the best, it also depends on various other 
factors like, server hardware and bandwith, only you can select the best 
option for your particular setup.



James





Yaswanth Narvaneni wrote:


Hi!

I would like to know what does the community think of the best
architecture for server client communication and why? That is, if
there is a server in C++ (say a game server) and the PHP has to 'read'
data 'from' the server then what is the best form of communication?

a) Shared Memory : Server opens the shared memory in write and the PHP
scripts open it in read and gets the data
b) TMPFS (just like shared memory): Server opens a file in tmpfs in
write and PHP in read
c) Databases: Server Updates a table in the DB and client reads from the 
table

d) Files: Same as TMPFS

Regards,
Yaswanth

--
In theory there is no difference between theory and practice.
In practice there is. -- Fortune Cookie







--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.3/173 - Release Date: 16/11/2005

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



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



Re: [PHP] PHP Search Engine

2005-11-08 Thread Philip Hallstrom

HI All,

Has anyone on here created a search engine in PHP?

I have project to create a search engine that will search about 50K or
so pages of information on 100 or so various domain names.

What have you all done in the past?  PHPdig was a failure.

Do you recommend any of the ones that are for sale?


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

don't know much about it though...

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



Re: [PHP] proc_open, fwrite, 16384 bytes magic

2005-11-03 Thread Philip Hallstrom

Sorry, as a follow-up, I just realized that from 'cat' I AM finally getting an
error in the log file, which will perhaps help trace the issue:

cat: stdout: Broken pipe


Could be wrong, but I think you're getting that error because you are 
closing $pipes[0] which well, closes the pipe and results in a broken 
pipe.  Maybe... maybe not.


Anyway, on FreeBSD 5.4 running CLI PHP 5.0.5 with your previously sent 
script I get output of:


10240
10240

anyway, thought that might be helpful...





  The output is:
10240
  6144
  which makes up exactly the magic 16384 bytes. So it's certainly not a
qmail issue.


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



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



Re: [PHP] Small regex help?

2005-10-12 Thread Philip Hallstrom

Can anyone suggest the correct regex to replace col1,col2... with count(*)
and strip out everything just before ORDER BY?

so for this:
SELECT col1,col2... FROM tbl WHERE filter1 filter2 ORDER BY order1,order2

I would get this:
SELECT count(*) FROM tbl WHERE filter1 filter2


$str = SELECT col1,col2... FROM tbl WHERE filter1 filter2 ORDER BY 
order1,order2;

$str = ereg_replace(^SELECT .* FROM (.*) ORDER BY .*,
SELECT COUNT(*) FROM \\1, $str);

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



Re: [PHP] storing passwords in $_SESSION

2005-10-10 Thread Philip Hallstrom

How secure is it to save a password in $_SESSION.

i.e. $_SESSION['password']

is it safe and is it practical?


Probably not.  If you're on a shared server, I could write a PHP script to 
look in /tmp and read the contents of every session file there...


-philip

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



Re: [PHP] user admin/site admin open source functions..

2005-10-10 Thread Philip Hallstrom

i'm trying to find an open source app that would provide me with user
admin/site admin functionality. i've been playing with a few of the open
source cms apps to get a feel for how they implement this kind of
funtionality. i could rip out what i need, but it might be painful for
something like mambo, given it's interconectivity.

anybody have pointers to an app that you can use as a user admin/site admin
function and tie it into a website/app...


Try here for a lot of CMS packages some of which might be easier to modify 
or some which might do exactly what you want...


http://www.opensourcecms.com/

And check zend.com in their dev section for apps/scripts under the 
content management section.


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



RE: [PHP] Dynamic sub directory listing without redirect

2005-10-08 Thread Philip Hallstrom

Hi List,

I am trying to allow dynamic URL's for my users to remember
similiar to:

www.mysite.com/joesoap

So I want to use joesoap in a PHP script to pick up the
user's details
from a MySQL database. If the joesoap does not exist in the table
I will handle that.

So basically I have one file www.mysite.com/index.php which should do
all the processing.

I have tried with the apache .htaccess mod_rewrite, however
when I echo
$_SERVER['PHP_SELF'] I can't detect the joesoap. It returns
/index.php.

Of course the easiest way is to do something like
www.mysite.com/index.php?username=joesoap
but that is too long and complicated for our users. As we
have thousands
of users, I don't want to create actual directories.

Furthermore can this be done too (without a joesoap file):
www.mysite.com/joesoap?show_extra_details=yes

Any advice/links would be much appreciated. If I am barking
up the wrong
tree throw me a bone please.

Thanks alot
Terence


Hi Terence,

I would handle this in a custom 404 error script.  Essentially, just have
the 404 page parse out the joesoap, check the database to see if its
valid, and act accordingly.


The only drawback to this is that the request won't appear in the access 
log.  At least under apache it won't.


Now if that matter to you or not is another issue...

-philip

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



Re: [PHP] Dynamic sub directory listing without redirect

2005-10-07 Thread Philip Hallstrom

Hi List,

I am trying to allow dynamic URL's for my users to remember similiar to:

www.mysite.com/joesoap

So I want to use joesoap in a PHP script to pick up the user's details from 
a MySQL database. If the joesoap does not exist in the table

I will handle that.

So basically I have one file www.mysite.com/index.php which should do all the 
processing.


I have tried with the apache .htaccess mod_rewrite, however when I echo 
$_SERVER['PHP_SELF'] I can't detect the joesoap. It returns /index.php.


Of course the easiest way is to do something like
www.mysite.com/index.php?username=joesoap
but that is too long and complicated for our users. As we have thousands of 
users, I don't want to create actual directories.


Furthermore can this be done too (without a joesoap file):
www.mysite.com/joesoap?show_extra_details=yes

Any advice/links would be much appreciated. If I am barking up the wrong tree 
throw me a bone please.


If you are using apache, add this to your VirtualHost section for 
www.mysite.com:


  ForceType  application/x-httpd-php
  Action application/x-httpd-php /script-to-handle-every-request.php

Then in your document root, put a file named 
script-to-handle-every-request.php and do whatever you want.


You'll probably want to start by looking at $_SERVER[PATH_INFO] and go 
from there.


I do this to make urls easier to remember for our sales guys so they don't 
have to remember that www.mysite.com:8001 is their sales demo site. 
Instead they can remember salesdemo.mysite.com/philip and it redirects 
them.


good luck!

-philip

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



Re: [PHP] Handling competing edits in a wiki engine?

2005-10-03 Thread Philip Hallstrom

I've recently been working on building my own wiki engine for my blog
site. While the majority of the engine is complete, a remaining concern
I have is how to handle competing edits (ie when two or more people are
editing the same wiki page simultaneously).

I'm wondering if anyone else on the list has given this some thought?
How would / do you handle competing edits to the same entry in a wiki
application?

Just to add a little extra information: all 'edits' are in fact
'inserts'. Entries are stored in a mysql table. The engine simply
displays the most recent record for the entry being viewed. This is, of
course, to allow for retrieval of an historical version of the entry
should one or more entries be vandalized.


Seems like you have a couple of choices.

1 - Lock the page when the first user edits it until they save their 
changes.  Has the advantage that it's pretty easy code-wise.  The 
disadvantage being that if that first user leaves, but doesn't save/cancel 
his edit, how/when do you decide to release lock?  This would be similar 
to how Visual Source Safe or RCS does it.


2 - Allow shared edits and programatically merge the changes back into the 
master document.  This is how CVS does it.  So you could do something like 
this:


- user A starts editing document.

- user B starts editing document.

- user A saves his changes.  this copy is now the most recent as the 
system would check to see that no changes were made to the master copy 
while user A was making changes.


- user B saves his changes.  the system would see that the master copy 
had been updated and would merge the changes into B's copy and save that.


In this last step you could do it a couple of different ways.

When user B saves his changes, the system could create a diff file between 
the most recent version of the document and the one that was the basis for 
B's changes -- this would be the changes user A made.  Then you could 
merge those changes into B's document.   If there was a conflict (ie. user 
A and user B made changes to the same line) user B would have to resolve 
the differences.  This is exactly how CVS handles it.


Or, you could just create a diff file and make user B manually apply the 
patch until he's happy.


If you have access to a unix box take a look at the 'diff' and 'patch' 
commands...


good luck!

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



Re: [PHP] Sanitize paths

2005-10-02 Thread Philip Hallstrom

realpath() is your friend...


That has been my first impression too, but...


realpath() expands all symbolic links


I am actually using symlinks :)

I trust the files on my server so local redirects via symlinks are no
problem, the user submitted data is.


Then realpath() your doc root as well and then you'll be comparing apples 
to apples...


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



Re: [PHP] Sanitize paths

2005-10-01 Thread Philip Hallstrom

I'm working on a script which basically loads an image, the user
requested and wonder how to properly sanitize the passed path. For
instance the user should never ever be able to do somtehing
like ?load=../../../etc/passwd.

My approach so far is to simply urldecode() the given string and return
an error if .. is found in it. Maybe I'm a little paranoid but is this
really enough?

For clarification: All paths are prefixed with some kind of a root path.
All images within this root path may be accessed but jumping out of it
should not be allowed.


realpath() is your friend... prepend your root path to the passed in 
string, then run that through realpath, then verify that your root path is 
still prepended...


http://us2.php.net/realpath

realpath() expands all symbolic links and resolves references to '/./', 
'/../' and extra '/' characters in the input path and return the 
canonicalized absolute pathname. The resulting path will have no symbolic 
link, '/./' or '/../' components.


realpath() returns FALSE on failure, e.g. if the file does not exist. On 
BSD systems realpath() doesn't fail if only the last path component 
doesn't exist, while other systems will return FALSE.


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



Re: [PHP] Regex Help

2005-09-28 Thread Philip Hallstrom

Hi, folks.   I'm having trouble with a simple regex.  I'm sure it's just
something small that I'm missing but nothing I'm trying is working.

In an HTML file I have comments like this:

!-- START PRINT --
various html crap here
!-- END PRINT --

Here's the regex I'm using:

/!-- START PRINT --(.*?)!-- END PRINT --/

And then the call to preg_match_all():

preg_match_all($printable_reg, $str, $out);

It's been quite a while since I've worked with regular expressions so
I'm not sure what the problem is.  The regex isn't throwing errors, it's
just not matching the content located between the start print and end
print comments.

Can anyone lend a hand or give some advice?


I'm thinking that perhaps you want to add the s modifier to your 
pattern...



From http://us2.php.net/manual/en/reference.pcre.pattern.modifiers.php


s (PCRE_DOTALL)

If this modifier is set, a dot metacharacter in the pattern matches 
all characters, including newlines. Without it, newlines are excluded. 
This modifier is equivalent to Perl's /s modifier. A negative class such 
as [^a] always matches a newline character, independent of the setting of 
this modifier.


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



Re: [PHP] split line of text

2005-09-27 Thread Philip Hallstrom

if chunk_split function split the line of text (here on 50 char)
I was wondering if there exists one function who take care if
the 50 char is in the middle of the word and split the line
first empty space before the word or just after?

$newstring = chunk_split($row[1], 50, 'br /');
echo $newstring;


http://us3.php.net/manual/en/function.wordwrap.php

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



Re: [PHP] how to stream a movie file with fread

2005-09-23 Thread Philip Hallstrom

I am trying to stream a movie file with 'fread'
this my first step in trying to dynamically encrypt the file as it is being 
streamed from the server


do I need to fread the data in chunks?
If so, how?

$filename =$path2file;
$file = fopen($filename,'r');
$fileSize = filesize($filename);
$ContentType =  video/quicktime;
header (Content-type: $ContentType);
header (Content-length: $fileSize);

while( $filedata_temp = fread($file, $fileSize) )
echo $filedata_temp;

bFatal error/b:  Allowed memory size of 16777216 bytes exhausted (tried 
to allocate 24113191 bytes) in b/fopenTest.php/b on line 
b27/bbr /


Not knowing exactly what you're trying to accomplish...

I'm guessing that your $filename file is 24113191 in size and that PHP is 
compiled with a memory limit of 16777216.  And since your assigning the 
results of fread() to a variable, PHP is going to try an allocate that for 
you and is failing.


Couple of points..

Why loop if you are reading the entire file at once?  Which is what 
fread($file, $fileSize) is going to do?


Instead perhaps you want this:

while ( !feof($file) ) {
echo fread($file, 32768);
}

(or some other value for 32768...)

That keeps the memory usage down, but does the same thing...

good luck!

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



Re: [PHP] Problem with Internet Explorer when downloading / viewing dynamically generated PDF files

2005-09-22 Thread Philip Hallstrom
I have written a script which dynamically generates PDF documents (with 
PDFlib). The link to the PDF file is presented as a static link (thanks btw 
to Richard Lynch and his previous contributions to this list on the subject 
force download). It is redirected to the script via a htaccess file. If the 
name of the PDF document matches a certain pattern, than the script will 
output the document, if not, a 404 error page will pop up. Everything works 
very well with all kinds of browsers, except Microsoft Explorer (tested with 
Windows Explorer 6 SP1, Internet Explorer 5.2 for Macintosh). And I want to 
know why.


Explorer shows the PDF document as plain text only. Trying to save the linked 
document to the computer (right click) gives something like The server can 
not be reached or the document does not exist.


I know that explorer is a real p.i.t.a. when it comes to all kinds of web 
standards. And my best guess is that this could have to do with headers, or?


A long time ago I helped out a buddy who had a problem with dynamically 
generated PDFs, but only certain ones.  I don't remember all of the 
specifics, but this is what I do remember.


What I remember is that it ended up only being a problem on PDF's that 
were larger than about 1mb -- but only for IE.


We finally figured out that IE was beginning the download of the PDF 
itself, but if it downloaded more than about 1mb, it would pass it off to 
a helper application to do the rest.  The thing was the helper application 
remade the request.  But it wasn't passing along the form parameters used 
to generate the PDF so he was always getting a blank PDF (blank in the 
sense of generically empty).


My memory is that the PDF was the result of a form POST submission and 
that changing it to GET fixed it, but he eventually kept the POST 
submission, generated the PDF, stored it on disk, and redirected to that.


I don't know... maybe that helps, maybe it doesn't...

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



Re: [PHP] Problem with Internet Explorer when downloading / viewing dynamically generated PDF files

2005-09-22 Thread Philip Hallstrom
These were all good suggestions, unfortunately none of them was able to solve 
my problem. I did a rather simple test to eliminate at least some of the 
possible causes. I changed the script in order to do three simple things: 
send a Content-type header, read an existing PDF document into a string, 
output the content and exit.


This is working in Safari, Firefox and many other browsers. Explorer (both 
Mac and Windows) says 'no'! 'The file could not be found' Could it be 
that Explorer in some way don't accept redirects? But redirects are made on 
the webserver, right? I tried to figure out if some header information was


Do you mean Header(Location: )?  Those happen on the *client*.

-philip



send during the redirection. But echoing apache_request_headers and 
apache_response_headers gave no result. So, the question remains: what is 
causing Microsoft Explorer to fail on the download?


Maybe the idea with static links isn't so good after all. I mean, if I do the 
same thing with a usual GET request, even Explorer won't make any trouble. 
But on the other hand, the PDF-generating-thing is supposed to be on an 
other server than the webserver. And I don't like to expose this server to 
the Internet.


Any ideas are still welcome!

/frank

2005-09-22 kl. 18.55 skrev Steve Lefevre:


Philip Hallstrom wrote:



We finally figured out that IE was beginning the download of the PDF 
itself, but if it downloaded more than about 1mb, it would pass it off to 
a helper application to do the rest.  The thing was the helper application 
remade the request.  But it wasn't passing along the form parameters used 
to generate the PDF so he was always getting a blank PDF (blank in the 
sense of generically empty).



If that is what's happening here, I can offer a solution -- I am using ROS 
( www.ros.co.nz/*pdf*/ ) to dynamically generate pdfs, which I first write 
to the server, and then I have just a regular link available to the user. 
That solved a lot of issues for me.


Steve Lefevre

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




- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NIKE HYDRAULICS AB

Frank Arensmeier
Marknadssupport / Webmaster
tel 016 - 16 82 34
fax 016 - 13 93 16

[EMAIL PROTECTED]
www.nikehydraulics.se
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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



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



Re: [PHP] help out a noob w/ include switch?

2005-09-21 Thread Philip Hallstrom

Hi All,
   My very first post to this group as I'm a freshly spanked new born php
baby. Hope I have the correct stop for noob tech questions. Please
re-direct me if I have it wrong. I've been doing web dev for a quite while
with a variety of methods (html, xhtml/css, cfml, flash/as, on and on...).
I work mainly for non-profit organizations and thought it was about time to
get away from commercial software. I'm doing my first site now w/ a
XHTML/CSS template that uses PHP to insert data from a switch container and
from a MySQL db.

My problem occurs only on the server (NT 5 b.2195, PHP 4.3.10, IIS 5.0) but
works great on my dev rig (XAMPP 1.4.15, VectorLinux).

My template index.php uses 'include' to get '$vars' from two files. one
for the body text and title, and the other for the navigation. Click on a
link in the navbar and index.php reloads with the new navbar and the
associated content each into it's div. Works great on my test rig but the
server the site will be hosted from ignores the urlencoded vars and just
loads the switch defaults. For whatever reason I tried return() instead of
break. Again, it worked on my rig but not the server. I know i'm missing
some dumb little thing but I have not figured out what yet. I also tried
session_unset() at the beginning of the index.php in case the problem was
with caching. Didn't work either but may be due to incorrect usage. Any
help or advice is very greatly appreciated!!


I'm guessing that register_globals is set to On on your dev box and Off on 
your NT server.  Check the manual for register_globals along with $_GET.


or if that fails, create a simple phpinfo() page on both servers and 
compare the output to see what settings are different.





jt.

index.php:
?php
   include 'content.php';   //sets the section title
   echo $title;
?
?php
   include 'navigate.php';  //sets appropriate navigation menu
   echo $navigate;
?
?php
   echo $content;   //loads body text
?

content.php:
?php
switch ($cont)
{
   case artist1:
   $title = 'event title';
   $content = 'psome text/p

   psome more text/p

   p class=sig- artist name/p';
   break;
   case artist2,3,4:
   [...]
   break;
   default:
   $title = 'event title';
   $content = 'psome text/p

   psome more text/p

   p class=sig- artist name/p';
   break;
}
?

navigate.php:
?php
switch ($nav)
{
   case 1:
   $navigate = 'ullia 
href=index.php?nav=1amp;cont=artist1Link
titlebr /by artist1/a/lilia
href=index.php?nav=2amp;cont=artist2link titlebr /by
artist2/a/lilia href=some more stuff/a/lilia
href=Contact/a/li/ul';
   break;
   case 2,3,4:
   [...]
   break;
   default:
   $navigate = 'ullia 
href=index.php?nav=1amp;cont=artist1Link
titlebr /by artist1/a/lilia
href=index.php?nav=2amp;cont=artist2link titlebr /by
artist2/a/lilia href=some more stuff/a/lilia
href=Contact/a/li/ul';
   break;
}
?

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



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



RE: [PHP] Re: email validation (no regex)

2005-09-21 Thread Philip Hallstrom

but you could do what you want to do. however, it's going to
be painful if
you want it to match the rfc spec...


Really?  Why does it need to be painful?  I just need to do a 'EHLO', 'Mail
From:' and 'RCPT to:' and 'QUIT'. It's not going to actually send an email.
Seems simple to me.  Maybe there's something else in the spec that I don't
see?


Some mail servers can be configured to not reject the email until the end 
of DATA.  I know you can do this in postfix.


Although if the user is invalid, why you'd wait I don't know, but it is 
possible.


-philip

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



Re: [PHP] comparing dates

2005-09-20 Thread Philip Hallstrom

Is there a quick way to compare dates in the format dd/mm/yy without
exploding and comparing the individual parts?


Compare them in what way?  Before, after, days between?

In any case, i'd look at strtotime() to convert them into timestamps, then 
diff them to get the number of seconds b/n them, then go from there.


If strtotime() won't do it because it expects mm/dd/yy (consider 01/02/05 
is that feb 1st or jan 2nd?) then split up the string and use mktime().


good luck.

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



Re: [PHP] Size limits of mysql

2005-09-14 Thread Philip Hallstrom

I have a simple database with one table with about 6 fields, just
holding filenames, filepaths and sizes.  Very basic audit for management
here.   Problem is I import a load of records into this table and it
seems to only allow me to put in about 550,000 records.Maybe it's
just mysqlFront that can only display that many records or something.
Anybody know of a size or record limit in mysql tables?  The actual size
of the database is about 70Mb.   Not huge really.


I don't know the actual limit, but you are nowhere near hitting it.  Not 
even close...


I suspect it's your mysqlFront app that is having issues.  Or just an 
issue in trying to display 550,000 records at once.


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



RE: [PHP] trying to figure out the best/efficient way to tell who is logged into a site..

2005-09-13 Thread Philip Hallstrom

any code/pointers to this...

i've been doing the google/search thing and haven't come across anything
which relates to what i'm searching for...

so.. any help in this area would be greatly appreciated!!

i would have thought there would be articles/open course code/apps on this!!

-thanks

bruce


http://www.php.net/manual/en/function.session-set-save-handler.php

Also try zend.com in the tips/articles/code-snippets section.




-Original Message-
From: Jason Barnett [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 13, 2005 2:25 PM
Cc: php-general@lists.php.net
Subject: Re: [PHP] trying to figure out the best/efficient way to tell
who is logged into a site..


Close: You mix both of these ideas.

Create a custom session handler. This handler creates user entries in a
database. Then when you want to know how many are online you do a count on
the number of user entries in the table. Play around with different
gc_probability values to tune the efficiency.



On 9/13/05, bruce [EMAIL PROTECTED] wrote:


hi...

anybody have pointers to trying to tell who/how long someone is logged
into
a system/site. i've thought about setting a session var, but i'm not sure
how to read/tabulate this var across the entire group of people who'd be
logged in. i've also thought about keeping track in a db tbl.. however,
i'm
still not sure that i've got a good way of tracking who's logged in, and
still on...

a possible approach would be to have the app periodically update the
system
whenever a logged in user goes from page to page...

so, any thoughts/ideas/etc...

-thanks

bruce
[EMAIL PROTECTED]

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




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



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



Re: [PHP] incrementing in a for loop

2005-09-12 Thread Philip Hallstrom
I've searched online and am unable to find how to increment by more than 
one in a for loop.


for ($i = 1; $i = 6; $i++) {

Is it possible to increment $i by 5?


Sure.

for ($i = 1; $i = 6; $i+=5) {

-philip

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



Re: [PHP] How large string in cookie?

2005-09-08 Thread Philip Hallstrom

How large can a string be in a cookie? (the value-parameter)


According to here: http://wp.netscape.com/newsref/std/cookie_spec.html

There are limitations on the number of cookies that a client can store at 
any one time. This is a specification of the minimum number of cookies 
that a client should be prepared to receive and store.


* 300 total cookies
* 4 kilobytes per cookie, where the name and the OPAQUE_STRING combine 
to form the 4 kilobyte limit.
* 20 cookies per server or domain. (note that completely specified 
hosts and domains are treated as separate entities and have a 20 cookie 
limitation for each, not combined)


Servers should not expect clients to be able to exceed these limits. When 
the 300 cookie limit or the 20 cookie per server limit is exceeded, 
clients should delete the least recently used cookie. When a cookie larger 
than 4 kilobytes is encountered the cookie should be trimmed to fit, but 
the name should remain intact as long as it is less than 4 kilobytes.


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



Re: [PHP] Inserting records question

2005-09-08 Thread Philip Hallstrom

Still learning, so sorry if this sounds really simply noobish.  But as I
understand things currently this should work.  But doesn't.  I've been
looking over tutorials but just don't see whatever the problem is.

I created a simple table with the following fields (in order)
tc_id (auto nmbr)
lname
fname
machine_name
email_addr
problem
date_time_submitted (timestamp)

And I'm trying to run this insert from form input.

$username=somename;
$password=somepass;
$database=somedb;
$table=sometable;
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die(Unable to Connect to DB);
$tc_query = INSERT INTO $tablel VALUES(NULL, $lname, $fname, 
$machine_name,
$email_addr, $problem, NULL);
$result = mysql_query($tc_query);
mysql_close();

So what exactly do I seem to be missing here?


A lot of single quotes... around the parameters you are inserting...

add in a print($tc_query) and see what that looks like... run that 
directly in mysql and it will give you more details on the error.


Or, make it look like this:

$tc_query = INSERT INTO $tablel VALUES(NULL, '$lname', '$fname', 
'$machine_name', '$email_addr', '$problem', NULL);


I'd also suggest you read this page:

http://www.php.net/mysql_escape_string

good luck!

-p

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



Re: [PHP] Stripping control M character (^M)

2005-09-07 Thread Philip Hallstrom

Hello All,

I'm having some issues with carriage returns. Specifically the control M
character (^M). I have attempted to clean and validate the file I'm
creating. Here's the code.

while ($row = mysql_fetch_array($result)){

   // assign and clean vars
   $artist = trim($row[artist]);
   $tdDate = trim($row[start_date]);
   $venue = trim($row[venue]);
   $city = trim($row[CITY]);
   $state = trim($row[STATE]);
   $country = trim($row[COUNTRY]);
   $tdId = trim($row[td_id]);

   // create string

   $line = $artist|||$tdDate||$venue|$city|$state|$country|$tdId\n;

   // validate the string

  if(preg_match(/.*.|||.*.||.*.|.*.|.*.|.*.|.*.n\//, $line)){
  // record is correct so write line to file
  fwrite($handle,$line);
  }
}


So ^M slips right by trim and my preg_match line.


Where is the carriage return appearing in your line of output?  Trim 
will remove these, but only at the beginning/end of a string so if $artist 
= Paul\rNowosielski that won't get cleaned up...


Maybe run them through ereg_replace() using [\n\r] as a pattern?

-philip

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



Re: [PHP] regular expression for integer range

2005-09-06 Thread Philip Hallstrom




On Tue, 6 Sep 2005, babu wrote:


Hi all,


I want to write regular expression for checking the string format entered by 
user.

the allowed formats are

examples:
10
10,
10,12-10
12-10

that is the valid strings are:
1. only integer
2. an integer, range of integers example 3

and no other characters must be allowed.


ereg(^[-0-9,]+$...

would do it, but it would also allow 10,- as a valid expression as 
well.. so if you want to check for valid ranges you'll want to beef that 
up a bit...


-philip

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



Re: [PHP] Re: php equivalent for cut

2005-09-06 Thread Philip Hallstrom

I am searching for the right equivalent for cut -d : -f5
but it must work with php4.


$fields = explode(':', $string, 5);


Hmmm.. that's going to create a 5 element array assigned to $fields.  So, 
using /etc/passwd as an example...


philip:*:1000:1000:Philip Hallstrom:/local/home/philip:/bin/tcsh

$fields is going to look like this:

0 = philip
1 = *
2 = 1000
3 = 1000
4 = Philip Hallstrom:/local/home/philip:/bin/tcsh

I think what he really wants is:

$fields = explode(':', $string);
$fullname = $fields[4]; // Philip Hallstrom


-philip

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



Re: [PHP] Re: php equivalent for cut

2005-09-06 Thread Philip Hallstrom

Am 2005-09-06 12:18:18, schrieb [EMAIL PROTECTED]:


$etcpasswd = username:passwd:123:345::/home/username:/bin/sh;
$pwdarr = explode(:, $etcpasswd);
echo $pwdarr[4];


OK, this works now.

But can I read a whome /etc/passwd into an 3d array ?
This would avoid multiple reads...

I know, that I can have a file as array with file() but
whats the best solution to put it into 3D style ?

I need only to extract the $USER, $GEKO and $HOMEDIR for
UID = 1000.


Why not use posix_getpwuid()?

http://us2.php.net/manual/en/function.posix-getpwuid.php

-philip

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



Re: [PHP] Session expires randomly

2005-09-06 Thread Philip Hallstrom



On Tue, 6 Sep 2005, Mauricio Pellegrini wrote:


You were right! That was exactly the problem
after reading your message, I 've verified the value for gc_maxlifetime
and found that it was set to 1440 secs in other words 24 minutes.

Thank you for that.

But, now I need to come up with something to avoid this behaviour.

The problem is that there's a second php application ruuning on the same
server and I don't want to change the default for gc_maxlilfetime,



Why not just change it on your pages?  The manual says it can get changed 
anywhere... so just make a call to ini_set() on your pages and other 
scripts will remain unaffected.


?






So I was thinking on implementing some sort of automatic session refresh
after a short period, let's say every 20 minutes of inactivity.

And of course I should provide the users with a manual way to make
session end, sort of a logout from the application.( no problem with
that)

My question is:

 Is there a way to set sort of a timer as to invoke an hipothetical
refresh_session.php without reloading the current page on the client?

Thanks
Mauricio.



On Fri, 2005-09-02 at 14:20, [EMAIL PROTECTED] wrote:

On Fri, 2 Sep 2005, Mauricio Pellegrini wrote:


Hi, I have this problem , When I start a Session everything seems to

be

ok but sometimes with no reason the session vanishes.

All settings are default , I mean session_cache_expire is 180 min.
I understand that this setting should make sessions last for at least

3

hours but in my case it seems not to be true since the real duration
varies from 20 minutes to an hour


I think the parameter you need to look at in php.ini is
session.gc_maxlifetime. It sets the session lifetime, not
session_cache_expire. The default lifetime is probably 1440 seconds,
roughly 20 minutes, so the behavior you are seeing is completely normal -
it's all working as it should.

Kirk


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



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



Re: [PHP] intval() vs. (int)

2005-09-02 Thread Philip Hallstrom

On checking form fields that they are of type int, what is best to use:
intval() or type casting (int)?
In terms of speed, would (int) not be better, because we save a function
call (especially on very large sql statements)?


Time it.

On an 800mhz box doing absolutely nothing else (it's just sitting there, 
honest :) a script which reads 100,000 16byte strings from a testfile 
(composed of a bunch of tar balls put together just to get something 
random) and then doing this:


- loop through array doing $x = $array[$i] just to read it all in once.
- loop through array doing $x = intval($array[$i])
- loop through array doing $x = (int) $array[$i]

yields this (in seconds).

nothing = 0.3619658946991
intval  = 0.60399794578552
(int)   = 0.48065304756165

So, for 100,000 random 16 byte strings you're saving 0.12 seconds or 
0.012 per iteration...


So, it probably doesn't really matter :)

-philip

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



Re: [PHP] Session expires randomly

2005-09-02 Thread Philip Hallstrom

On Fri, 2 Sep 2005, Mauricio Pellegrini wrote:


Hi, I have this problem , When I start a Session everything seems to be
ok but sometimes with no reason the session vanishes.

I'm using PHP 4.3.4 as a Apache module.
Apache version is 1.3 under Suse Linux 8.2

All settings are default , I mean session_cache_expire is 180 min.
I understand that this setting should make sessions last for at least 3
hours but in my case it seems not to be true since the real duration
varies from 20 minutes to an hour

I use session_start()
and then on any routine I verify the existence of certain session
variables.

Is the server expiring the session automatically for some reason?


Just a thought... normal file based sessions are stored in /tmp.  Maybe 
your server has some process that is cleaning out files in /tmp that 
haven't been accessed in X amount of time..


Crazy thought, but maybe that's it...

Try some tests... start a session, load a page, and have the page reload 
itself every minute (being sure to access/modify the session).  Put 
some code in there so as soon as the session goes away it spits out the 
date/time and stops so you can see how long it lasted. Let that run for 
over an hour.  See what happens.


Try another one, but only reload the page every 20-30 minutes or 
something...


good luck!

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



Re: [PHP] session cookies

2005-09-02 Thread Philip Hallstrom



Rasmus Lerdorf wrote:

That's a bit misleading. The HTTP response headers are sent a soon
as you output something from your script (calling header() or
setcookie() doesn't count as output, so you can set all the headers
and cookies you want).


They're sent to Apache, but that doesn't mean anything is necessarily sent to 
the client, right? I guess I should have pointed out that this depends on a 
few things, such as whether the response is sent with:


Transfer-Encoding: chunked

or

Content-Length: ...

Common sense tells me that Apache can't provide a reliable Content-Length 
header until my script completes. :-)


That's true... it can't... and doesn't... at least not all the time...

---
% telnet localhost 8004
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /phpinfo.php HTTP/1.0

HTTP/1.1 200 OK
Date: Fri, 02 Sep 2005 17:12:10 GMT
Server: Apache/1.3.29 (Unix) PHP/4.3.4
X-Powered-By: PHP/4.3.4
Connection: close
Content-Type: text/html

(phpinfo output follows)
---

-philip

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



Re: [PHP] Content - strip...

2005-09-02 Thread Philip Hallstrom

Hi there!

Anyone that has an easy solution to this?

I have a string filled with content. A lot of content is before Jumping Jack 
flash


I want the $content - string to start at Jumping Jack flash

Is there any smart way of doing this?


Use strstr() to find the first occurence of Jumping Jack flash.
Then use substr() to extract from that point to the end of the string into 
a new string.


http://us2.php.net/strstr
http://us2.php.net/substr

-philip

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



Re: [PHP] need information on sending email using php

2005-09-02 Thread Philip Hallstrom

I am new to php.  I am going to be setting up a page that has a form
on it.  When the user clicks on submit an email should be sent with
the contents of the form.  My question is How do I do that?

the webserver that I will be placing this page on has php ver 4.4.0  on it.

Any help would be appreciated


www.php.net/mail

-philip

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



Re: [PHP] Saturdays and Sundays

2005-09-01 Thread Philip Hallstrom

Is it possible to get the number of saturdays and sundays for a given month
/ year?


This seems to work...


?php

$month = 9;
$year = 2005;
$day = 1;

$ts = mktime(0, 0, 0, $month, $day, $year);

$week_day = date(w, $ts); // 0 (for Sunday) through 6 (for Saturday)

if ( $week_day  0  $week_day  6 ) {
$day += 6 - $week_day; // $day = first saturday
}

$ts = mktime(0, 0, 0, $month, $day, $year);
$tmp_month = date(n, $ts); // 1 - 12

while ( $month == $tmp_month ) {
$num_satsuns += 2;
$day += 7;

$ts = mktime(0, 0, 0, $month, $day, $year);
$tmp_month = date(n, $ts); // 1 - 12
}

print(Number of Sat/Suns: $num_satsuns\n);

?

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



Re: [PHP] CookieMonster

2005-09-01 Thread Philip Hallstrom

Simple question I guess..

How do I set a cookie so it will never expire? (I don't want it to expire)


You can't really... I could delete it and that would be the same as 
expiring it...


Best you can do is set it to expire 100 years in the future or some 
such... see the manual for SetCookie() for more info...


-philip

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



Re: [PHP] CookieMonster

2005-09-01 Thread Philip Hallstrom

You can.. Dont include the expire argument.. or set it to 0.


You sure?

The manual says (last sentence):

expire

The time the cookie expires. This is a Unix timestamp so is in number of 
seconds since the epoch. In other words, you'll most likely set this with 
the time() function plus the number of seconds before you want it to 
expire. Or you might use mktime().


time()+60*60*24*30 will set the cookie to expire in 30 days. If not set, 
the cookie will expire at the end of the session (when the browser 
closes).






Jason

On 9/1/05, Philip Hallstrom [EMAIL PROTECTED] wrote:



Simple question I guess..

How do I set a cookie so it will never expire? (I don't want it to

expire)

You can't really... I could delete it and that would be the same as
expiring it...

Best you can do is set it to expire 100 years in the future or some
such... see the manual for SetCookie() for more info...

-philip

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






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



Re: [PHP] Port 443

2005-09-01 Thread Philip Hallstrom

Using an API for an Ecomemrce app. Wondering how I can ensure I have
access to port 443 and that it's open?


use fsockopen() to open a socket connection to the host on port 443.  You 
should at least connect...  if it fails to connect, it's not open...


-philip

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



Re: [PHP] session cookies

2005-09-01 Thread Philip Hallstrom

Is there a way, using PHP, to determine if session cookies are enabled (or
disabled) in the user's browser privacy settings?


Set a cookie using setcookie().

Then use an HTML meta refresh (or javascript, just not 
Header(Location...) to redirect them to another page.


On that page, see if the cookie value is set.

If it is, they have cookies enabled.  If it's not, they don't.

-philip

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



Re: [PHP] session cookies

2005-09-01 Thread Philip Hallstrom

Philip Hallstrom wrote:
Then use an HTML meta refresh (or javascript, just not Header(Location...) 
to redirect them to another page.


Why not header(Location...)? Just out of interest -- it's always worked for 
me, and it's a much better way to redirect users for many reasons[1] (like 
not breaking the back button).


[1] http://www.w3.org/QA/Tips/reback


For some reason (and maybe it's no longer true) I've had problems setting 
a cookie and then doing a header(Location...).  Seems some browsers 
wouldn't pick up the cookie.


Now... when this happened (could have been as early as 98) I don't recall, 
but it's always stuck with me and I usually end up spitting back a little 
javascript to send the user wherever it is I want them to go...


-philip

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



Re: [PHP] String format problem

2005-08-31 Thread Philip Hallstrom

hi
i have a problem when i am formating a string
the problem is it converts the \n in the string to a new line
here is the code

?
$Text = D:\AppServ\www\intranet\admin\store\nodirectory\sub;
$Replace = D:\AppServ\www\intranet\admin\store;
$with = http://localhost/bank/admin/store;;

//$doc = str_replace ($Replace, $with, $Text);
$doc = str_replace( '\\', '/', str_replace( $Replace, $with, $Text ) );

echo $doc;

//i need $Doc to look like this
http://localhost/bank/admin/store/nodirectory/sub
//but it outputs http://localhost/bank/admin/store odirectory/sub


Replace your double quotes with single quotes... that is:

$Text = 'D:\AppServ\www\intranet\admin\store\nodirectory\sub';
$Replace = 'D:\AppServ\www\intranet\admin\store';
$with = 'http://localhost/bank/admin/store';

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



Re: [PHP] weird results from imagettfbbox()

2005-08-31 Thread Philip Hallstrom

I have an array of strings in which I am passing to imagettfbbox() in order
to calculate the height of the text box for each string.  I am then
subtracting the height from the y position in order to deviate the pivot
point form the top left corner to the bottom left corner when I used
imagettftext() to draw the text on an image.  I am giving both commands a
fontsize of 50, an angle of 0 and I am using the font ARIAL.

I am having an issue where the first string comes back with a height of 50
and the next comes back with 47.  Then 50 again for the next following
string and then 47 again for the next one foloowing that.  It keeps going on
and on like this and I do not understand why.  I am using the same font,
font size, and angle for each string so shouldnt they all come back as the
same size?


Is each line of the file the same?  It's going to vary depending on what 
letters are in the string (ascenders and descenders for letters like 
qygpi, etc.).


maybe that's it?



Here's a snippet of what I am doing:

 $file = this can be any file;
 $im = imagecreatefromjpeg($file);

 $textcolor = imagecolorallocate($im, 0, 0, 0);
 $fontfile = arial.ttf;
 $fontsize = 50;

 $arr = split(CR, $_GET['text']);

 $boxes = count($arr);
 if (preg_match('/[0-9]/', $boxes)){
   for($c=0;$c$boxes;$c++){
 $text = stripslashes($arr[$c]);
 $y = $fontsize * $c;
 $bbox = imagettfbbox($fontsize, 0, $fontfile, $text);
 $dy = $bbox[7] - $bbox[1];
 $py = $y-$dy;

 imagettftext($im, $fontsize, 0, 1, $py, $textcolor, $fontfile, $text);
   }
 }

 header(Content-type: image/jpeg);
 imagejpeg($im,  ,95);
 imagedestroy($im);

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



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



Re: [PHP] displaying certain number of character

2005-08-30 Thread Philip Hallstrom

$words= If length is given and is negative,
then that many characters will be omitted from
the end of string (after the start position has
been calculated when a start is negative). If start
denotes a position beyond this truncation, an empty
string will be returned. ;

echo substr($words, 0, 50);
?


I have been using this but how can I make sure I do not split a word in
half? - Finishing on a space would probably do it.


You could use wordwrap() to wrap lines at 50 characters and then just take 
the first line


http://us3.php.net/wordwrap

-philip

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



Re: [PHP] read directory and paginate

2005-08-26 Thread Philip Hallstrom

A little while back there was a post  where someone needed to read all files
(images/thumbs) from a gallery
and paginate them automatically, I cannot find the thread in the archive but
if anybody can point me to the
thread or knows how the poster solved his problemplease reply as i need
something very very close to that
functionality.


Mabye posts 1-8 from here?

http://marc.theaimsgroup.com/?l=php-generalw=2r=1s=previous+%2B+next+buttons%2C+no+DBq=b

-philip

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



Re: [PHP] Sort table by column and pagination

2005-08-26 Thread Philip Hallstrom

We have quite a complex product all written in PHP and our own mySQL
wrapper. We initially wanted to use smarty, but due to time constraints, we
couldn't re-write everything, so it never got implemented.

Two feature requests we get a lot are the ability to sort the tabular data
by column heading (click once for ascending and again for descending) and
the second is pagination.


My guess is finding code that does this that you can integrate is going to 
take longer than just doing it yourself.  It's not that bad...


Just add some variables that either get kept in a session or passed around 
via URL's to store the $offset and $order_by.


Then in your code set your $limit.

Then it's just a matter of adjusting your SQL to add ORDER BY 
$order_by LIMIT $limit OFFSET $offset when relevant.  For your array, 
it's the same thing, but use array_slice.


To go to the next page just have the link set $offset to $offset + $limit. 
Similarly for previous.


Then add the boundary checks, etc.

Good luck!

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



Re: [PHP] PHP vs. ColdFusion

2005-08-24 Thread Philip Hallstrom
It's too bad  you have to use Windows and IIS.  Just curious but why are 
they not wanting to use Linux?  Do they know it's free and way less likely 
to be attacked?


I've made this argument numerous times. Management seemed to be receptive, 
and I thought they were starting to change their Microsoft only attitudes, 
so the statement from my boss that management said it has to run on IIS 
really caught me by surprise.


I think you might be going about this the wrong way...

If I understand this thread correctly, your app *works* on linux/php.  It 
breaks on windows/php.


So it's working, right?

Which is all they should care about, but they don't?

So, write up a little document showing how much time (which equals money) 
you're spending trying to fix something that really isn't broken except in 
the eye's of management.


This thread's been going on for a couple of days now.  Assuming you've 
done nothing else for those several days and I've seen mention of 
discussing it with other engineers and sysadmins...


just how much money has the company spent on this non-problem?

Then since it also seems like you're not that much closer to solving the 
problem, estimate how much additional time it's going to take to fix it.


Then show them the bottom line.  That the company has spent $2,000 so 
far and will probably spend another $3,000 until it's fixed.


Not to mention all your other projects being delayed.  That's another 
$5,000.


Ask them if this is worth spending $10,000 to fix something which isn't 
broken.


Then be sure to tell them you will be happy to revisit the problem when 
there is *nothing else to do*



I've had issues like this.. usually they want to know how long it will 
take to port our application from FreeBSD/PHP/PostgreSQL to 
Windows/ASP/SQLServer and when I tell them at least six months, probably a 
year, they decide maybe it's not worth it to satisfy someones need to say 
yes, we run on windows!


(and yes, I know php,postgresql is available for windows now, but that's 
not the point)


Anyway, might work... then again it might not.  But it changes it from a 
technical discussion to a financial one which is how they think.


good luck!

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



Re: [PHP] parsing useragent string without get_browser

2005-08-24 Thread Philip Hallstrom

I've done a google and can't find anything on this.

I want to parse a long list of useragent strings for a web analysis script I 
am writing. I could use get_browser, but firstly this would slow down my 
script quite a bit and secondly I am relying on the browscap.ini file of the 
newness of which is upto my ISP as I am on shared hosting.  Is there are a 
way of doing this?


I'd like to break down the string into it's componant parts but the 
difference in strings is big. eg-


Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; stumbleupon.com 1.927)

Windows-Media-Player/10.00.00.3650

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 
Firefox/1.0.4


Mozilla/5.0 (compatible; Yahoo! Slurp; 
http://help.yahoo.com/help/us/ysearch/slurp)


Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, 
like Gecko) Safari/312


How do I start with this one?


Depending on your license, take a look at the code for webalyzer or 
awstats or some other package and see how they do it.


-philip

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



Re: [PHP] syntax for two comparison operators

2005-08-24 Thread Philip Hallstrom
Is there a technical reason why PHP does not allow comparison operator 
expressions like the following:


if (2  $x = 4) {}


I prefer this concise way as it is common for mathematics expressions, and 
much easier to grasp physically on first glance. From what I can tell, this 
expression can currently only be written as:


if ( $x  2  $x = 4) {}


I'm sure someone who knows more about it than me will chime in with the 
real reason, but at first glance how would the interpreter interpret it?


Given 2  $x = 4, do you mean:

2  $x  $x = 4

or do you mean

(2  $x) = 4

where 2  $x will evaluate to true or false.  Doesn't make much sense as a 
condition, but it's there...


Also, you could wrap it in a function if you find you use it a lot..

function between($x, $min, $max) {
return( $min  $x  $x  $max );
}

-philip

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



Re: [PHP] Files passing through

2005-08-23 Thread Philip Hallstrom

Benchmark it both ways and see.



I benched this with a 100 MiB text file (largest I could find at short 
notice). Buffer used for fread() calls was 2 KiB as above.


Values are averaged over 100 runs (I would have liked to do more, but I don't 
have time). All values are to 4 significant figures.


Thought it might be interesting to see what happens by changing the buffer 
size using the fread option.  Hacked up your script to run 100 times for a 
variety of buffer sizes reading in a ~100mb file, writing it out to 
/dev/null.  Each iteration would shuffle the buffer size array so that it 
didn't them in various orders (just cause).  This is on a FreeBSD 4.x box 
800mhz, scsi disk, completely idle.  Looks like for my server, 32K is the 
fastest, but it also looks like it really doesn't matter much.  And none 
of this was run through apache which might have an affect since it's going 
to cache data before sending it as well I expect.


BUFSIZE AVERAGE MIN MAX STDEV
10241.161640766 0.750351191 2.089925051 0.343560356
20481.192794297 0.749926805 2.099468946 0.352989462
40961.175014074 0.750481129 2.094204187 0.340703504
81921.191642218 0.750271797 2.103453875 0.342129591
16384   1.179281006 0.750427008 2.103821039 0.294178021
32768   1.112951536 0.750751972 2.096071959 0.280774437
65536   1.121285999 0.750077009 2.084055901 0.281509943
131072  1.223868408 0.750341177 2.114228964 0.376586171
262144  1.195006318 0.750770092 2.094146013 0.307552031
524288  1.247279932 0.75097084  2.878097057 0.405213182
1048576 1.162287986 0.752273083 2.099447012 0.328753411
2097152 1.170556216 0.752089024 2.101628065 0.298650593

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



Re: [PHP] Files passing through

2005-08-22 Thread Philip Hallstrom

What is the fastest way to do this? I know
echo(file_get_contents('myfile')); is not a good idea ;)


Why not?


My guess would be because file_get_contents returns the contents as a 
string.  So if 'myfile' is 100mb, you're going to have to allocate 100mb 
of memory to store that string while echo() spits it back out.


But I'm just guessing as I don't know for sure...

-philip

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



Re: [PHP] Week Days

2005-08-19 Thread Philip Hallstrom

All you need is the mktime() command.

do something like:
$futureDate = date(Y-m-d, mktime(0, 0, 0, $month, $today+
$daysToAdd, $year));

Jordan


http://www.php.net/mktime
mktime() is useful for doing date arithmetic and validation, as it
will automatically calculate the correct value for out-of-range
input. For example, each of the following lines produces the string
Jan-01-1998.

?php
echo date(M-d-Y, mktime(0, 0, 0, 12, 32, 1997));
echo date(M-d-Y, mktime(0, 0, 0, 13, 1, 1997));
echo date(M-d-Y, mktime(0, 0, 0, 1, 1, 1998));
echo date(M-d-Y, mktime(0, 0, 0, 1, 1, 98));
?


All fine and dandy... but he said WEEKDAYS, so adding 5 days to a given
day must non deduct from the 5 days when a weekend day is passed. This
kind of calculation is useful for banks and other businesses that only
process transactions on business days (which happen to be weekdays).


Easy enough to change that date(...mktime(...)) command above to return 
the weekday and while the weekday is a weekend just add a day and repeat.


that would give you the next monday.

Holidays are another matter though, but that could be worked around as 
well via a lookup table...


-philip

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



Re: [PHP] Week Days

2005-08-19 Thread Philip Hallstrom

Easy enough to change that date(...mktime(...)) command above to return
the weekday and while the weekday is a weekend just add a day and repeat.


Actually sorry to post again on the same post, but this is like the
first solution posted and is invalid since it doesn't account for
non-weekdays that fall within the range. It only checks the endpoints of
the addition. For instance adding 50 days would contain about 20 or so
weekend days.


Ah... but you are forgetting the rule I live by... anything that happened 
more than a week ago or is happening more than a week in the future... 
doesn't count, I don't remember, and I can't be held responsible for.


:-)

good catch though.

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



Re: [PHP] Re: previous + next buttons, no DB

2005-08-18 Thread Philip Hallstrom

Ashley,

How are you creating the gallery page? You must be reading the filenames in 
the directory and producing an img for each one. Can you create an array 
of those filenames, save it to session (or generate it each time),   and 
iterate through them?



  Say the images are in a folder called /gallery/

  Within that, I have an index.php that is manually coded to have thumbnails 
of the images displayed in a grid.  Important to note: they're in a very 
specific (artistic) order.  Each one of those thumbnails is linked to one and 
the same popup.php file that is simply another php file that expects an $ID 
passed to it.  That $ID, which again is hard coded in index.html, tells 
popup.php which file to display.  (that $ID is basically the file name of the 
image, so I can append it to the img / tag as the page loads.


  So you see, I have no array of anything.  The index.html file gets 
manually edited every time something is added or removed.  This is why I'd 
like a programmatic way of a) generating that file, so that the client can 
add/remove images as they see fit, and b) be able to have prev/next buttons 
on the popup window.


Change it.  Remove all the hardcodings from index.html.  Instead create 
another data file that contains the list of images (and the order) you 
want them displayed.  Easier for you if that file is a PHP file that looks 
something like:


$img_array = array(
img1,
img3,
img2,
);

But it could just as easily look like this:

img1
img3
img2

Note that I'm only putting in the basename of the image, not the full 
name.  Hopefully you can determine the path to the thumbnail and full 
image from this basename.


If you can't make it look like this:

img1thumb.jpg img1.jpg
...

Then turn your index.html into a index.php file that includes (or 
processes) this data file.  Now you've got an array you can loop through 
to display the thumbnails.


Change your popup.php page to read that data file in as well.  And now you 
can loop through it to find the image you're viewing.  Keep track of a 
counter and if that counter is greater than zero, display a previous link. 
If it's less then the total count of the array minus one, display a next 
link.


I'd take it a step further still and have each separate index.php include 
a master index.php (same for popup.php) so that the only thing a specific 
directories index.php contains is:


include_once(/path/to/master/index.php);

That way you can make global code changes without touching all the files.

Good luck!

-philip

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



Re: [PHP] one more mysql question

2005-08-12 Thread Philip Hallstrom
I apology for mysql question posted here, but, as I said once, I like you 
guys more! :)


have two tables: orders and special_orders. foreign key is trans_no.
I can't figure it out how to create a query that pulls orders from the 
orders tables that are NOT in special_orders table?


I can never remember the syntax, but you want to LEFT JOIN the tables and 
then only return rows where the resulting special_orders column is NULL.


something like this (most likely wrong syntax):

SELECT o.trans_no, s.trans_no FROM orders o LEFT JOIN special_orders s ON 
o.trans_no = s.trans_no WHERE s.trans_no IS NULL


But that should get you started...

-philip

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



Re: [PHP] Re: possible bug (string equality to zero)?

2005-08-11 Thread Philip Hallstrom

No, Christopher, that is not a bug. As long as the var is empty, and if
you try to compare with 0, or false, it will report true in the
comparison because the variable does not contain anything, which will
mean false for a boolean and 0 for a variable. If you are attempting to
discover if a string contains data, use empty() instead. You can also
check if the string is null or actual zero (0).


But the var isn't empty.

$a[] = 'blah';
$a[] = 'blah';
$a['assoc'] = 'array';
foreach ($a as $k = $v)
 if ($k == 'assoc')
   # do something

The 'if' statement is incorrectly executing when $k is 0.  I find it strange
that 0 == any string.  The way I see it, 0 is false.  false == 'a string'
should not be true.



You might try === instead of == to get type checking as well...

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



Re: [PHP] Blatantly Evil Question

2005-08-11 Thread Philip Hallstrom

robots.txt will not do what you want it to.

Just sniff for those robots' User-Agents (Google, MSN and Yahoo all publish 
their UA strings on their websites, AFAIK) and send different content if 
it's one of those.


they will hammer you for it eventually - AFAICT all major SEs send out their
spiders occasionally with faked user-agent strings - to catch out crap like
this.


google adsense won't.  I explicity asked them about this.  Well, what I 
asked was that if I had a password protected area, could I allow them 
access to spider the content so that normal users could see the ads.  I 
told them the layout would be different, but the content the same.


They said that was fine.

2cents.

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



Re: [PHP] graph - dowloads/hr

2005-08-09 Thread Philip Hallstrom
i'd like to create a graph with the amount of downloads per hour, i am a 
little confused how i should go about this.


i know i can use rrdtool/mrtg, but im looking for more 'user friendly' graphs 
with custom colors,etc.


each time someone downloads a file it is incremented in the db and the last 
time the file was downloaded. i am unsure about the data i would need to 
store to create and if what i am storing is enough to do this.  any 
suggestions or tools that already exists to create this types of graph?


jpgraph can do it... as can a lot of other graph/chart libraries...

http://www.aditus.nu/jpgraph/

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



  1   2   3   4   5   >