Re: [PHP] zip code validation/regular expression

2003-06-03 Thread CPT John W. Holmes
> Simply trying to use regular expressions to validate a 5 or 5+4 zip code,
> excluding 0 and 0-.  Looked on http://www.regexlib.com, and
> that's where I found the pattern below, but it doesn't work.  The best I
can
> do on my own is two separate regular expressions, one to match a valid
zip,
> and another to match the 0 invalid code.  I would really like to
> condense it into one, just because I think it should be possible.
> This code below is suppose to do all this for me, but it's not matching as
> I'd hoped.  I get results like this:
>
> 21832-1234 MATCHES.
> 0- MATCHES.
> 0 MATCHES.
> 1234 doesn't match.
> ABCDEF doesn't match.
> ABC doesn't match.
>
> I'd appreciate any help.  Thanks,
> jason
>
> 
> $regex1 = "/^(\?(^0(|-))|(\d{5}(|-\d{4})))$/";
>
> $zips =
> array("21243","21832-1234","0-","0","1234","ABCDEF","ABC");
>
> foreach ($zips as $zip) {
> if (preg_match($regex1,$zip)) {
> echo "$zip MATCHES.";
> } else {
> echo "$zip doesn't match.";
> }
> }
>
> ?>

Don't know of a way to do it all in one regex. You could do something like
this, though:

$pattern = '/[0-9]{5}(-[0-9]{4})?/';

if((int)$zip && preg_match($pattern,$zip))
{ echo "$zip MATCHES"; }
else
{ echo "$zip doesn't match"; }

Casting $zip to an INTEGER and checking for a TRUE value will eliminate
0, 0-, and anything starting with a letter right off the bat.
Then your regex can handle the rest.

---John Holmes...


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



Re: [PHP] Variables changes their values

2003-06-03 Thread CPT John W. Holmes
> I'm getting strange behavior in some of my scripts
> I just upgraded from 4.3.1 to 4.3.2 and was hoping it would solve the
>  problem. The problem is that variables changes its values from one line
og
>  code to another - without specific code that should change the value.
> Do anybody else had this problem?

The problem is in your code. Show us an example of this problem with your
actual code.

---John Holmes...


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



Re: [PHP] convert seconds to hours, minutes, seconds

2003-06-03 Thread CPT John W. Holmes
> I have a value 178607, which is stored as seconds. I
> like to convert it (178607 Secs) to Hours, Minutes and
> Seconds appropiatly.
> Can anybody help me supplying the code?

If it's stored in MySQL, you can use SEC_TO_TIME()

mysql> select sec_to_time(178607);
+-+
| sec_to_time(178607) |
+-+
| 49:36:47|
+-+
1 row in set (0.00 sec)

mysql> select sec_to_time(178607)+0;
+---+
| sec_to_time(178607)+0 |
+---+
|493647 |
+---+
1 row in set (0.00 sec)

---John Holmes...

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



Re: [PHP] Variables changes their values

2003-06-03 Thread CPT John W. Holmes
> On Tuesday 03 June 2003 13:58, Jay Blanchard wrote:
> > [snip]
> > We would have to see some code
> >
> > Jay
>
> I'm not able to reproduce this in a short code-snippet.
> But from the first echo to the last echo $lid change its value:

Either this is a bad cut and paste job or this script will never run because
it's full of errors. Either way, if $lid changes, it's because you're
changing it. Maybe you have an if($lid = 'value') instead of if($lid ==
'value') somewhere?

>   if ($hostid==31) echo "lid1: $lid";
>
>   # Paragraphs
>   #
>   if ($bodytype==1) {
>  sql_query("UPDATE tblArticleParagraph SET sort=-1 WHERE
artid=$lid
> AND hostid=$session_hostid");
>  $tmpbody = '';
>  for ($i=0; $i $popt = 1;
> $popt = $popt | (($parhardoutline[$i]) ? 0x2 : 0);
> $parpicurl[$i] = preg_replace("/'/s",'"',$parpicurl[$i]);
> $parheadline[$i] = trim($parheadline[$i]);
> $parpictext[$i] = trim($parpictext[$i]);
> if ($hostoptions&0x80) {  # STRICT FONT/STYLE STRIP
>$parparagraph[$i] = stripFontAndStyle($parparagraph[$i]);
> }
> sql_query("INSERT INTO tblArticleParagraph
> (hostid,artid,sort,options,headline,picurl,paragraph,pictext)
>VALUES
>
($session_hostid,$lid,$i,$popt,'$parheadline[$i]','$parpicurl[$i]','$parpara
graph[$i]','$parpictext[$i]')");
> $tmpbody .= $parheadline[$i];
> $tmpbody .= ' ';
> $tmpbody .= $parparagraph[$i];
> $tmpbody .= ' ';
>  }
>  sql_query("UPDATE tblArticle SET body='$tmpbody' WHERE id=$lid
AND
> hostid=hostid=$session_hostid");
>  sql_query("DELETE FROM tblArticleParagraph WHERE artid=$lid AND
> sort=-1 AND hostid=$session_hostid");
>   }
>
>   if ($special && $formid) {
>  # form based article publishing
>  # arnt h, Feb 03
>  list($tformid,$treplyid) = sql_queryandfetch("SELECT
formid,replyid
> FROM refArticleForm WHERE hostid=$session_hostid AND artid='$saveid'

You do not finish the above SQL statement

>  if (!$tformid && !$treplyid) {
> sql_query("INSERT INTO refArticleForm
> (hostid,artid,formid,replyid) VALUES
($session_hostid,$saveid,$formid,0)");
> $tformid = $formid;
>  }
>  $surveyid = $tformid;
>  $hostid = $session_hostid;
>  $arntid = $id;
>  $id = $saveid;
>  $arntpublic_userid = $public_userid;
>  $public_userid = 0;
>  include 'include/surveysavereply.inc'; ## perform saving
>  $public_userid = $arntpublic_userid;
>  $id = $arntid;
>  sql_query("UPDATE refArticleForm SET replyid=$thisreplyid WHERE
> artid=$saveid AND hostid=$session_hostid");
>  $tmp = '';
>  reset($surveykeyval);
>  foreach ($surveykeyval as $key  => $val) {
> for ($xxi=0; $xxi$tmpval = $val[$xxi];
>if (!$tmpval) continue;
>$tmpval = preg_replace('/\|\{.*?\}/','',$tmpval);
>$lbl = "fbq_".$key;
>$tmp .= "<$key lbl=\"".$$lbl."\">$tmpval\r\n";
> }
>  }
>  # $tmp = ''.$tmp.'';
>  sql_query("UPDATE tblArticle SET body='$tmp' WHERE id=$saveid AND
> hostid=$session_hostid");
>   }
>
>   # Save tblArticleExtension
>   #
>   list($tmp) = sql_queryandfetch("SELECT id FROM tblArticleExtension
WHERE
> artid=$lid AND hostid=$session_hostid");
>  if ($tmp) sql_query("UPDATE tblArticleExtension SET
>
custom1='$custom1',custom2='$custom2',custom3='$custom3',custom4='$custom4'
> WHERE ar

Same here...

>   elseif ($custom1||$custom2||$custom3||$custom4) sql_query("INSERT
INTO
> tblArticleExtension (hostid,artid,custom1,custom2,custom3,custom4) V

and here...

Those alone will cause a ton of parse errors.

>
>   if ($hostid==31) echo "lid2:$lid";

---John Holmes...


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



Re: [PHP] Displaying 5 records only/displaying specific records

2003-06-03 Thread CPT John W. Holmes
> I'm trying to build a news panel for my home page. Basically I want to
> present the five most recent news articles in a recordset, but I'm not
> sure how to cut off the recordset after 5.
> Also I want to present a picture with my first headline.
>
> My code will go something like this:
>
>  // Start News Wotsit.
> // Create Recordset
> $gubbins = "SELECT * FROM tblContent WHERE pageParent =
> 3 ORDER BY pageDate DESC";

SELECT * FROM tblContent WHERE pageParent = 3 ORDER BY pageDate DESC LIMIT 5

Now your result only has 5 results returned. Loop through them with
mysql_fetch_assoc() and display accordingly.

---John Holmes...


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



Re: [PHP] Delete from Multidimensional Array?

2003-06-03 Thread CPT John W. Holmes
> I've built a page that collects network card information, assigning each
> element its place within a $Card array, and all of the cards to $NetCards.
> As you enter your card information at the bottom, the previous card is
> displayed above it, with a Delete checkbox option at the end of that row
> ($Delete[$Card]).
>
> But I can't figure out how to actually delete that card from the "deck",
> as it were. I've looked over the Arrays pages, but there's little there
> about multi-dimensional arrays and I ended up more confused than ever.
> Here's my print_r:
>
> Array   <=---  This is $NetCards
> (
> [0] => Array<=--- This one is just
> $Card
> (
> [0] => 3Com <=--- Description
> [1] => 12:34:45:78:90:AA<=--- MAC Address
> [2] => 129.93.100.100   <=--- IP  Address
> )
>
> [1] => Array
> (
> [0] => Intel 100b
> [1] => 12:34:45:78:90:AB
> [2] => 129.93.100.101
> )
>
> [2] => Array
> (
> [0] => ThinAire
> [1] => 12:34:45:78:90:BB
> [2] => 129.93.100.102
> )
>
> [3] => Array
> (
> [0] => 3Com
> [1] => 12:34:45:78:90:BC
> [2] => 129.93.100.103
> )
>
> )
>
> How can I delete, say, the wireless card (ThinAire) which is third, here,
> if someone clicks on that one's Delete box? Thanks!

Assuming you somehow already get the "2" value when the user checks the
checkbox, you'd simply call

unset($NetCards[2]);

to get rid of the "ThinAire" card. If you're also looking for help making
the checkboxes, let me know.

---John Holmes...


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



Re: [PHP] Re: Migration from register_globals=on to register_globals=off

2003-06-04 Thread CPT John W. Holmes
> yeah .. I knew it .. but it would be so very helpfull if it would be just
> included in a superglobal similar to $_REQUEST ...

Do it yourself, if you must: array_merge()

---John Holmes...

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



[PHP] Re: John - > RE: pagenting logic to cut short

2003-06-04 Thread CPT John W. Holmes
> Thanks, its working fine now, actually a little better than I expected :-)
> Dont understand the logic though, if you find time point me to the correct
> place where i can read up and figure out the logic you used.

The logic isn't too hard. You're on page X. You show links to other pages
from X minus 5 to X plus 5. So if you're on page 15, you show links for
pages 10 - 20. Those adjust dynamically based upon the current value of
$page.

The min() and max() bits are just easy ways to ensure you don't create links
for pages below 1 or above $numofpages.

---John Holmes...


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



Re: [PHP] setting up a cron job for a PHP script

2003-06-04 Thread CPT John W. Holmes
You can also call the file through lynx or wget if you can't call the php
executable directly.

lynx --dump http://www.yourserver.com/file.php
wget http://www.yourserver.com/file.php

Down side is that the file has to be in your web root. Works great for
calling remote files, though.

---John Holmes...

- Original Message - 
From: "Jay Blanchard" <[EMAIL PROTECTED]>
To: "Tim Thorburn" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, June 03, 2003 2:12 PM
Subject: RE: [PHP] setting up a cron job for a PHP script


[snip]
I've setup a simple PHP script that runs through a database table and
sends an email to a group of members asking them to verify their
information.  My new ISP allows me to access the cron tab so we can have
this script run at
set intervals.  However I'm a little new to the whole cron tab command
line ... is it possible to have a PHP script execute on command from a
cron tab?  And if so, could someone proide an example of say having the
script run on the first of every month?  We're using 4.3.0 if that
helps.
[/snip]

Find out where the PHP executable is...

which php

...should return something like /usr/local/bin/php

Put the following line in your crontab

15 2 1 * * /usr/local/bin/php -q /path/to/your/script.php

This will run in the 15th minute of the 2nd hour of the 1st of the
month. The -q get PHP to run quietly.

HTH!

Jay

-- 
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] Best open source banner advertising application

2003-06-04 Thread CPT John W. Holmes
> From: "Randum Ian" <[EMAIL PROTECTED]>
> Why pay for something when you can get this for nowt! ;o) 

I love getting things for nowt... like candy from a baby...

:)

---John Holmes...

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



Re: [PHP] setlocale() changes?

2003-06-04 Thread CPT John W. Holmes
> I've been getting a warning on one of my scripts since I upgraded from
4.1.2
> to the most recent version of PHP.  The warning is:
>
> Warning: setlocale(): Passing locale category name as string is
deprecated.
> Use the LC_* -constants instead
>
>
> The script at the line that is failing sez:
>
> setlocale ("LC_TIME", "$locale");

"LC_TIME" is a string... LC_TIME is a constant...

Like the warning says, use a constant.

---John Holmes...


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



Re: [PHP] Sessions and headers

2003-06-05 Thread CPT John W. Holmes
> When using PHP sessions, if the user's browser supports
> cookies, PHP sets the session id as a cookie (so far as I
> understand it).  So when trying to use the session ID in a
> script, a cookie request is sent to the browser to get the ID
> and assigns it to the internal variable $PHPSESSID (again,
> so far as I understand it).
> My problem is this and I'm hoping someone has come up
> with a workaround...
> When I try to use the Header() function call (which I do alot
> to set the content type such as PDF, doc, xl, etc), I'm getting
> errors opening up the file due to previous headers already
> having been sent - namely, the header call to get the cookie
> value.

What errors, exactly? Can you show some examples?

I had problems like this with IE over SSL that was solved by changing the
session.cache_limiter. Does it work for other browsers at all or is it a PHP
error you're getting?

---John Holmes...


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



Re: [PHP] Is "gd" present?

2003-06-05 Thread CPT John W. Holmes
> Is there a way to check within an application if the "gd" library has 
> been installed?

Maybe get_loaded_extensions() 

---John Holmes...

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



Re: [PHP] file output, columns, etc...

2003-06-05 Thread CPT John W. Holmes
> Need some help here.  I have to format a line with each piece of the line
> being a fixed set of characters in length, wether its a mix of spaces and
> letters, or all letters.  Here's an example of the line:
>
> 06?4111ABDALARM333 N COUNTRY CLUB  CANTON
DD8
>
> In this file, for instance, CANTON's space on the line has a length of 13
> characters.  If 'CANTON' is not 13, I have to fill with spaces.  Is there
> some sort of report formatting functions or osmething I can look at to lay
> out the structure of the line and then drop in variables to it and have
the
> line format itself w/o me having to calculate the length of each variable
> and put spaces at the end accordingly?  I've tried search, but I don't
have
> a clue what I am really looking for.  Help is appreciate.

printf() or sprintf() should do what you want...

---John Holmes...


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



Re: [PHP] function re-defined | WorkAround? [and some more Q's]

2003-06-05 Thread CPT John W. Holmes
> I'm working on quite a large website with a lot of php pages.. And a lot
of
> includable functions (modules).. Sometimes one of those modules gets
> included twice accidently and then it generates an error .. of course..
This
> made me wonder of there's any way to prevent the function from being
defined
> again.. I've looked on the 'get_included_files' and used it to check if
the
> file was already included.. For one, this had to search through the entire
> array and second it does not seem to return full file paths to the file,
but
> only the filename itself.. Not really what I want either, since there may
be
> various files with the same filename in various dirs..

How about using include_once() or require_once()?

> Or what I sometimes want to do is overrule a function .. the manual just
> told me PHP does not support this, is that really true?

Yeah...

> And then for my last question at this moment... things like "print" and
> "require" are considered langauge construct and therefore don't need the
> parentheses .. Can I make stuff like that myself too, so I can make
> something like a function which does not use parentheses ??

No.

---John Holmes...


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



Re: [PHP] Another Session Question

2003-06-09 Thread CPT John W. Holmes
So does your code work? Here's a tip: Try a simple example, like what's in
the manual, and see which method works for you. If they both work, which one
do you understand? Use that one...

---John Holmes...

- Original Message - 
From: "Pushpinder Singh Garcha" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, June 09, 2003 4:23 PM
Subject: [PHP] Another Session Question


Hello all,


I have php ver 4.1.1 running with register_globals() ON on my site.  I
am trying to use sessions to maintain state during a visit to the site.
I have read thru the manual, but my mind is still cluttered with
doubts. I understand that use of the $_SESSION global array will
greatly add to the security of the site and will prevent variable
poisoning.

How do I register a session?
The manual (http://www.php.net/manual/en/print/ref.session.php) says
that there are 2 methods:

Example 1. Registering a variable with $_SESSION.


---


Example 4. Registering a variable with register_globals enabled


-

This is a snippet of the code that I am testing:
";
   if(!isset($_SESSION['validuser']))
   $_SESSION['validuser'] = 0;
  else $_SESSION['validuser']++;

}

else{
echo "Please try again later";
}
}
?>

Thanks in advance,
Pushpinder


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



Re: [PHP] PHP vs. jsp, advice please

2003-06-10 Thread CPT John W. Holmes
Agree 100%. Don't assume that just because you use JSP, or any other
language, your program is going to instantly "scale well" and be easy to
maintain. You can write crappy, inefficient code in any language. You can
also write good programs in most any language if you put the proper planning
into it before hand.

It all comes down to using the language you know well enough to make your
program efficient. If you decide to use JSP, great, I wish you all the best.
If you decide to use PHP, great, I wish you all the best and we'll be here
on the mailing list to help.

---John Holmes...

PS: Sorry for the top-post, OE sucks!

- Original Message - 
From: "Jay Blanchard" <[EMAIL PROTECTED]>
To: "Jean-Christian Imbeault" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Tuesday, June 10, 2003 7:46 AM
Subject: RE: [PHP] PHP vs. jsp, advice please


[snip]
I'm worried that PHP won't scale well. And by scaling I don't mean under
heavy load, I mean maintenance wise :) I
can't imagine having to do a feature upgrade on a PHP project with more
than 100 files ... (this file requires that file which requires that one
and so on ...)
[/snip]

This is really a planning issue. PHP scales extremely well maintenance
wise if you plan the application well. IMHO a lot of PHP developers
operate fast and loose because the language allows it, therefore
planning is glossed over and maintenance issues get out of hand.
Conversely there are many well planned large scale PHP projects that do
not suffer from the maintenance problems you describe. I have seen this
problem in other apps using other languages...so I think that this is a
moot point.

Jay

-- 
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] How to show BLOB ?

2003-06-10 Thread CPT John W. Holmes
> I have a blob in the database. I want to open a file=BLOB in the browser
such
> a way as if I clicked on a link. So if it is pdf, its opened by pdf
plugin,
> if it is doc, it is open by word plugin, if it is zip the dialog for
> opening/saving to disk is opened, if it is jpeg it is directly displayed
in
> the browser. The header() function with Attachment doesn't work. Any idea
how
> to achieve this effect without writing the BLOB to a temporary file
somewhere
> on the disk and opening this file ???

You need to get header() to work. Use header() to deliver the correct
content-type for the file, then echo the $BLOB data. That's it. Show your
code if it's not working.

---John Holmes...


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



Re: [PHP] MSSQL - Previous/Next Paging Results

2003-06-10 Thread CPT John W. Holmes
> > -Original Message-
> > MSSQL seems to be a little bit messier that MySQL..e.g limit clause etc
> >
> > Anyone know of articles/examples that specifically deal with this issue?
>
> Look into the Top() function for MSSQL.  It goes something like:
>
> SELECT Top(10) * FROM table
>
> You should be able to find some info under the msdn.microsoft.com page.
> Or, MS has several hundred newsgroups, they should have one for MSSQL.

Use TOP in conjuction with mssql_data_seek() to get where you need. Since
you can't specify a starting point with TOP like you can with LIMIT, you
seek() to the starting point. All other concepts still apply.

---John Holmes...


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



Re: [PHP] confusing problem or am just plain confused....

2003-06-10 Thread CPT John W. Holmes
> I dont know how exactly to explain this but will do my best, i have many
of
> the following lines in a page:
>
>  ="package" value="loco package">



> each line of course has a differient id[] value and package value.
>
> Everything is working fine with the just id[] value but now i need to add
> the package value too...but the problem is when i submit the form all the
> hidden fields are getting submitted when i only need the hidden "package"
> value of the ticked checkbox...is there any way to do that? or alter the
> above so that each id[] can have 2 values?

---John Holmes...


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



Re: [PHP] nl2br

2003-06-11 Thread CPT John W. Holmes
> I am trying to create a very basic page where we can all easily work on a
> document.  I just have a huge textarea that inserts the text into a
longtext
> field in the mysql db.  I use nl2br to keep the formatting.  Of course,
when
> the document is viewed in the textarea, all of the  are there.  THe
> problem is, everytime I update the text in the textarea, another set of
 />'s are put in so with every edit, the lines get farther and farther
> apart...why?

So stop using nl2br() on the data before you put it in the database. You
only use nl2br() when it's displayed on a webpage as HTML. If you're
displaying the data in a textarea, you should be running htmlentities() on
it before you put it between  and  tags.

---John Holmes...


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



Re: [PHP] slash trouble when editing text

2003-06-11 Thread CPT John W. Holmes
Use stripslashes() to remove the slashes. Use htmlentities() on the text
before you put it into the , also.

---John Holmes...

- Original Message - 
From: "Matt Palermo" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, June 11, 2003 4:16 PM
Subject: [PHP] slash trouble when editing text


I wrote a small script that creates a link to all the .php and .txt files in
a given directory.  When one of these links is clicked, it brings up another
window with the files contents inserted into a text area.  From there the
user can edit the text file then click a submit button to make the changes.
The problem is whenever the file contains quotes, when the file gets edited
it puts a slash in front of every quote.  Like this.

// original .txt file
"these are quotes"

Then when the submit buttons is clicked, the file looks like this:

// edited .txt file
\"these are quotes\"

If submit is pressed again, then it will look like this:

// twice edited file
\\"these are quotes\\"

Does anyone know how I can avoid this from happening?  Thanks.

Matt


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



Re: [PHP] How to find if a string is an integer?

2003-06-12 Thread CPT John W. Holmes
> 
> > Sorry, I don´t know that you needed an effective snipet. And you are
> > right,
> > I only writed for positive integers. Try something like apply 2 type
cast
> > simunltaneous.
> >
> > if ( (string) ((int) $_POST["var_int"]) == $_POST["var_int"])
> > echo "is int";
> >
>
>
> Why not just use the is_int() function?
>
> www.php.net/is_int

Please try to use is_int() on a value passed from a form and see why.

Also, in the beginning of this thread, the OP already said that is_int() had
been tried.

---John Holmes...


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



Re: [PHP] dealiong with quote's in SQL strings

2003-06-13 Thread CPT John W. Holmes
> I recently installed 4.3.1 and enabled the magic_quotes_gpc to deal with
> quotes in mysql inserts.
> 
> However, I think I have run into a problem that might be related, and
> was wondering if there is an easy way to fix it:
> 
> I have a script that gets user input from a drop-down, on the action
> page I search a mysql table for the row matching the selection made
> previously. What I do then is to extract the result of that "select *
> from table where data = form_selection" and then to re-insert the data
> into the table ; note, re-insert, NOT UPDATE ( the app cals for a new
> row to be added with the updated data, so the "old" row stays intact and
> a new row is added that contains some of the old row's data plus some
> new stuff I add).
> 
> So, the new insert sql looks as per usual 
> 
> insert into table (`var1`,`var2`,`var3`,`var4`,...) values
> ('$var1','$var2',);
> 
> where $var1, $var2 etc is either "inherited" from the extract of the
> first querie's result set, or overwritten with my newly generated
> values. The problem now comes in with this:
> 
> If one or more of the extracted variables containes something like 
> " O'Healy " or something similar that causes trouble with the quotes in
> the new INSERT sql, well, you see the problem...
> 
> And I don't want to have to go and addslashes to all my extracted
> variables, because there really are a whole heap of them.
> 
> So, is there another php.ini setting that I'm missing to help me with
> this, or maybe a function that will addslashes to all my extracted vars?

magic_quotes_runtime in php.ini

---John Holmes...

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



Re: [PHP] page name string

2003-06-16 Thread CPT John W. Holmes
> I need a really simple function that retrieves the actual page file name
> from a URL.  So, if the URL is http://www.server.com/pagename.php, or if
> it is http://www.server.com/directory/pagename.php, the function in both
> cases will return "pagename.php".
> 
> I'm sorry if this is a ridiculously easy question, but I've combed
> $_SERVER and Javascript and have come up with nothing, and I am
> dumbfounded.

Well, at least you admit it. :)

$file = basename($_SERVER['PHP_SELF']);

---John Holmes...

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



Re: [PHP] Re: Difference between $_POST[foo] and $_POST['foo']?

2003-06-17 Thread CPT John W. Holmes
> At 16:19 17-6-03, you wrote:
> >$sql = 'select * from db where apple = \'' . $_POST['foo'] . '\';';
> >Like that?
> you missed some quotes:
> $sql = 'select * from db where apple = \''' . $_POST['foo'] . '\'"';

Go back and count the quotes again. The original post is correct as far as
quotes go. Yours is not, though, since you have three single quotes in a row
and have thrown in a double quote by itself.

Without color coding, this is all very hard to tell. That's why I prefer to
do it such as:

$sql = "SELECT * FROM db WHERE apple = '{$_POST['foo']}' ";

or, like someone else said, the following is perfectly valid:

$sql = "SELECT * FROM db WHERE apple = '$_POST[foo]' ";

There are way to many methods to do this, though, so just use the one that
makes the most sense to you. I've changed my mind about this a few times in
the past. :)

---John Holmes...


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



Re: [PHP] sorting an array

2003-06-17 Thread CPT John W. Holmes
> > array[numrooms] => Array ( [3] => 2 [2] => 5 [1] => 1 )
> > I want to get a result like this:
> > 2=>5
> > 3=>2
> > 1=>1
> > ( I want the keys to stay attached to the results)
> 
> perhaps asort()?
> "This function sorts an array such that array indices maintain their
> correlation with the array elements they are associated with."

Or arsort(), which will sort them in decending order.

---John Holmes...

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



Re: [PHP] cron job

2003-06-17 Thread CPT John W. Holmes
> Is there a way to run a script (to check a table for new fields, or to
> check time..etc) evrey few hours, without using programes souch as
> crontab.

In addition to what others have said, you don't _have_ to set up the cron
job (or any scheduled job) on the same computer as your scripts. If you have
a Cable/DSL connection, you could set up a cron job on your own computer to
connect to http://www.yourdomain.com/cron.php and run it when you need it.
If you have windows, you can even do the same thing with Task Scheduler.
Yeah, it makes things a little more difficult, but it's doable.

---John Holmes...


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



Re: [PHP] PHP.net Manual Magic?

2003-06-17 Thread CPT John W. Holmes
> One of the coolest things I have seen online, and some of you may not even
> know this works, but if you type in the url: "http://www.php.net/foo";
> you'll be taken straight to the foo page of the php manual, if one exists.
> If "foo" doesn't exist, you pull up a Google search-within-the-site page.
>
> I haven't been messing with php for very long, but I haven't been able to
> put together all of the pieces for something like this. Is it hugely
> complicated? There's definitely a lot more here than a simple .htaccess
> rewrite. Has anyone thought of any other uses this kind of thing could be
> put to?

It's a custom 404 page, IIRC. Your 404 page simply looks at the URL, grabs
the last part and forwards (using header(), I imagine) to the appropriate
page.

Many other uses for it, too. One that's written about on PHP.net is using
this to make static HTML pages. You have a URL such as domain.com/1234.html,
where that page doesn't exist. Your 404 page looks up product 1234 from the
database, writes an HTML page to disk called 1234.html, then redirects back
to the page. Now subsequent requests for 1234.html pull up the page just
created and do not hit the database at all. To "clear" everything, simply
delete all of the .html files and they'll be regenerated as they're needed.

I'm sure there are other uses...

---John Holmes...


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



Re: [PHP] Problems with quotes in URL - SOLVED - plz FLAME me!!!

2003-06-18 Thread CPT John W. Holmes
No, I'm all for a public flaming... let him serve as an example to others!!
:)

In all honesty, I have posted about the htmlentities/htmlspecialchars()
requirement when putting data in form inputs quite a lot recently. You
should have picked up on it sooner. :) Oh well, though... at least you know
now... AND KNOWING IS HALF THE BATTLE!

---John Holmes...

- Original Message - 
From: "Aaron Gould" <[EMAIL PROTECTED]>
To: "'Petre Agenbag'" <[EMAIL PROTECTED]>; "'Chris Hayes'"
<[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, June 18, 2003 8:59 AM
Subject: RE: [PHP] Problems with quotes in URL - SOLVED - plz FLAME me!!!


Oh come on now, we don't flame people, or even engage in name-calling for
that matter on this list...  :)

We all learn our lessons.

--
Aaron Gould
Web Developer
Parts Canada



-Original Message-
From: Petre Agenbag [mailto:[EMAIL PROTECTED]
Sent: June 18, 2003 8:49 AM
To: Chris Hayes
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Problems with quotes in URL - SOLVED - plz FLAME me!!!


Hi lists ( and all the guys trying to help me)

Firstly

SORRY, I oversimplified my examples that I posted in the hope that I
would get to the solution faster.

What i failed to mention in my stupidity, was that I echoed the variable
as the value of a form input text field, so I actually messed up the
HTML, and I just realized it, and a simple $var = htmlspecialchars($var)
does the trick beautifully.

Again
Sorry guys, I really should have known better than to post stripped down
code as the problem is usually a simple thing like this...

Just for the by-and-by, my previous claims to having a "perfectly
working" application before upgrading to 4.3.1 was also then a load of
bull, and I only realized now that my app had this bug in it all the
time!

Just goes to show.

Anyway, I deserve a good flaming for this one!

I'm ready;)




On Wed, 2003-06-18 at 14:39, Chris Hayes wrote:
> (cutted the part about sending a var as get)
>
>
>page.php?my_var=whatever+whatever++%5C%22whatever+whatever%5C%22&next_var=b
labla
> ok so here the variable is still complete, including slashes and quotes.
>
>
> >And now, on page.php
> >
> >If I do an
> >
> >echo stripslashes($my_var);
> >
> >I get exactly this:
> >
> >whatever whatever \
>
> i get better results with
>
> echo stripslashes(urldecode($_GET['my_var']));
> (or in your version
> echo stripslashes(urldecode($my_var));
> )
>
>
> this even though Marek  said "Incomming GET values are urldecoded
> automaticaly, no need to do this." (this=urldecode)
>
>


-- 
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] Session filesize limit

2003-06-18 Thread CPT John W. Holmes
> Does anyone know about the ideal session filesize
> limit? I am using the common functionality in the
> entire application. So i am thinking to store data
> into the session file once user logs into the system
> rather retrieving the information from database on
> each user request. But i dont know what should be the
> filesize limit. I am just trying to save database
> calls on each request. If anyone has other suggestions
> then please let me know.

2GB is the limit on most OS. Have fun. I hope  you know what you're doing.
:)

---John Holmes...


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



[PHP] Re: Fatal error: Call to undefined function: str_word_count()

2003-06-18 Thread CPT John W. Holmes
"nabil" <[EMAIL PROTECTED]> wrote in message
news:<[EMAIL PROTECTED]>...

> when i use str_word_count()  i got the following :

> Fatal error: Call to undefined function: str_word_count()

>

> and my PHP is Version 4.2.3

>

> What is the problem ???



Reading English?



us2.php.net/str_word_count



PHP 4.3.0 and greater...



---John Holmes...


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



Re: [PHP] Calling c function from php

2003-06-18 Thread CPT John W. Holmes
> Anyway, can any make a suggestion on how to connect to a c function from
> a php app?
>
> I have to connect to a sales tax calculation software.  The function
> is being written for me but I have to figure how to call it - get the
> variable - and use it again in my php app.
>
> I've been told there's an api or module on the php site with
> documentation that I am trying to research.
>
> Has anybody ever done this ?

I'm sure you could compile it into PHP somehow, if you wanted to go that
route. I can't help you there, though.

Or, you could just compile your C function into a stand-alone program and
call it through exec(), passing the parameters it needs and then retrieving
the output.

Why not just "port" the C code over to PHP??

---John Holmes...


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



Re: [PHP] Software Testing and Internationalization - Free book by LISA/Lemoine International

2003-06-18 Thread CPT John W. Holmes
> >> LISA, in collaboration with Lemoine International has made "Software
> >> Testing and Internationalization"  by Galileo Computing freely
> >> available for download.
> >> [snip]
> >> To download a copy, please visit
> >> http://www.lisa.org/interact/2003/swtestregister.html
> >
> >How about a privacy statement on the page where you collect all of our
> >info?
>
> John,
>
> A privacy statement has been placed on the page. We will also be putting
> up a statement on the other pages.
>
> Thank you.

Sounds great. Just trying to make sure you stay honest. I still don't know
if I'll give you all of that info or not, though... :)

---John Holmes...


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



Re: [PHP] Validating a "money" input

2003-06-18 Thread CPT John W. Holmes
> What is the best way to validate a "money" input?  For example, 3452.67 
> versus 3452..67.

if($value == (string)round((float)$value,2))

or

if(preg_match('/^[0-9]*\.?[0-9]+$/',$value))

appear to work. :) Assuming your value is a string to start with. 

---John Holmes...

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



Re: [PHP] direct access to file uploads

2003-06-18 Thread CPT John W. Holmes
> I am new to PHP and am trying to get access to files that are uploaded.
> I have RTFM ;-) and have noticed that PHP writes the file to disk in a
> temporary location and provides a method/class with all of the
> information needed to access it. I am loading (PDF's) into a binary
> field in mySQL and find it rather inefficient to have the file written
> to disk, and then have it read off and then written back into the db
> which is ultimately written to disk. Is there a way I can get direct
> access to the file as it comes in. I noticed a user comment on
> predefined vars page mentioned $RAW_POST_DATA (or something like that)
> but no info on how to address it. Is that my answer and what do I do
> from there? It also seems to be depricated and I do not want to use
> something that will disappear soon.

You can read it directly from the temp location into MySQL. We could debate
the logic of storing the files in the database to begin with, if you want.
:)

---John Holmes...


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



Re: [PHP] [Newman] Passing an image through a php file.

2003-06-19 Thread CPT John W. Holmes
> try this:
> 
> header("Content-type: image/jpeg");
> fopen ("d:/crushme/images/1.jpg", "r");

Just my opinion, but maybe you should try reading the file and echoing the
data instead of just opening it. :)

---John Holmes...


> I would like to pass an image throught
> http://server/newman/ImageTEST/image.php
>
> 1. I need the headers (Assuming) 
> would make the computer think its a image file.
> 2. load the image using fopen ("d://crushme//images//1.jpg", "r");
>
>
> 
> header("Content-type: image/jpeg");
> fopen ("d://crushme//images//1.jpg", "r");
>
> ?>
>
>
>  The image "http://server/newman/ImageTEST/image.php"; cannot be displayed,
> because it contains errors.
>
> This returns this error (above)
>
> Yes 1. Image is in the right location.
> Yes 2. I'm stuck.
>
> Any Suggestions would be very good.


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



Re: [PHP] Trapping PHP Errors

2003-06-19 Thread CPT John W. Holmes
> How do I trap a PHP error and display my own error message instead?
> 
> I have two PHP scripts - one that creates tables on MSSQL and one that
> deletes tables on MSSQL. I wish to capture the message that appears if
> the user attempts to create tables that already exist, or delete ones
> that do not exist.

http://us2.php.net/manual/en/function.set-error-handler.php

---John Holmes...

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



Re: [PHP] unique random id

2003-06-19 Thread CPT John W. Holmes
> How do i generate a unique random number?

You can use rand(), but there's no guarantee it'll be unique unless you
remember every number you've ever generated

---John Holmes...


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



Re: [PHP] Session Vars

2003-06-19 Thread CPT John W. Holmes
> setting up some pages to allow users to log in, and store their userID in
a
> session var.
> for development purposes, i've installed AMP on my windows box.
>
> -everything parses fine
> -register globals is on.
>
> problem: session vars do not seem to be carrying over pages, even when i
set
> the session_id to initial value.
>
> i start the session and save the variable:
>
> session_start();
>
> $PHPSESSID=session_id();
>
> $_SESSION['userID'] = $userID; //i've checked and $userID DOES contain a
> value: 1
> //If i echo $_SESSION['userID']; then it prints 1.
>
>
> header("Location: nextpage.php?PHPSESSID=$PHPSESSID");
>
> exit;
>
>
> on nextpage.php:
>
> session_start();
>
> session_id($PHPSESSID);

Please note the second sentence in this direct quote from the manual:

If id is specified, it will replace the current session id. session_id()
needs to be called before session_start() for that purpose. Depending on the
session handler, not all characters are allowed within the session id. For
example, the file session handler only allows characters in the range a-z,
A-Z and 0-9!

Thank you.

---John Holmes...


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



Re: [PHP] php https file download

2003-06-19 Thread CPT John W. Holmes
> Apache 2.0.40
> PHP 4.2.2
> Linux
>
> I have a single php script for downloading requested files.  It works
> beautifully on http over port 80.  It does NOT work at all over https on
> port 443.  I am using the exact same script (the very same file) for both
> http and https connections.  Apache has the +StdEnvVars enabled for all
> files and dirs under the https site.  Forms and cookies are working
> normally, as are redirect headers.  But for some reason, the headers for
> file downlaods are not working at all over ssl.
>
> I am really only testing this with IE 6 right now.

Read here:

http://marc.theaimsgroup.com/?l=php-general&w=2&r=1&s=session.cache_limiter+https&q=b

---John Holmes...


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



Re: [PHP] Empty Page problems

2003-06-19 Thread CPT John W. Holmes
> Can anyone tell me what is wrong with my PHP script? I am trying to add
> information to an MSSQL database from a separate HTM file. The script it
> as follows:

How about you tell us what the problem is? What is the result of this
script? What are you expecting the result to be? Take away the @ symbols so
you'll see errors if there are any. Add some debugging to track the progress
through the script

---John Holmes...

> 
> $myEmployeeName=$_GET['name'];
> $myEmployeeDept=$_GET['department'];
> $myEmployeeNotes=$_GET['notes'];
> $myEmployeeCTP=$_GET['ctp_op'];
>
> $myServer = "192.92.0.248";
> $myUser = "repro";
> $myPass = "repro";
> $myDB = "repro";
>
> error_reporting(E_ALL);
>
> print ("Attempting To Connect To MSSQL -
> ");
>
> $s = @mssql_connect($myServer, $myUser, $myPass)
> or die("Couldn't Connect To SQL Server On $myServer");
>
> print ("Stage 2");
>
> $d = @mssql_select_db($myDB, $s)
> or die("Couldn't Open Database $myDB");
>
> #this is the create bit
> print ("Connected - Attempting To Create Employee...");
>
> if ($mYEmployeeCTP == "on") {
> $query = "INSERT INTO users (name, department, notes, ctp_op)
> VALUES ('$myEmployeeName', '$myEmployeeDept', '$myEmployeeNotes', 'Y')";
>
> $result = mssql_query($query)
> or die("Creating Employee Failed");
>
> } else {
>
> $query = "INSERT INTO users (name, department, notes, ctp_op)
> VALUES ('$myEmployeeName', '$myEmployeeDept', '$myEmployeeNotes', 'N')";
>
> $result = mssql_query($query)
> or die("Creating Employee Failed");
>
> }
>
> print ("Employee Added To Database");
>
> print ("Go back to index");
>
> ?>


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



Re: [PHP] PHP: cannot configure SMTP_port....

2003-06-19 Thread CPT John W. Holmes
> i am trying to send mail from a script, but i receive these error message:
>
> Warning: mail() [function.mail]: Failed to connect to mailserver at
> "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini
> or use ini_set() in c:\apacheserver\apache\htdocs\work-net\serial.php on
> line 295
>
> I have PHP + Apache + MySql and work in "localhost" on a win98 machine.
how
> can i set it?

Have you tried doing what the error message suggests? Setting the SMTP value
in php.ini or through ini_set()? I assume you're coming through some ISP and
do not have your own SMTP server running, so you'd set the SMTP settting in
php.ini to the SMTP server of your ISP.

---John Holmes...


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



Re: [PHP] Re: error handling

2003-06-19 Thread CPT John W. Holmes
> I looked in the manual (twice now).  I want to keep logging to the log
> file but print to browser on this one script.
>
> I have in my script:
> error_reporting (E_ALL);
> error_reporting  (E_ERROR | E_WARNING | E_PARSE);
>
> but they're still only being logged to file.  I dont have access to
> php.ini.

Is display_errors enabled? You should be able to set either of these options
with ini_set().

If it's either log or display and you can't have both, then implement your
own error handler for the page, log the error, then display it also.

---John Holmes...


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



Re: [PHP] Month loop

2003-06-19 Thread CPT John W. Holmes
> Is there any way I could loop thru and print all the month names (i.e.
> January, February)?

Just make an array and loop through the array. You know the rest of the
names, right? :)

---John Holmes...


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



Re: [PHP] Cookies- peanut butter or chocolate??

2003-06-19 Thread CPT John W. Holmes
> 1. How do you setup a cookie that will not expire?? 

You can't. 

> 2. How do you put 2 items that you want to save in 
> the cookie and retrieve?? Examples in the PHP manual 
> only show how to work with a single value.

You can't. Use an array or two cookies. 

---John Holmes...

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



Re: [PHP] Is there an RTFM for 'use strict' ?

2003-06-23 Thread CPT John W. Holmes
> Done a lot of Perl & PHP coding over the years and one thing I _really_
> liked about Perl is its 'use strict;' directive.  For those of you not
> familiar with Perl, this made the script die if you don't (among other
> things) declare your variables before using them.
>
> Once the fingers are flying, stupid typing mistakes often come in and
> it is more often when a variable name is being typed.  It would be
> interesting to see how many PHP coders out there have spent ages trying
> to find a bug in their code that was due to them mis-spelling a variable
> or method name.
>
> Anyway, I can't find a reference to anything in the manual that will
> force PHP to strictly check variable names etc. to see if they are
> declared before use and if not throw up an error.
>
> Can somebody tell me which M to FR ?

The closest you can come is to set your error_reporting() to E_ALL. Then
you'll get notices about undefined variables and keys for arrays, but the
script will not die. You can do some FR at www.php.net/error_reporting. :)

---John Holmes...


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



Re: [PHP] sending headers

2003-06-23 Thread CPT John W. Holmes
> I try to include a redirect header in my script, but is fails with the
> familiar ( headers already sent) error.
>
> I KNOW you should put the headers call where it will cause the first
> output, and I do that, the only thing happening infront of the headers
> call is an include statement to my main db class; this class has
> absolutely NO output unless a function is called (which it is not)...
>
> What am I missing?

The error message tells you exactly what you need to know. "Output started
at xxx.php:12" or something similar. That gives you the file name and line
number where "output" was started. Begin your troubleshooting there. Ensure
you don't have any whitespace before or after the opening/closing 
tags (like an extra newline at the end of the included file).

---John Holmes...


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



Re: [PHP] Performance question

2003-06-23 Thread CPT John W. Holmes
> I have a question regarding retrieving the
> information. I have the functionlity in which on every
> user click, system needs to retrieve information for
> particular user and display the page according to the
> retrieved information. Now question is which is the
> scalable solution? (1) Retrieve information from the
> database on each user click. (2) Retrieve information
> from the session (here information is retrieved once
> and stored in the session file on the server, when
> user logs into the system)

Benchmark it and find out yourself.

I'm sure 99% of the people here are going to jump on this and say SESSION is
the way to go, and I'd probably agree with them up front. But the only way
to really tell with your program is to benchmark each possibility. If you're
already establishing a database connection for other uses, then one more
query may not be a big deal versus opening an file and reading it, but
you'll never know the real answer until you try both of them. Now, if you
only use the database connection to get this information, then yeah,
sessions will definitely be faster when you remove the database connection
entirely.

---John Holmes...


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



Re: [PHP]

2003-06-23 Thread CPT John W. Holmes
> When I include  in my html
> code, I get a parse error. The version is 4.1.2; phpinfo() reports
> that XML support is turned on. Can anyone help with this?

The first two characters are opening up a PHP block of code, so you get a
parse error. Either disable short open tags in php.ini, or use

";
?>

---John Holmes...


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



Re: [PHP] header() issues....

2003-06-23 Thread CPT John W. Holmes
> Does anyone know if there are issues with using the header() function
inside
> frames?  Is there extra stuff that needs to be added to it to get it to
work
> correctly?

No... each frame is it's own HTTP request. PHP operates server side so it
has no idea of "frames". It simply processes the code and redirects the
request or sends the appropriate header.

> Or if there were issues with header in php 4.06?

Dunno about that, look at the changelogs, maybe?

---John Holmes...


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



Re: [PHP] php.ini

2003-06-25 Thread CPT John W. Holmes

- Original Message - 
From: "Jay Blanchard" <[EMAIL PROTECTED]>
> [snip]
> > I am running a red hat 9 linux box with Apache 1.3.27 with
> > PHP 4 what is
> >
> > the default location for the php.ini file
> [/snip]
>
> Create a page with just the following...
>
>  phpinfo();
> ?>
>
> place the page in your web root and access it through a browser. On
> there you will find the path to your php.ini. The path is different for
> differing distros and OS's and if it is CLI, CGI, or not.

Also, as an FYI addition to this, if your PHP installation is not finding a
php.ini and using the defaults, you'll fine a _path_ to where PHP is
expecting to find php.ini listed on the phpinfo() page. If a path to an
actual php.ini file is listed, then that's the one it's using.

---John Holmes...


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



Re: [PHP] cannot get php through apache to write to my home dir on shared server

2003-06-26 Thread CPT John W. Holmes
From: "frank reeves" <[EMAIL PROTECTED]>
> I have an account on shared server and am trying to
> write a logfile (a dump of an email which i use mail()
> to send) to a logfile in my home dir.  This logfile
> will grow with all emails send by my app and will thus
> give me an archive of sorts.
>
> However, because php is executed through apache as
> user nobody it does not have permission to write to my
> linux home dir (fopen("log.file","a")) fails with
> permission denied). I dont want to open my home dir to
> the world to allow this operation but I also dont want
> to write my log to /var/tmp as user nobody.
>
> Does anyone know how I can get php to write as me to
> my home dir ?

You can only get this with PHP as a CGI.

> I suppose i could write a shell script and have my app
> call this but that seems a bit convoluted.

Other option is to read/write the file over FTP, since you'll be able to log
in as you.

---John Holmes...


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



Re: [PHP] PHP Interview questions

2003-08-26 Thread CPT John W. Holmes
From: "Micheal Harris" <[EMAIL PROTECTED]>

> I am in the process of hiring someone that needs to have extensive PHP and
> MySQL experience. Does anyone have any suggestions for interview
questions?
> I have no PHP or MySQL experience, and come from a non-technical
background.
> I want the questions to be technical, but I am unsusre as to how specific
I
> should get with the questionning!

How are you going to grade it, though, if you don't know PHP or MySQL?

I say you should send them to the list and let us grill them!! We'll sort
out the riff-raff.. :)

Seriously, look at their portfolio, call their references, and MAKE them
write code.

TASK: Create a PHP application that will insert names and dates of birth
into a MySQL database.

CONDITIONS: Given the PHP Manual, MySQL Manual, Notepad (or similar text
editor), and database host, user, and password information.

STANDARD: The application will run without errors when complete. The
application will accept a first name, last name, and date of birth (in
DDMMMYY format) through an HTML form and store the information in a MySQL
database. The application will list all current entries in the database in
an HTML table after a new row is inserted.

Things to look for:

1. Do they program for register_globals ON or OFF?
2. Do they check the setting of magic_quote_gpc?
3. Do they include error checking of form data and queries?
4. Is their program open to cross site scripting or SQL injection attacks?
5. Do they use a DATE type column or VARCHAR column for dates?
6. Do they write valid HTML?
7. How many files do they use to accomplish the task?
8. Do they try to add extra "fluff" instead of just accomplishing the task?

Hopefully others will pipe up with their comments, also. :)

---John Holmes...

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



Re: [PHP] Serve a file using PHP

2003-08-26 Thread CPT John W. Holmes
From: "Grant Rutherford" <[EMAIL PROTECTED]>
> Is there a way that PHP can allow a user to browse the files on the
> server's network, and ultimately send the file to the user?
>
> I'm making a database interface with PHP to be used internally on our
> network.  Through a PHP interface, the user wants to browse their
> network and find a file, and insert the file's path into the database.
> The user then wants the database to display a link, which when clicked
> will open the file.  They want this to work in Mozilla or IE, on both
> windows and linux machines.  I tried making the path a link with
> file://"path", but Mozilla wouldn't follow the link (probably a security
> thing; it makes sense that links shouldn't open local files).
>
> Is there a way that I can give PHP the network path (through $_POST for
> example), and it would return the file instead of an HTML document?

Can't you just link to \\computer_name\path\to\file.doc (or whatever the
filename is) ?

file:/// would try to load it off of their machine, not a network machine.

---John Holmes...

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



Re: [PHP] PHP Interview questions

2003-08-26 Thread CPT John W. Holmes
From: "Jay Blanchard" <[EMAIL PROTECTED]>

> Also ask a couple of other questions that require thought, but have
> nothing else to do with code. such as...
>
> In one room you have 3 light switches, each connected to one light bulb
> in another room. How many trips must you make to determine which switch
> is connected to which light bulb?

PHP is server side, so it obviously cannot control light bulbs. Use
javascript.

---John Holmes...

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



Re: [PHP] verifying sql INSERTs

2003-08-26 Thread CPT John W. Holmes
From: "Chris W. Parker" <[EMAIL PROTECTED]>

> I should instead just try to perform the INSERT and then if it fails I
> know I've already got a record. If it doesn't I know everything is cool.

If it is a certain kind of failure, then you have a duplicate, otherwise it
could be another type of failure/error. Use mysql_errno() to make sure you
catch the right error as a duplicate.

---John Holmes...

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



Re: [PHP] Website templating schemes

2003-08-26 Thread CPT John W. Holmes
From: "Joel Konkle-Parker" <[EMAIL PROTECTED]>


> I'm trying to make a PHP-backed website, and I'm trying to decide between
two
> templating schemes:
>
> 1. define 2 php template files: header.php, footer.php. in index.php,
require
> header.php, output content, require footer.php
>
> 2. define a php template file and a local page file. index.php defines
body()
> and crequires template.php. template.php prints the header, calls body()
to
> print the content, and and prints the footer.
>
> I'm currently using the second method, but I've only seen the first used
> elsewhere. Is there a reason that #1 is better than #2 (or is anything
else even
> better than that?)?

With method 2 it seems like your template file would become redundant
because every one of them would have to contain the header and footer code.

I would use 3 template files, header.php, footer.php, and body_index.php

index.php would:

1. PERFORM LOGIC
2. include header
3. include body
4. include footer

Then, all you have to do is make new body_XXX.php files for each page on
your site and the header/footer content is contained in one place.

---John Holmes...

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



Re: [PHP] verifying sql INSERTs

2003-08-27 Thread CPT John W. Holmes
From: "Curt Zirzow" <[EMAIL PROTECTED]>

> > I should instead just try to perform the INSERT and then if it fails I
> > know I've already got a record. If it doesn't I know everything is cool.
>
> I've debated with myself several times if this is really a good
> method to not have duplicates in the database.
>
> Like what happens if for some reason the constraint gets dropped?
> having your progam rely on the constraint will cause all data
> integrity to go to hell.

For one little script inserting into it's own little table, yeah, it really
doesn't matter.

Consider, though, a business making use of this database not only through a
PHP script, but through an Access frontend in marketing, some ASP scripts in
HR, etc. Now, if you don't enforce the constraints in the database, each and
every program must enforce the constraits itself. It's easier to do it in
one place. :)

---John Holmes...

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



Re: [PHP] PHP Interview questions

2003-08-27 Thread CPT John W. Holmes
From: "Curt Zirzow" <[EMAIL PROTECTED]>

> toggle_light(1);
> sleep(120);
> toggle_light(1);
> 
> toggle_light(2);
> move('self', 'room/');
> 
> if ($lightbulb['temp'] > $room['temp']) {
>   echo "switch #1";
> } elseif ($lightbulb['ison']) {
>   echo "switch #2";
> } else {
>   echo "switch #3";
> }
> 
> hm.. i had to keep it OT somehow :)

Aren't you missing a foreach($lightbulb as $bulb) in there somewhere?

---John Holmes...

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



Re: [PHP] Looping through a list - Newbie question

2003-08-27 Thread CPT John W. Holmes
From: "James Johnson" <[EMAIL PROTECTED]>
> I have a list contained in a session var. I want to loop through the list,
> getting the value of the current item, then do a query based on that
value.
> Is there an easy way to do this, or do I need to convert the list to an
> array first? In the code below, $id isn't being set.
>
> Here's my code (this is just testing stuff, sv_CampusList is set somewhere
> else):
>  session_start();
> $_SESSION['sv_CampusList'] = "1,2,4,5";
> for($i=1; $i<=strlen($_SESSION['sv_CampusList']); $i++){
> $id = strpos($_SESSION['sv_CampusList'],$i);
> echo $id;
> }
> ?>

What are you actually trying to accomplish here? I could tell you how to
loop through a list in a string and run a query for each number, but I'd
have the horrible feeling that you're using some inefficient method to
accomplish something.

For instance, if you're just trying to select data matching the numbers in
your list, you can do this:

$query = "SELECT * FROM Table WHERE campus_list IN
({$_SESSION['sv_CampusList']})";

---John Holmes...

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



Re: [PHP] dealing with arrays

2003-08-27 Thread CPT John W. Holmes
You need to name the elements a little differently. You're on the right
track with making them an array, but if I check the third box, that'll make
$check[0] = 1, and if I put in a name in the first box, that'll make
$name[0] = 'John'... so you have no way of relating the name from "entry
one" to the checkbox in "entry one".

So, the easy fix for this is to supply the key yourself.

Entry One




Entry Two




Now, when that is submitted, only the checked values will be passed in
$check.. so you can do this (assuming POST):

foreach($_POST['check'] as $key => $value)
{
  if(empty($_POST['name'][$key]))
  { echo "you didn't supply a name for entry $key"; }
  if(empty($_POST['tel'][$key]))
  { echo "you didn't supply a telephone number for entry $key"; }

  //process $_POST['name'][$key] and $_POST['tel'][$key]
}

Hope that helps. Sorry for the top post, but OE sucks. :)

---John Holmes...

- Original Message - 
From: "Aris Santillan" <[EMAIL PROTECTED]>
To: "Php (E-mail)" <[EMAIL PROTECTED]>
Sent: Tuesday, August 26, 2003 11:21 PM
Subject: [PHP] dealing with arrays


hi


I Have
Entry One




Entry Two




Entry Three




Entry Four




Entry Five




.

i want to process entries only with checked checkbox

how can i do this in php?

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



Re: [PHP] Cannot pass values from one page to another

2003-08-27 Thread CPT John W. Holmes
From: <[EMAIL PROTECTED]>
> Ok this is a major vulnerability that you are coding. Register globals 
> on and password being stored in the session is like having a banner on 
> your home page saying 'come and hack me'.

Please explain how you've come to this conclusion...

---John Holmes...

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



Re: [PHP] Implode slows down file reading? [was: str_replace performance in large mailing script]

2003-08-27 Thread CPT John W. Holmes
From: "frederik feys" <[EMAIL PROTECTED]>

> I thought str_replace caused slow down of my mailing script, but it
> seems to be this line of code:
>
> $fd =
> implode("",file("http://www.domain.org/store/min/Mailing_template.html";)
> );
>
> I first put the mailing template in $fd (only once) and then replace
> (str_replace) elements of it to individualize HTML emails.
> Btw i'm using php version 4.0.6.
>
> Are there better(faster) ways to read the contents of a file?

file_get_contents() ?

The slow down is probably because you're going through HTTP to read the
file. Is there a reason for that? Any way you can cache the file locally so
it's not read through HTTP all of the time?

---John Holmes...

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



Re: [PHP] Cannot pass values from one page to another

2003-08-27 Thread CPT John W. Holmes
From: <[EMAIL PROTECTED]>

> Didn't know this was the army :-)

Yeah, I signed you up last week. You report to basic training in November. I
hope you're ready! :)

> first unless you got your variable ordering (POST, GET, Env, Sesssion
> etc). the values in the session can be easily overridden with a simple
> old query string. Sure would hate to have my username and password
> passed along to each page. remember that when you are using cookies the
> data actually get's transferred between the client and the server.

By default, sessions are made global last, so the session value would
overwrite anything passed. But, yes, you're right that if some idiot changed
the order around (why?) then it could present a security problem. Thanks for
the explanation (just checking!) :)

---John Holmes...

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



Re: [PHP] session.cookie_domain

2003-08-27 Thread CPT John W. Holmes
From: "Shu Chow" <[EMAIL PROTECTED]>
> We're having a problem with a site that recently upgraded to php 4.3.3.
>   Ever since the upgrade, session variables won't pass between pages.
> Looking at the php.ini file, I see that session.cookie_domain is set to
> server.hostingcompany.com while our site is www.ourdomain.com.  If the
> session.cookie_domain is set to another domain, would this be the cause
> of our problems?

Yeah, that'd cause problems. You can set your own value for the domain using
an .htaccess file or the session_set_cookie_params() function

http://us2.php.net/manual/en/function.session-set-cookie-params.php

---John Holmes...

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



Re: [PHP] Session var read by form C++ CGI prog ?

2003-09-02 Thread CPT John W. Holmes
From: "John Bryan" <[EMAIL PROTECTED]>


> If so, the problem is that this file that is being uploaded
> via the form to the program MyCppProg.exe gets sent
> as THE input to the prog, apparently as a cgi-type
> parameter through stdin (i.e. cin), so that when I try to
> pass the value as a cgi parameter, it gets inserted INTO
> the file that is being uploaded.

Does this file already exist or are you looking to create it? It sounds like
you just need to fopen() the file, tack on your "variable" at the end of the
file (in some format) and then let the C++ program load the file, right?

---John Holmes...

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



Re: [PHP] Session var read by form C++ CGI prog ?

2003-09-02 Thread CPT John W. Holmes
From: "John Bryan" <[EMAIL PROTECTED]>

> The file would already exist on the client side.  They are
> uploading the file to be processed by this program
> MyCppProg.exe, which is invoked as a form 'action'.
> This already works, but depends on the Apache variable
> REMOTE_USER being set when user logs in, but we
> moving to implement a different method for authentication
> that involves talking to two different Oracle databases,
> password rules, etc., so this REMOTE_USER variable
> no longer gets set since we are bypassing Apache's
> authentication here.
>
> So I need to set an 'environment' variable that remains
> visible to scripts and progs within the session space, that
> can then be grabbed by the MyCppProg.exe, for example
> with getenv("MyEnvVar").  It used to use getenv("REMOTE_USER").
>
> I'm hoping to not have this variable have to be part of the file that gets
uploaded.

Ah, I see now.

If you're using a file upload box and submitting that form directly to your
.exe, then there's probably not much you can do.

In order to do this, I think you'll have to "intercept" the file.

When the user submits the file, it goes to a PHP script that copies it
somewhere. Then see if you can make an exec() call to the system and set the
"REMOTE_USER" variable, somehow. I'm not sure on the syntax/possibility of
that, it would depend upon your OS. Then make another exec() call to your
C++ program and send it the path the the file that was already uploaded.
Capture the output and show it to the user or do whatever you normally do.

---John Holmes...

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



Re: [PHP] evaluating dynamic variable

2003-09-02 Thread CPT John W. Holmes
From: "Stephen Goodman" <[EMAIL PROTECTED]>


> When I run the code you've attached, with $i iterating up to 3, I get
> three 'empty!', even if $resolution1 should be 'not empty!'. It seems
> like the $i in $_POST["resolutions".$i] is not getting parsed into a
> value, and php is looking for a key resolutions$i.
>
> Whoops, I'm an idiot. Resolution singular, not plural. Thanks for the
> help everyone

Does that mean you solved it? Remember that PHP is case sensitive, too.
$_POST['Resolution'] is not the same as $_POST['resolution'].

If you're still having trouble, go back to some basic debugging. Do a
print_r($_POST) so you actually know what $_POST contains, to begin with.

---John Holmes...

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



Re: [PHP] Form variables lost when duplicate records are found !

2003-09-02 Thread CPT John W. Holmes
From: "Pushpinder Singh Garcha" <[EMAIL PROTECTED]>
>   I am making use of a php form to add company details to a MySQL
> Database. Before I add the form variables I am checking to see if the
> SAME company name exists in the DB. If the same company exists, then a
> notification is provided. In between this , the variables that were
> entered on the form are LOST. Is there anyway I can store the variables
> so that if a duplicate record was found to be present, then the forms
> variables are stored and  NOT LOST ??
>
> Any suggestions would be greatly appreciated !  Thanks in advance

How do you display the form again when there is a "notification"?

Something as simple as:



will (safely) "remember" POSTed variables when you show the form again.

---John Holmes...

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



Re: [PHP] PHP installation on IIS

2003-09-03 Thread CPT John W. Holmes
From: "Sid" <[EMAIL PROTECTED]>

> This is the first time I am installing PHP on IIS and I don't know what I
am doing wrong. I copied the default php.ini file to the winnt dir.
> Then I added an ISAPI extention with .php to the App Mapings tab. (ISAPI
caching enabled)
> Then I made a test.php file with
> phpinfo();
> ?>
> but ll I see is the source code when I access this page.
>
> Does anyone have any ideas?

1. Make sure php4isapi.dll is in the same directory as php.exe

2. Make sure the IIS user (typically IUSR_computername) has read permissions
to c:\php (or wherever you put PHP)

3. Don't skip adding the ISAPI filter. I don't know why the instructions say
this as it never works unless you do it.

4. Make sure you restart IIS after the changes.

If that still doesn't work, let me know. If it doesn't work, open up the
"ISAPI Filter" tab and see if  you have a red or green arrow next to the PHP
Filter.

---John Holmes...

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



Re: [PHP] Q on Class and EXTEND

2003-09-03 Thread CPT John W. Holmes
jsWalter wrote:

> What I am trying to do is EXTEND the PEAR::Auth Class with new properties
> and methods.
>
> But I still want to use the original instantiation call...
>
>$myAuth =& Auth();
>
> So, I don't think I can rename the orginal Class in this case.
>
> I'm just being particular.
>
> Or do I have to create my new EXTENDED Class and then add code to
PEAR::Auth
> to make it work as if it is always just Auth? (I was told I could not do
> that)


You rename the PEAR::Auth class to something like Auth2. Then, you create
your new class and call it Auth. The new Auth class will extend the old one.
Then  you include your new methods in the new class.

Your old code will still continue to work.

---John Holmes...

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



Re: [PHP] Get the lowest value out of different fields

2003-09-03 Thread CPT John W. Holmes
From: "Frank Keessen" <[EMAIL PROTECTED]>

> I hope you can help me with this:
>
> I have a tabel in my database like this
>
> TEST
>
> fieldnameValue's
>
> testid  1
> testf1   3
> testf2   4
> testf3   0
> testf4   2
> testf5   0
>
> (so this is one record!)

Those are columns, right? Anytime you have columns named like that it means
you have a horrible database design.You're going to be better of pulling
this into PHP and finding the min() number.

Here's one way to do it in SQL, but you see how complex it is with just
three columns:

select case
when a>0 and b>0 and c>0 then least(a,b,c)
when a>0 and b>0 then least(a,b)
when a>0 and c>0 then least(a,c)
when b>0 and c>0 then least(b,c)
when a>0 then a
when b>0 then b
when c>0 then c
end from test;

---John Holmes...

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



Re: [PHP] mysql Pattern Matching

2003-09-04 Thread CPT John W. Holmes
From: "Ralph Guzman" <[EMAIL PROTECTED]>


> I know this question is best for the mySQL mailing list, but I am unable
> to subscribe to their list at this moment so perhaps somebody here can
> help me out.
>
> I have a table with a field where amenities are listed together using a
> comma delimiter like: pool,spa,fitness-center
>
> To search this table I use a query that looks something like this:
>
> SELECT * FROM properties WHERE amenities LIKE '%pool%' AND amenities
> LIKE '%spa%' AND amenities LIKE '%fitness-center%'
>
> This works, however let's say the user chooses to search for more
> amenities. This means the query would need multiple 'AND amenities LIKE
> '%%' statements.
>
> Is there a better way to write this?

You could use FIND_IN_SET().

SELECT * FROM properties WHERE FIND_IN_SET('pool',amenities) AND
FIND_IN_SET('spa',amenities) AND ...

It'll still grow as the number of amentities grow, but there's no getting
around that.

---John Holmes...

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



Re: [PHP] mySQL overhead: Tweaking Scripts for Speed

2003-09-05 Thread CPT John W. Holmes
From: "Dan Anderson" <[EMAIL PROTECTED]>
> But how much overhead is there in:
>
> $link = mysql_connect($hostname,$username,$password) or die("");
> $db = mysql_select_db($database,$link) or die("");
>
> Would it be beneficial to run a single one at the beginning of every
> script?  Currently I have a bunch of functions each with their own
> calls.

You should only "connect" once in your script. It's usually in an include
file to make things easy.

While multiple connections will just return the first connection, anyhow,
why do the extra work, right?

---John Holmes...

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



Re: [PHP] mysql Pattern Matching

2003-09-05 Thread CPT John W. Holmes
From: "Ralph Guzman" <[EMAIL PROTECTED]>


> Is there an advantage or difference in running FIND_IN_SET() instead of
> LIKE?

Actually no, I guess there isn't. Neither one will use an index.

mysql> desc test;
+---+-+--+-+-+---+
| Field | Type| Null | Key | Default | Extra |
+---+-+--+-+-+---+
| b | varchar(50) |  | MUL | |   |
+---+-+--+-+-+---+
1 row in set (0.01 sec)

mysql> explain select * from test where b like '%two%';
+---++---+--+-+--+--+---+
| table | type   | possible_keys | key  | key_len | ref  | rows | Extra |
+---++---+--+-+--+--+---+
| test  | system | NULL  | NULL |NULL | NULL |1 |   |
+---++---+--+-+--+--+---+
1 row in set (0.00 sec)

mysql> explain select * from test where find_in_set('two',b);
+---++---+--+-+--+--+---+
| table | type   | possible_keys | key  | key_len | ref  | rows | Extra |
+---++---+--+-+--+--+---+
| test  | system | NULL  | NULL |NULL | NULL |1 |   |
+---++---+--+-+--+--+---+
1 row in set (0.00 sec)

---John Holmes...

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



Re: [PHP] mySQL overhead: Tweaking Scripts for Speed

2003-09-05 Thread CPT John W. Holmes
From: "Dan Anderson" <[EMAIL PROTECTED]>


> > While multiple connections will just return the first connection,
anyhow,
> > why do the extra work, right?
>
> Yes that was what I was thinking.  But I was also thinking that I would
> need to global the $link and $db variables and run mysql_query() with
> them in options.  So I'm wondering how much work coding it will save.
> Or will it default to the mysql connection active in the main program?

It'll default. You only need to pass $link and $db to mysql_query() and the
other functions when you have multiple connections open to multiple
databases at the same time (something that is rarely needed).

---John Holmes...

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



Re: [PHP] Form data

2003-09-08 Thread CPT John W. Holmes
From: "Hardik Doshi" <[EMAIL PROTECTED]>

> I have a form for adding a university course details.
> It has some fields for which the parent form calls the
> child form. For example: Each course is associated
> with at least one faculty member. So when the user
> enters faculty member then first user needs to find
> the appropriate faculty member using the search module
> and then needs to append that faculty member to the
> course details form by clicking the button next to
> faculty member's name on the search results.
>
> Now my question is once user leaves the parent form to
> the search form for the faculty member, at that time
> how can i store the already entered information on the
> parent form. So i can retrieve it back once i come to
> the parent form after finding the appropriate faculty
> member.
>
> I would like to know your ideas for this problem. I
> have think two possible ways to do it. One is to store
> entire $_POST array of parent form into the database
> associated with the session id. Second is to store
> $_POST array of parent form into the session file
> itself. But i don't know which one is the efficient
> and real world solution. Even i would like to know
> other possible solutions.

I'd just store it in the session. If you put it in the database, then you
have to worry about cleanup. Session cleanup is automatic.

---John Holmes...

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



Re: [PHP] Creating a Calender

2003-09-08 Thread CPT John W. Holmes
From: "Dan Anderson" <[EMAIL PROTECTED]>


> Does anybody know how to generate calendars easily?  (i.e. print out
> complete calenders from the current month on)

I'd check out PEAR or phpclasses.org. I'm sure something is already written,
but I don't know of any personally.

---John Holmes...

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



Re: [PHP] adodb and php5

2003-09-08 Thread CPT John W. Holmes
From: "Gilberto Garcia Jr." <[EMAIL PROTECTED]>


> Does anyone had tested ADODB with php5?
> I can make a query, print the recordcount but when i try to show the
result i got nothing
>
> while (!$qry->EOF) {
> echo $qry->fields['campo'] . "";
>
> $qry->MoveNext();
> }

You might want to ask on the adodb forums:
http://phplens.com/lens/lensforum/topics.php?id=4

Does this work?

while($r = $qry->FetchRow($qry))
{ echo $r['campo']; }

---John Holmes...

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



Re: [PHP] Session Variables in a Class

2003-09-09 Thread CPT John W. Holmes
From: "micro brew" <[EMAIL PROTECTED]>
> I've been experimenting with sessions.  I can make
> them work just fine in a normal PHP page.  But when I
> create a class and try to define a session variable
> within a method in the class it won't work.  I've
> tried setting the session variable directly
> ($_SESSION['name']='somevalue') but that didn't work.
> The normal way of setting it -
> session_start();
> session_register('name');
> $name='somevalue';
>
> - didn't work either (within the class).

"didn't work" isn't very helpful to us. How useful would it be for me to
just answer you with "it worked" for me.

Show us some code examples (short ones) as to how this doesn't work, please.

---John Holmes...

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



Re: [PHP] Multiple image buttons

2003-09-09 Thread CPT John W. Holmes
From: "Hardik Doshi" <[EMAIL PROTECTED]>

> I have a page on which there are multiple image
> buttons. Is there any way to determine which button is
> pressed by the user?
>
> For example, there is a page on which i display all
> the users of the system with the edit and delete
> button beside each user entry. Now if admin wants to
> delete one of the users then how can i know admin
> pressed which button? It is possible with non-image
> button but image button always give me x and y
> co-ordinates.
>
> Please let me know if you have any clue.

Use a method like this:











Where the number in image[XX] will user_id of the user you want to edit or
delete.

---John Holmes...

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



Re: [PHP] Session Variables in a Class

2003-09-10 Thread CPT John W. Holmes
From: "micro brew" <[EMAIL PROTECTED]>

> Here's my class.  I start the session in the
> constructor and in later methods attempt to register
> session variables.  You can see I've tried a couple
> different methods but none of them maintain the
> session variable values.  Any suggestions?

Is register_globals ON or OFF? You shouldn't mix session_register() with
$_SESSION. Just use one other the other, but I recommend just using
$_SESSION.

$_SESSION['var'] = 'some value';

to set a session var, and

if(isset($_SESSION['var']))

to see if a variable is set.

Also, if you have a varible $foobar within a class method that you define as
a session var, you must make it global if you want to access it in other
methods. The same thing for HTTP_SESSION_VARS. I think you're just running
into a scope issue.

---John Holmes...

> Mike
>
> 
> class login {
>
> //This variable tells the browser where to redirect to
> the loginpage
> var
> $loginPage='http://www.somedomain.com/somepage.php';
> var
> $exitPage='http://www.somedomain.com/somepage.html';
> var $loggedIn;
> var $access;
> var $accesslevel;
>
>  function login($loggedIn, $access, $accesslevel) {
>
>   session_start();
>   if ($loggedIn=='1') {
>$this->checkLogin();
>   }
>   if ($access=='1') {
>$this->checkAccess();
>   }
>   if ($access=='0' && $loggedIn=='0') {
>$this->authenticateLogin();
>   }
>  }
>
> function checkLogin() {
>
>   if (session_is_registered('user')!='True') {
>session_register('unauthorizedaccess');
>$unauthorizedaccess="http://"; .
> $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
>header("location: $this->loginPage");
>exit();
>   }
>  }
>
>  function checkAccess() {
>
>if (session_is_registered('permission')=='True') {
> if
> ($HTTP_SESSION_VARS['permission']<$this->accesslevel)
> {
>  session_destroy();
>  header("location: $this->exitPage");
>  exit();
> }
>}
>else {
> session_register('unauthorizedaccess');
> $unauthorizedaccess="http://"; .
> $_SERVER["SERVER_NAME"] . $_SERVER["SCRIPT_NAME"];
> header("location: $this->loginPage");
> exit();
>}
>  }
>
>  function authenticateLogin() {
>
>   if ((!$HTTP_POST_VARS['un']) ||
> (!$HTTP_POST_VARS['pw'])) {
>session_register('loginError');
>header("Location: $this->loginPage");
>exit();
>   }
>
>   else {
>
>include("includes/db_connect.inc");
>
>//call db_connect function from db_connect.inc
>db_connect() or trigger_error("MySQL error #" .
> mysql_errno() . ":" . mysql_error());
>
>$query="select * from users where username=\"" .
> addslashes($HTTP_POST_VARS['un']) ."\" and
> password=\"" . addslashes($HTTP_POST_VARS['pw']) .
> "\"";
>
>$result=mysql_query($query) or trigger_error("MySQL
> error #" . mysql_errno() . ":" . mysql_error());
>
>$foundCount = mysql_num_rows($result);
>
>if ($foundCount==1) {
> session_register('user');
> session_register('permission');
> session_register('company');
> session_unregister('loginError');
> for ($i=0; $i < $foundCount; $i++) {
>  $row=mysql_fetch_array($result);
>  $_SESSION['user']=$row['userID'];
>  $_SESSION['permission']=$row['permissionLevel'];
>
>  $_SESSION['company']=$row['companyID'];
> }
> if
> (session_is_registered('unauthorizedaccess')=='True')
> {
>
> $location=$HTTP_SESSION_VARS['unauthorizedaccess'];
>  session_unregister('unauthorizedaccess');
>  header("Location: $location");
>  exit();
> }
>}
>else {
> session_register('loginError');
> header("Location: $this->loginPage");
> exit();
>}
>   }
>  }
>
>
> //closes class
> }
>
> ?>

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



Re: [PHP] divide

2003-09-10 Thread CPT John W. Holmes
From: "phpu" <[EMAIL PROTECTED]>

> I'm new in php and i've got allready a problem.
> I wanna divide 2 numbers and the result to be an integer separated by
comma. For example:
> $number1=1000;
> $number2=17;
> $result=$number1 / $number2;
> In this case the result is 588235.29411764
> And I wanna the result to be like this 588,235

I don't know if this is old or not, but I just got it.

Anyhow, use number_format()

---John Holmes...

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



Re: [PHP] How to access a program outside of PHP?

2003-09-10 Thread CPT John W. Holmes
From: "Adam Douglas" <[EMAIL PROTECTED]>


> Hi. I'm trying to develop a web interface to the ghostscript (gs)
> application. I have the ghostscript syntax down perfectly in the console.
> Now when I go to try and do it in PHP I get nothing. No errors, nothing
just
> a blank page with PHP logs turned on and errors turned on.

Does the Apache user have permission to run this program? PHP runs as the
Apache user when installed as a module.

---John Holmes...

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



Re: [PHP] Can't use strtotime for dates before 1970. Why not??

2003-09-10 Thread CPT John W. Holmes
From: "Free Grafton" <[EMAIL PROTECTED]>

> We provide a MySQL, PHP solution to customers. One of the fields that we
> store for the customers are birthdates. We just recently upgraded from Red
> Hat 7.1 to Red Hat 9.0 and now have realized that at version 7.3 they
> changed it where strtotime no longer shows values before 1/1/1970 as
> negative values. It nows creates a ­1 error. Thus, we are now left with
any
> individual over the age of 33 to not be able to calculate their birthdate.
> This is quite frustrating as there are no other functions that can handle
> this that we have found. I have looked around the PHP boards and it
appears
> that individuals are having to build custom functions to handle this and
are
> also frustrated with this issue.

You can use this in your query to calculate the age:

year(current_date) - year(dob) -
(if(dayofyear(dob)>dayofyear(current_date),1,0))

where "dob" is the Date of Birth column in a MySQL DATE format.

---John Holmes...

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



Re: [PHP] reverse lookup/domain lookup in PHP

2003-09-11 Thread CPT John W. Holmes
From: "Tim Baker" <[EMAIL PROTECTED]>

> Is it possible to reverse lookup (like here
> http://www.whatismyipaddress.com/reverse.asp) to
> find the domain with PHP? I assume a DNS lookup
> requires an external server somewhere?

That's be great if there was a PHP function to do this, something like
gethostbyaddr(), wouldn't it?

;)

http://us2.php.net/manual/en/function.gethostbyaddr.php

It's expensive, though...

---John Holmes...

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



Re: [PHP] Mysql Authentication problem

2003-09-11 Thread CPT John W. Holmes
From: "James Hamilton" <[EMAIL PROTECTED]>
> current testing code:
> 
> $link = mysql_connect("localhost", "user", "pass" )
> or die("Could not connect : " . mysql_error());
> print "Connected successfully";
> mysql_select_db("name") or die("Could not select database");
> print "connected";
> 
> with user = null && pass=null && name=test then I can access the test db 
> with no probs

How did you create this new user?

---John Holmes...

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



Re: [PHP] reverse lookup/domain lookup in PHP

2003-09-11 Thread CPT John W. Holmes
From: "Tim Baker" <[EMAIL PROTECTED]>
> Expensive? In server/processor time, money or bandwidth (doubt the
latter?)

server/processor time. It can take a while to get a response. Same as doing
it from command line.

---John Holmes...

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



Re: [PHP] New Session Ids generated with each page request

2003-09-11 Thread CPT John W. Holmes
From: "Golawala, Moiz M (IndSys, GE Interlogix)" <[EMAIL PROTECTED]>


> My problem is that I get a new Session Id with every
> request I send to the server. For that reason I am unable
> to share variables between pages using sessions. (I get a
> new session Id even I refresh the same page). The code
> below prints out different session id for "page1.php" and
> "page2.php". Can someone please help me figure out what
> would be causing this.
>
> on page1.php  I have the following code:
>  session_start();
> echo SID
> ?>
> Next page 
>
> on page2.php I have the following code
>  session_start();
> echo SID
> ?>

Your browser is not accepting the session cookie for some reason.

Change your link to this:

Next Page

and it'll work. You'll either have to pass the SID in every link/form, or
figure out why cookie aren't working.

---John Holmes...

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



Re: [PHP] Mailing List Programme

2003-09-11 Thread CPT John W. Holmes
From: "Sheni R. Meledath" <[EMAIL PROTECTED]>
> Many thanks for the details. Now the problem is Flush() is not working on
> my server (UNIX/Apache 1.3). Are there any issues with Unix servers. The
> page displays the title and then waits for teh complete script to execute.
> I am using IE 6.0 to browse the page.

The content could still be cached servers side or client side before being
displayed.

If you're using tables. IE may wait until  until it displays the
content.

---John Holmes...

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



Re: [PHP] Problem with HTML Text box and PHP variable.

2003-09-11 Thread CPT John W. Holmes
From: "murugesan" <[EMAIL PROTECTED]>


> This will help you
> 
>   $dins="Dinesh";
>  echo "";
> ?>

Use double quotes for HTML attributes. 

---John Holmes...

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



Re: [PHP] some kind of redirection (not the header function)

2003-09-11 Thread CPT John W. Holmes
From: "Juan Nin" <[EMAIL PROTECTED]>

> The beheaviour I want to acomplish is the same as in yahoorgoups.
>
> You can access a mian page, where you login and have a list of all the
groups you are subscribe to.
> You click on the link to each one and it redirects you to:
http://groups.yahoo.com/groups/yourGroup/
>
> There it displays the page for your group with all it´s characteristics.
The same behaviour
> if you access that URL directly. Or you can also access
http://groups.yahoo.com/groups/yourGroup/messages/ etc
>
> Thatś what I ant to do  :)
>
> Any ideas?

This is doable. It's discussed on here often. Basically, you use an apache
command to FORCE "groups" to be a PHP file. Then the remainder of the URL is
available in $_SERVER['REQUEST_URI']. You parse that to determine what group
the user is after, retrieve the content, and show it.

Search the archives or google for "search friendly urls" and you should get
some good tutorials or instructions.

---John Holmes...

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



Re: [PHP] rename()

2003-09-11 Thread CPT John W. Holmes
From: "Edward Peloke" <[EMAIL PROTECTED]>

> This is probably an easy question

Yep.. ;)

> I have an uploaded image in a temp file that I want to rename and put in
> another folder.  I am using rename() which works fine, the problem is, I
> want to force an overwrite if the file already exists.  [snip]

You should use move_uploaded_file(), which will overwrite the destination
file if it exists. It also has the added security that rename() does not in
that it will ENSURE the file actually came from an HTTP POST operation.

http://us2.php.net/manual/en/function.move-uploaded-file.php

---John Holmes...

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



Re: [PHP] Simple (?) var_dump question

2003-09-12 Thread CPT John W. Holmes
From: "Thomas Panzarella" <[EMAIL PROTECTED]>

> Hi.  I'm new to the list so sorry if this has already
> been asked before ...
>
> I want to find a way to capture the var_dump
> output as a string so I can write it to a log file ...
> (for example):
>
> $logger->debug(var_dump($foo));
>
> So, the above line would get a "var_dump
> stringified" version of $foo and pass it to my
> logger's debug method.

You need to use output buffering to capture the output with var_dump.

Or you can use print_r(), which will give you a similar output and can be
returned to a varible.

---John Holmes...

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



Re: [PHP] Simple (?) var_dump question

2003-09-12 Thread CPT John W. Holmes
From: "Wouter van Vliet" <[EMAIL PROTECTED]>


> aiaiaia ... you are all pretty right, for another function was forged.
> var_export has a "return" flag as second argument where print_r and
var_dump
> both have other variables as second (and third, and fourth, and sixth) ..
>
> So you can do: $logger->debug(var_export($Var), true)); which will log the
> var to your log.

print_r() is also a BOOL for the second argument that controls whether a
value is returned or displayed.

The only difference between print_r() and var_export() produces valid PHP
code.

The output from var_export() can only be captured with output buffering.

---John Holmes...

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



Re: [PHP] Simple (?) var_dump question

2003-09-12 Thread CPT John W. Holmes
From: "CPT John W. Holmes" <[EMAIL PROTECTED]>

> The only difference between print_r() and var_export() produces valid PHP
> code.

That should say var_export() produces valid PHP code, while print_r() does
not.

---John Holmes...

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



Re: [PHP] Calling a function.

2003-09-12 Thread CPT John W. Holmes
From: "Vincent M." <[EMAIL PROTECTED]>
> Is there any way to call a function with a variable inside the call. ie:
> 
>   if($preferences != "") {
> dis_display$$preferences() ;

$functon = "dis_play$preferences";
$function();

---John Holmes...

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



Re: [PHP] error cannot instantiate non-existent class

2003-09-12 Thread CPT John W. Holmes
From: "Golawala, Moiz M (IndSys, GE Interlogix)" <[EMAIL PROTECTED]>

> I am newbie with php and I am trying to instantiate a
> class.

Welcome to PHP.

> this->$config = $config;

$this->config = $config;

> Parse error: parse error, unexpected T_OBJECT_OPERATOR
> in C:\Program Files\Apache Group\Apache2\htdocs
> \Alarms\AddConfigs.inc on line 7
>
> Fatal error: Cannot instantiate non-existent class: addconfigs in
C:\Program Files\Apache Group\Apache2\htdocs\Alarms\test1.php on line 4

That first error is being caused by your syntax error above. Since there is
parse error in the class file, the second file cannot create an instance of
the class, hence the second error. Fix that line above and both will go
away.

---John Holmes...

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



Re: [PHP] Calling a function.

2003-09-12 Thread CPT John W. Holmes
From: "Jason Wong" <[EMAIL PROTECTED]>

> On Saturday 13 September 2003 01:40, CPT John W. Holmes wrote:
> > From: "Vincent M." <[EMAIL PROTECTED]>
> >
> > > Is there any way to call a function with a variable inside the call.
ie:
> > >
> > >   if($preferences != "") {
> > > dis_display$$preferences() ;
> >
> > $functon = "dis_play$preferences";
> > $function();
>
> Better still:
>
>   $functon(); // [sic]

LOL... No, you don't have to worry about that. Isn't PHP smart enough to
know what I mean??

---John Holmes...

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



<    1   2   3   4   5   >