php-general Digest 6 Nov 2009 07:26:50 -0000 Issue 6429

Topics (messages 299649 through 299674):

How do I get reliable COMPUTERNAME?
        299649 by: Andrew Ballard
        299658 by: Jim Lucas
        299662 by: Andrew Ballard

Re: Plotting a Line Graph
        299650 by: cool.hosting4days.com

Re: Creating a Dynamic PHP/CSS Page (newbie design question)
        299651 by: Ashley Sheridan
        299652 by: Shawn McKenzie
        299653 by: Shawn McKenzie
        299654 by: Andrew Ballard
        299656 by: tedd
        299660 by: cool.hosting4days.com
        299663 by: Shawn McKenzie
        299664 by: Ashley Sheridan
        299667 by: tedd

Re: Should I care about these errors?
        299655 by: tedd
        299657 by: Robert Cummings

Re: Imagick question
        299659 by: Ashley M. Kirchner
        299661 by: Ashley Sheridan
        299665 by: Ashley M. Kirchner

Re: Custom function for inserting values into MySQL
        299666 by: Daevid Vincent

Re: Free tech talk by Percona tonight in Palo Alto, CA
        299668 by: Michael Shadle
        299670 by: Sam Ghods

question about smarty
        299669 by: Sudhakar
        299674 by: Fernando Castillo Aparicio

Function Not Working...Little help
        299671 by: Don Wieland

Re: Why getcwd() returs different results?
        299672 by: Raymond Irving

Preview button to show PDF without submitting post data?
        299673 by: Dave M G

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
I want to store the name of the computer that is executing a script in
some log tables. (Our servers are load balanced, and I'd like to be
able to determine which physical machine is serving each request.)

On my development machine (Windows PC running the debugger in Zend
Studio), I can find the name in three places:

getenv('COMPUTERNAME')
$_ENV['COMPUTERNAME']
$_SERVER['COMPUTERNAME']

On the development server, only the first works; $_ENV and $_SERVER
both return NULL and throw an undefined index notice.

I'm concerned about the reliability of all of these methods, since it
seems that they are not always available and all three can be easily
overridden inside a script. However, I notice that the header
generated by phpinfo() remains correct even when I manually spoofed
all three values on my development machine. Is there a reliable way to
find this value?

Andrew

--- End Message ---
--- Begin Message ---
Andrew Ballard wrote:
> I want to store the name of the computer that is executing a script in
> some log tables. (Our servers are load balanced, and I'd like to be
> able to determine which physical machine is serving each request.)
> 
> On my development machine (Windows PC running the debugger in Zend
> Studio), I can find the name in three places:
> 
> getenv('COMPUTERNAME')
> $_ENV['COMPUTERNAME']
> $_SERVER['COMPUTERNAME']
> 
> On the development server, only the first works; $_ENV and $_SERVER
> both return NULL and throw an undefined index notice.
> 
> I'm concerned about the reliability of all of these methods, since it
> seems that they are not always available and all three can be easily
> overridden inside a script. However, I notice that the header
> generated by phpinfo() remains correct even when I manually spoofed
> all three values on my development machine. Is there a reliable way to
> find this value?
> 
> Andrew
> 

Well, I looked at all the variables that are available.  Then I looked at the
data in the output of phpinfo().

The only place that I can find the information that you are looking for is
available in the "PHP Configuration" section and it is in the System 
information.

So, looking at the phpinfo() page, I noticed the first comment down had a
method/function for converting the output of phpinfo() into a multidimensional
array.  Taking the output of that users function, you can access the data the
data you are looking for.

So, here is a link to the phpinfo() page.

http://php.net/phpinfo

>From there, get the function called phpinfo_array()

take the output of that and run it through the following set of commands.

$data = phpinfo_array(TRUE);
list(, $server_name) = explode(' ', $data['PHP Configuration']['System']);
print( $server_name );

This will give you what you are looking for.

Jim

--- End Message ---
--- Begin Message ---
On Thu, Nov 5, 2009 at 2:03 PM, Jim Lucas <[email protected]> wrote:
> Andrew Ballard wrote:
>> I want to store the name of the computer that is executing a script in
>> some log tables. (Our servers are load balanced, and I'd like to be
>> able to determine which physical machine is serving each request.)
>>
>> On my development machine (Windows PC running the debugger in Zend
>> Studio), I can find the name in three places:
>>
>> getenv('COMPUTERNAME')
>> $_ENV['COMPUTERNAME']
>> $_SERVER['COMPUTERNAME']
>>
>> On the development server, only the first works; $_ENV and $_SERVER
>> both return NULL and throw an undefined index notice.
>>
>> I'm concerned about the reliability of all of these methods, since it
>> seems that they are not always available and all three can be easily
>> overridden inside a script. However, I notice that the header
>> generated by phpinfo() remains correct even when I manually spoofed
>> all three values on my development machine. Is there a reliable way to
>> find this value?
>>
>> Andrew
>>
>
> Well, I looked at all the variables that are available.  Then I looked at the
> data in the output of phpinfo().
>
> The only place that I can find the information that you are looking for is
> available in the "PHP Configuration" section and it is in the System 
> information.
>
> So, looking at the phpinfo() page, I noticed the first comment down had a
> method/function for converting the output of phpinfo() into a multidimensional
> array.  Taking the output of that users function, you can access the data the
> data you are looking for.
>
> So, here is a link to the phpinfo() page.
>
> http://php.net/phpinfo
>
> From there, get the function called phpinfo_array()
>
> take the output of that and run it through the following set of commands.
>
> $data = phpinfo_array(TRUE);
> list(, $server_name) = explode(' ', $data['PHP Configuration']['System']);
> print( $server_name );
>
> This will give you what you are looking for.
>
> Jim
>

Close, but not quite what I need. On the Windows systems, the System
value is "Windows NT [hostname] [build]", so that just returns "NT".
Thanks, though. :-) You never know when something like that might be
useful.

I found php_uname('n') which looks like it will return the information
I'm after without having to dissect strings, and it appears to work
just fine across platforms.

Andrew

--- End Message ---
--- Begin Message ---

On Oct 16, 2009, at 11:45 AM, [email protected] wrote:

Jim Lucas wrote:

I would recommend http://www.rgraph.net/
It was written and is currently maintained by a member of this list.
Jim Lucas

Hi Jim,

rgraph looks cool... most demos I see show just a few points - do you think this could display 500 points? (I'm looking through their docs now...)


I als see this :

http://pear.php.net/package/Image_Graph

Q: has anyone had success using this?

Also - it says "this package is not maintained" - is that a scary thing?

Are there any other ways for php to create a simple live line graph from 500 points?

Thanks,
[email protected]






--- End Message ---
--- Begin Message ---
On Thu, 2009-11-05 at 08:06 -0800, [email protected] wrote:

> Hi Folks,
> 
> My goal: is to have a template form to control css styles, where the  
> user fills out choices in a template form page and the results might  
> get stored in a MysQL prefs table.
> 
> But I guess you can't have php mixed with .CSS page ... so is the  
> best way to do this like: ...?
> 
> - set a a normal mystyle.css style sheet with no php but with all  
> possible choices
> 
> - then - on the css prefs form page you might have choices like:
> 
> fontsize = small or med or big etc. then you might store the 'actual'  
> css name (on the real css style sheet) associated with the choice like :
> style = "HEADER1" or whatever based on the choice
> 
> 
> then let's say I have a page:
> 
> mypage.php
> 
> that links to a css style sheet:
> 
> mystyle.css
> 
> - then the php page might use it like:
> 
> class = "<?php echo $thischoice; ?>" for "HEADER1"
> 
> Q: Is that the best way to setup dynamic css choices using php?
> 
> Any comments would be appreciated - dave
> 
> 
> Thanks,
> [email protected]
> 
> 
> 
> 
> 
> 


You can point your stylesheet link to a PHP file like this: <link
type="stylesheet" href="css.php" type="text/css">

and then in your PHP script, make sure you set your output header type
to text/css like so:

header("Content-Type: text/css");

That way, your PHP script can output exactly what CSS you require.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
[email protected] wrote:
> Hi Folks,
> 
> My goal: is to have a template form to control css styles, where the
> user fills out choices in a template form page and the results might get
> stored in a MysQL prefs table.
> 
> But I guess you can't have php mixed with .CSS page ... so is the best
> way to do this like: ...?
> 
> - set a a normal mystyle.css style sheet with no php but with all
> possible choices
> 
> - then - on the css prefs form page you might have choices like:
> 
> fontsize = small or med or big etc. then you might store the 'actual'
> css name (on the real css style sheet) associated with the choice like :
> style = "HEADER1" or whatever based on the choice
> 
> 
> then let's say I have a page:
> 
> mypage.php
> 
> that links to a css style sheet:
> 
> mystyle.css
> 
> - then the php page might use it like:
> 
> class = "<?php echo $thischoice; ?>" for "HEADER1"
> 
> Q: Is that the best way to setup dynamic css choices using php?
> 
> Any comments would be appreciated - dave
> 
> 
> Thanks,
> [email protected]
> 

Maybe setup your table like this:

selector        style           value
-------------------------------------
HEADER1         font-size       small
HEADER1         color           black
etc...

Then have a PHP page (user_styles.php) that queries the DB for the
styles and echoes them:

$result = query("SELECT * from user_styles WHERE userid = $userid");

while($row = fetch_assoc($result)) {
    echo $row['selector']." { ".$row['style'].": ".$row['value']." }\n";
}

Then just link the PHP page as a stylesheet in your HTML:

<link rel="stylesheet" href="user_styles.php" type="text/css" />



-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
Shawn McKenzie wrote:
> [email protected] wrote:
>> Hi Folks,
>>
>> My goal: is to have a template form to control css styles, where the
>> user fills out choices in a template form page and the results might get
>> stored in a MysQL prefs table.
>>
>> But I guess you can't have php mixed with .CSS page ... so is the best
>> way to do this like: ...?
>>
>> - set a a normal mystyle.css style sheet with no php but with all
>> possible choices
>>
>> - then - on the css prefs form page you might have choices like:
>>
>> fontsize = small or med or big etc. then you might store the 'actual'
>> css name (on the real css style sheet) associated with the choice like :
>> style = "HEADER1" or whatever based on the choice
>>
>>
>> then let's say I have a page:
>>
>> mypage.php
>>
>> that links to a css style sheet:
>>
>> mystyle.css
>>
>> - then the php page might use it like:
>>
>> class = "<?php echo $thischoice; ?>" for "HEADER1"
>>
>> Q: Is that the best way to setup dynamic css choices using php?
>>
>> Any comments would be appreciated - dave
>>
>>
>> Thanks,
>> [email protected]
>>
> 
> Maybe setup your table like this:
> 
> selector      style           value
> -------------------------------------
> HEADER1               font-size       small
> HEADER1               color           black
> etc...
> 
> Then have a PHP page (user_styles.php) that queries the DB for the
> styles and echoes them:
> 
> $result = query("SELECT * from user_styles WHERE userid = $userid");
> 
> while($row = fetch_assoc($result)) {
>     echo $row['selector']." { ".$row['style'].": ".$row['value']." }\n";
> }
> 
> Then just link the PHP page as a stylesheet in your HTML:
> 
> <link rel="stylesheet" href="user_styles.php" type="text/css" />
> 
> 
> 

Obviously you'd also want the userid and most likely a PK in the table
also :-)

id      userid  selector        style           value
-----------------------------------------------------

And also probably what Ash said:

header("Content-Type: text/css");

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
On Thu, Nov 5, 2009 at 11:31 AM, Shawn McKenzie <[email protected]> wrote:
> Maybe setup your table like this:
>
> selector        style           value
> -------------------------------------
> HEADER1         font-size       small
> HEADER1         color           black
> etc...

If you do this, you'll probably want to add a sequence number column
to ensure that your directives are output in the correct order in
consideration of CSS inheritance rules.

Andrew

--- End Message ---
--- Begin Message ---
At 8:06 AM -0800 11/5/09, [email protected] wrote:
But I guess you can't have php mixed with .CSS page


Not so grasshopper.

Try this:

http://sperling.com/examples/pcss/

These values can be pulled from a database.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
SORRY FOR THE EXTRA 2 BAD pre SENDS (accident...)


Thank for all the help!

Getting there... as a baby step - I'm trying this:

(part of this is from - http://sperling.com/examples/pcss/)

1 - I created this style sheet page called css.php with these contents:

================

.test1 {
        font-family: Verdana, Arial, Helvetica, sans-serif;
        color: #0099FF;
        font-size: 18px;
}

<?php
header("Content-type: text/css");
$color = "green";        // <--- define the variable
echo <<<CSS
/* --- start of css --- */
.title-text
        {
        color: $color;  /* <--- use the variable */
        font-weight: bold;
        font-size: 1.2em;
        text-align: left;
        }
/* --- end of css --- */
CSS;
?>

-------------------------

2 - I created this test page called testcss.php with these contents:

PROBLEM: the 'test1' style shows up - but the 'title-text' doesn't seem to work
btw: even added this : media="screen" from demo ....
How do I get it to show up?

======



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>

<link href="css.php" rel="stylesheet" type="text/css" media="screen" />
</head>

<body >
<p>test <span class="test1">this</span></p>

<p class="title-text">and this</p>
</body>
</html>


===================


Thanks,
[email protected]






--- End Message ---
--- Begin Message ---
[email protected] wrote:
> SORRY FOR THE EXTRA 2 BAD pre SENDS (accident...)
> 
> 
> Thank for all the help!
> 
> Getting there... as a baby step - I'm trying this:
> 
> (part of this is from - http://sperling.com/examples/pcss/)
> 
> 1 - I created this style sheet page called css.php with these contents:
> 
> ================
> 
> .test1 {
>     font-family: Verdana, Arial, Helvetica, sans-serif;
>     color: #0099FF;
>     font-size: 18px;
> }
> 
> <?php
> header("Content-type: text/css");
> $color = "green";        // <--- define the variable
> echo <<<CSS
> /* --- start of css --- */
> .title-text
>     {
>     color: $color;  /* <--- use the variable */
>     font-weight: bold;
>     font-size: 1.2em;
>     text-align: left;
>     }
> /* --- end of css --- */
> CSS;
> ?>
> 
> -------------------------
> 
> 2 - I created this test page called testcss.php with these contents:
> 
> PROBLEM: the 'test1' style shows up - but the 'title-text' doesn't seem
> to work
> btw: even added this : media="screen" from demo ....
> How do I get it to show up?
> 
> ======
> 
> 
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
> <title>Untitled Document</title>
> 
> <link href="css.php" rel="stylesheet" type="text/css" media="screen" />
> </head>
> 
> <body >
> <p>test <span class="test1">this</span></p>
> 
> <p class="title-text">and this</p>
> </body>
> </html>
> 
> 
> ===================
> 
> 
> Thanks,
> [email protected]

You need to do the header() before anything else.


-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
On Thu, 2009-11-05 at 14:13 -0600, Shawn McKenzie wrote:

> [email protected] wrote:
> > SORRY FOR THE EXTRA 2 BAD pre SENDS (accident...)
> > 
> > 
> > Thank for all the help!
> > 
> > Getting there... as a baby step - I'm trying this:
> > 
> > (part of this is from - http://sperling.com/examples/pcss/)
> > 
> > 1 - I created this style sheet page called css.php with these contents:
> > 
> > ================
> > 
> > .test1 {
> >     font-family: Verdana, Arial, Helvetica, sans-serif;
> >     color: #0099FF;
> >     font-size: 18px;
> > }
> > 
> > <?php
> > header("Content-type: text/css");
> > $color = "green";        // <--- define the variable
> > echo <<<CSS
> > /* --- start of css --- */
> > .title-text
> >     {
> >     color: $color;  /* <--- use the variable */
> >     font-weight: bold;
> >     font-size: 1.2em;
> >     text-align: left;
> >     }
> > /* --- end of css --- */
> > CSS;
> > ?>
> > 
> > -------------------------
> > 
> > 2 - I created this test page called testcss.php with these contents:
> > 
> > PROBLEM: the 'test1' style shows up - but the 'title-text' doesn't seem
> > to work
> > btw: even added this : media="screen" from demo ....
> > How do I get it to show up?
> > 
> > ======
> > 
> > 
> > 
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> > <html xmlns="http://www.w3.org/1999/xhtml";>
> > <head>
> > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
> > <title>Untitled Document</title>
> > 
> > <link href="css.php" rel="stylesheet" type="text/css" media="screen" />
> > </head>
> > 
> > <body >
> > <p>test <span class="test1">this</span></p>
> > 
> > <p class="title-text">and this</p>
> > </body>
> > </html>
> > 
> > 
> > ===================
> > 
> > 
> > Thanks,
> > [email protected]
> 
> You need to do the header() before anything else.
> 
> 
> -- 
> Thanks!
> -Shawn
> http://www.spidean.com
> 


Like I mentioned in my first reply to this, you need to set the content
type of the output in css.php:

header("Content-Type: text/css");

That way, the server sends down the right headers to the agent that is
requesting the CSS. By default, PHP outputs a content type of text/html,
and your browser thinks it got HTML instead of CSS so does nothing.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
At 8:16 PM +0000 11/5/09, Ashley Sheridan wrote:
On Thu, 2009-11-05 at 14:13 -0600, Shawn McKenzie wrote:

 > > Getting there... as a baby step - I'm trying this:
 >
 > > (part of this is from - http://sperling.com/examples/pcss/)

 >
 > You need to do the header() before anything else.


I'm not ragging on you Ashley, but what he needs to do is follow the directions as outlined in my example.

I really find it frustrating when I take the time to make things as simple as possible and then have people who don't want to take the time to understand what's being presented to them.

He could have his entire problem solved if he would only read and follow the documentation instead of throwing stuff together as if it will somehow work.

This reminds me of my first memory when I was two years old. You see, I had a wagon and I wanted it to run like cars do. I knew that my wagon didn't have what it took to make it run, so I started throwing stuff into it in the hopes that somehow everything would come together and the wagon would automagically run.

Well... it didn't run!

So, I stopped trying to solve things that way when I was two. I'm just surprised how long it takes others to discover that simple fact.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
At 11:50 PM +1000 11/5/09, Angus Mann wrote:
OK...point taken.

On a partly related matter, which of the following is "correct" or "Better" ?

echo("Stuff to display...");
or
echo 'Stuff to display...';
or
echo "Stuff to display...";
or
echo('Stuff to display...');


I use:

   echo('Stuff to display...');

First, it easy for me to read. Second, the processor doe not evaluate the contents.

However,

   echo 'Stuff to display...';

is probably the more "purest" route. You don't need the parenthesis.

If you have a variable in the mix, then use double quotes, such as:

   echo("Stuff to display... $stuff");

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
tedd wrote:
At 11:50 PM +1000 11/5/09, Angus Mann wrote:
OK...point taken.

On a partly related matter, which of the following is "correct" or "Better" ?

echo("Stuff to display...");
or
echo 'Stuff to display...';
or
echo "Stuff to display...";
or
echo('Stuff to display...');


I use:

    echo('Stuff to display...');

First, it easy for me to read. Second, the processor doe not evaluate the contents.

However,

    echo 'Stuff to display...';

is probably the more "purest" route. You don't need the parenthesis.

If you have a variable in the mix, then use double quotes, such as:

    echo("Stuff to display... $stuff");


This is really a personal preference. The same issue arises with the use of require, require_once, include, and include_once. None of these are functions (just like echo) and so they do not need the parenthesis. That said... for eacho I prefer to leave the parenthesis off since it makes formatting of text more convenient. However for require, include, etc... I usually add parenthesis so that it looks like a function :)

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
Brady Mitchell wrote:
I'm sure it can be done, but without seeing your code we can't really help.
Easily solved. From the PHP manual (http://www.php.net/manual/en/function.imagick-roundcorners.php):

     <?php

       $image = new Imagick();
       $image->newPseudoImage(100, 100, "magick:rose");
       $image->setImageFormat("png");

       $image->roundCorners(5,3);
       $image->writeImage("rounded.png");
     ?>

That produces a nice transparent cornered image, as it should. However, try saving it as a JEPG instead. Set the image format to 'jpeg' and write it out as 'rounded.jpg' and you'll notice the corners are now black.

I know JPEG doesn't support transparency, that's fine. What I want is to change the black to white instead.

   -- A

--- End Message ---
--- Begin Message ---
On Thu, 2009-11-05 at 12:22 -0700, Ashley M. Kirchner wrote:

> Brady Mitchell wrote:
> > I'm sure it can be done, but without seeing your code we can't really 
> > help.
>     Easily solved.  From the PHP manual 
> (http://www.php.net/manual/en/function.imagick-roundcorners.php):
> 
>       <?php
> 
>         $image = new Imagick();
>         $image->newPseudoImage(100, 100, "magick:rose");
>         $image->setImageFormat("png");
> 
>         $image->roundCorners(5,3);
>         $image->writeImage("rounded.png");
>       ?>
> 
>     That produces a nice transparent cornered image, as it should.  
> However, try saving it as a JEPG instead.  Set the image format to 
> 'jpeg' and write it out as 'rounded.jpg' and you'll notice the corners 
> are now black.
> 
>     I know JPEG doesn't support transparency, that's fine.  What I want 
> is to change the black to white instead.
> 
>     -- A
> 


Fill the background with white before you create the corners.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
Fill the background with white before you create the corners.
   Well, I tried that, with no luck.  This is my actual code:

     $width = 150;
     $height = 150;
     $im = new Imagick('original/' . $filename);
     $im->thumbnailImage($width, $height, true);
     $im->sharpenImage(50, 1);
     $im->setImageBackgroundColor('white');
     $im->roundCorners(5, 5, 7);
     $im->setImageFormat('jpeg');
     $im->writeImage('thumbnail/' . $filename);
     $im->clear();
     $im->destroy();

--
H | It's not a bug - it's an undocumented feature.
 +--------------------------------------------------------------------
 Ashley M. Kirchner <mailto:[email protected]>   .   303.442.6410 x130
 IT Director / SysAdmin                        .     800.441.3873 x130
 Photo Craft Imaging                       .          2901 55th Street
http://www.pcraft.com ..... . . . Boulder, CO 80301, U.S.A.
--- End Message ---
--- Begin Message ---
 

> -----Original Message-----
> From: Shawn McKenzie [mailto:[email protected]] 
> Sent: Thursday, November 05, 2009 6:14 AM
> To: Daevid Vincent
> Cc: 'Allen McCabe'; 'PHP General'
> Subject: Re: [PHP] Custom function for inserting values into MySQL
> 
> Daevid Vincent wrote:
> >  
> > 
> >> -----Original Message-----
> >> From: Shawn McKenzie [mailto:[email protected]] 
> >> Sent: Wednesday, November 04, 2009 4:59 PM
> >> To: Daevid Vincent
> >> Cc: 'Allen McCabe'; 'PHP General'
> >> Subject: Re: [PHP] Custom function for inserting values into MySQL
> >>
> >> Daevid Vincent wrote:
> >>>> -----Original Message-----
> >>>> From: Shawn McKenzie [mailto:[email protected]] 
> >>>> Sent: Wednesday, November 04, 2009 6:20 AM
> >>>> To: Allen McCabe; PHP General
> >>>> Subject: Re: [PHP] Custom function for inserting values 
> into MySQL
> >>>>
> >>>> In your example, I would name my form inputs similar to name
> >>>> ="data[user_id]".
> >>>>
> >>>> Then you just pass the $_POST['data'] array to your function.
> >>>>
> >>>> -Shawn
> >>>>
> >>>> Allen McCabe wrote:
> >>>>> You raise some good points. I always name my input fields 
> >> after the
> >>>>> entity names ( eg. input type="hidden" name ="user_id" 
> >> value=" ?php
> >>>>> echo $resultRow['user_id'] ? " ).
> >>>>>
> >>>>> I suppose I am still in the phase of learning efficiency, 
> >>>> and perhaps
> >>>>> trying to 'get out it' by writing functions that I can 
> >> just call and
> >>>>> pass parameters instead of fully learning the core concepts.
> >>>>>
> >>>>> I just think functions are so damn cool :)
> >>>>>
> >>>>>
> >>>>>     I'll echo what the others have said about the 
> >>>> parameters.  For me
> >>>>>     personally, if I am passing more than three parameters 
> >>>> (sometimes even
> >>>>>     three) I rethink my function.  I'm not sure what 
> you envision
> >>>>>     using this
> >>>>>     function for, but the approach I use for forms and 
> >>>> databases is always
> >>>>>     arrays.  I get an array from my forms, I insert that 
> >>>> array into the
> >>>>>     database, and of course I fetch arrays out of the 
> >>>> database.  These are
> >>>>>     all indexed the same with the index as the field name 
> >>>> of the table so
> >>>>>     it's easy.
> >>>>>
> >>>>>
> >>>>>     --
> >>>>>     Thanks!
> >>>>>     -Shawn
> >>>>>     http://www.spidean.com
> >>>>>
> >>>>>
> >>>>>
> >>> There are pro's and cons to this type of thing. In general 
> >> that is how I do
> >>> it too, but you have to be aware of security and 
> >> organization. It's not
> >>> always smart to expose your DB field names directly so you 
> >> might want to
> >>> obscure them for some critical values. If your passing from 
> >> one controlled
> >>> function/method to another then this isnt an issue so much. 
> >>>
> >>> I also follow the ruby/rails ideal where tables are plural 
> >> names ("users")
> >>> and classes are singular names ("user.class.php"). Tables 
> >> always have fields
> >>> for 'id','created_on','timestamp','enabled'. Except in 
> >> 'glue table' cases
> >>> (1:n or n:m). Classes extend a base class which handles a 
> >> lot of the minutea
> >>> including the magic __get() and __set() routines as well as 
> >> knowing what
> >>> table they should be through introspection (ie. Their own 
> >> file name). 
> >>> No need to name your fields as arrays. $_POST is already an 
> >> array. You've
> >>> just added more complexity/dimensions. When you submit your 
> >> form just pass
> >>> $_POST to your function instead. In the function, is where 
> >> you should do any
> >>> normalizing, scrubbing and unsetting (as per good MVC ideology)...
> >>>
> >> The way I normally do it I learned from the CakePHP 
> framework which is
> >> very similar to (I think an attempt at a clone of) Rails.  
> >> I'm not sure
> >> if they do it the same way in Rails, but as you were 
> mentioning, in a
> >> Cake view of a form they use the table name as the array name
> >> (name="Users[username]").  Internally to the framework 
> this may make
> >> things easier, but imagine you have a page with 2 or more 
> forms that
> >> update different tables, or if your form had some fields that 
> >> you wanted to check after submission but are not DB fields.  
> > 
> > The $_POST array will ONLY contain the key/values for the FORM that
> > contained the submit button.
> > 
> > <form name="form_add">
> >     <input type="text" name="foo" value="bar">
> >     <input type="submit" name="action" value="Add">
> > </form>
> > 
> > 
> > <form name="form_update">
> >     <input type="text" name="bee" value="boo">
> >     <input type="submit" name="action" value="Update">
> > </form>
> > 
> > So if you click the 'Add' button, you get back: 
> >     $_POST['foo'] => 'bar', $_POST['action'] => 'Add'
> > 
> > if you click the 'Update' button, you get back: 
> >     $_POST['bee'] => 'boo', $_POST['action'] => 'Update'
> > 
> > where's the confusion? You can only submit one form on a 
> page at a time.
> > 
> >> Why would you use the entire POST array?
> > 
> > Presumably, anything in the form is of some value to your 
> database and you'd
> > want it. Otherwise why is it in the form?
> > 
> 
> I guess I was going for multiple tables and not multiple 
> forms. Consider a form that takes input for a Users table 
> and a Groups table. As for the inputs not needed by the DB,
> there are too many examples I could give
> with lots of inputs, but here is the simplest example I can think of:
> 
> username
> password
> captcha
> rememberme
> 
> Presumably you don't need the captcha or rememberme in the 
> DB.  To each his own.

Right, so that (again) is why your CONTROLLER (MVC) does the scrubbing as
previously illustrated:

function process_data($data)
{
   //perhaps you don't care about captcha and submit etc.
   unset($data['submit']); 
   unset($data['captcha']); 
   unset($data['rememberme']); 
...


If you really want 'groups' then I would suggest a prefix scheme so you can
then weed out or work with the 'groups' you wanted...

user_name
user_email
user_password
user_captcha
...
group_name
group_id
...

If you use JavaScript in your pages for pre-checking before submit, working
with 'user[name]' is a little more cumbersome than just working with
'user_name' IMHO. See this page for many examples of that headache:

http://www.php.net/manual/en/faq.html.php#faq.html.arrays

Like this is just UGLY: var foo = form['user[password]'].value;

But as you say, to each their own. :)

http://daevid.com


--- End Message ---
--- Begin Message ---
On Tue, Nov 3, 2009 at 10:17 AM, Sam Ghods <[email protected]> wrote:
> Hi all,
>
> I would like to invite everyone to a Box.net sponsored free tech talk (and
> free dinner!) in Palo Alto tonight on Goal Oriented Performance
> Optimization, given by Peter Zaitsev of Percona, the leading MySQL/LAMP
> performance consulting firm. Learn more about the event from our blog post
> <http://blog.box.net/?p=1363> and RSVP here:

got any slides?

--- End Message ---
--- Begin Message ---
You can see the slides from the talk here:

http://assets.en.oreilly.com/1/event/27/Goal%20Driven%20Performance%20Application%20Paper.pdf

----
Sam Ghods
[email protected]
Box.net - Vice President of Engineering
office: (877) 269-6736 ext. 60
fax: (650) 529-0392

On Nov 5, 2009, at 2:45 PM, Michael Shadle wrote:

On Tue, Nov 3, 2009 at 10:17 AM, Sam Ghods <[email protected]> wrote:
Hi all,

I would like to invite everyone to a Box.net sponsored free tech talk (and
free dinner!) in Palo Alto tonight on Goal Oriented Performance
Optimization, given by Peter Zaitsev of Percona, the leading MySQL/ LAMP performance consulting firm. Learn more about the event from our blog post
<http://blog.box.net/?p=1363> and RSVP here:

got any slides?


--- End Message ---
--- Begin Message ---
i am using smarty template engine at work place, following is the situation


i already have 1 template that has already been created example =
http://localhost/sites/template1.com this works fine

following is the folder structure i have for smarty on xampp

1. C:\xampp\htdocs\sites\template1.com where i have .htaccess index.php and
siteconf.php

2. C:\xampp\htdocs\sites\_templates\templates\template1


in the siteconf.php file there are all the major variables defined which are
accessed in other tpl file of the templates example in aboutus page,
contactus page etc of this template1

now i have created another template called template2 and this also has the
same structure

1. C:\xampp\htdocs\sites\template2.com where i have .htaccess index.php and
siteconf.php

2. C:\xampp\htdocs\sites\_templates\templates\template2


my question is the look and feel when i access
http://localhost/sites/template1.com and
http://localhost/sites/template2.com

is the same the only thing that needs to be done is for template2 when i
access http://localhost/sites/template2.com ONLY the header image should be
different compared to the header i have for
http://localhost/sites/template1.com this is the only change i need

i am not aware as to the php code i need to write so that when i access
http://localhost/sites/template2.com the header image changes and this new
header image remains for the entire pages of
http://localhost/sites/template2.com

presently in header.tpl of template1 is written as follows

{if strpos($Data.KEYWORD,"rv rental") === false}
<div class="header"
style="background:url(images/header_{$siteData.COUNTRY3}.gif) no-repeat top
left;">
{else}
<div class="header"
style="background:url(images/header_{$siteData.COUNTRY3}_rv.gif) no-repeat
top left;">
{/if}
</div>

so i need to chane the {if} {else} where i need to mention that if i am
accessing http://localhost/sites/template2.com then the header image should
be different.

any help will be greatly appreciated.

please advice.

thanks.

--- End Message ---
--- Begin Message ---
I'm not sure where is the problem, but can't you just define every changing 
part in your template as variables and assign them as needed from php?

If you need to change the image url, just make it a variable, like in

background:url(images/{$img})

Then you just assign the variable as needed in each file:

//template1.php
$img = 'mi_image_1.gif';
$smarty->assign( 'img', $img );

//template2.php
$img = 'mi_image_2.gif';
$smarty->assign( 'img', $img );

That way you don't need to use the {if} inside smarty and make your template 
lighter.




________________________________
De: Sudhakar <[email protected]>
Para: [email protected]
Enviado: vie,6 noviembre, 2009 00:14
Asunto: [PHP] question about smarty

i am using smarty template engine at work place, following is the situation


i already have 1 template that has already been created example =
http://localhost/sites/template1.com this works fine

following is the folder structure i have for smarty on xampp

1. C:\xampp\htdocs\sites\template1.com where i have .htaccess index.php and
siteconf.php

2. C:\xampp\htdocs\sites\_templates\templates\template1


in the siteconf.php file there are all the major variables defined which are
accessed in other tpl file of the templates example in aboutus page,
contactus page etc of this template1

now i have created another template called template2 and this also has the
same structure

1. C:\xampp\htdocs\sites\template2.com where i have .htaccess index.php and
siteconf.php

2. C:\xampp\htdocs\sites\_templates\templates\template2


my question is the look and feel when i access
http://localhost/sites/template1.com and
http://localhost/sites/template2.com

is the same the only thing that needs to be done is for template2 when i
access http://localhost/sites/template2.com ONLY the header image should be
different compared to the header i have for
http://localhost/sites/template1.com this is the only change i need

i am not aware as to the php code i need to write so that when i access
http://localhost/sites/template2.com the header image changes and this new
header image remains for the entire pages of
http://localhost/sites/template2.com

presently in header.tpl of template1 is written as follows

{if strpos($Data.KEYWORD,"rv rental") === false}
<div class="header"
style="background:url(images/header_{$siteData.COUNTRY3}.gif) no-repeat top
left;">
{else}
<div class="header"
style="background:url(images/header_{$siteData.COUNTRY3}_rv.gif) no-repeat
top left;">
{/if}
</div>

so i need to chane the {if} {else} where i need to mention that if i am
accessing http://localhost/sites/template2.com then the header image should
be different.

any help will be greatly appreciated.

please advice.

thanks.



      

--- End Message ---
--- Begin Message ---
Hello,

I am trying to get this function working but it gives me a PHP error (blank page):

function Validate_Page_Nav($LastPage, $ErrorPage) {

$trimmed = str_replace($staffroot, '', $_SERVER['SCRIPT_NAME']);
$resul = $db->query("SELECT * FROM Page_Access WHERE URI = '$trimmed'") or die("failed to get access data");
$page_access = $resul->fetch_assoc();
$URI_access = explode(",", $page_access['User_Level']);

if($_SESSION['Last_Page'] != $LastPage}) {
header("location: {$ErrorPage}?message=Unable to update user information.");
                exit();
                }

if(in_array($_SESSION['Staff_level'], $URI_access)) {
                echo "Access";
                exit();
                }else{
                echo "No Access";
//header("location: {$ErrorPage}?message=Unable to update user information.");
                exit();
                }
}

Validate_Page_Nav("user_list.php", "user_list.php");

There are parts of the code I was trying to debug.

Any help would be appreciated.

Don Wieland
D W   D a t a   C o n c e p t s
~~~~~~~~~~~~~~~~~~~~~~~~~
[email protected]
Direct Line - (949) 305-2771

Integrated data solutions to fit your business needs.

Need assistance in dialing in your FileMaker solution? Check out our Developer Support Plan at:
http://www.dwdataconcepts.com/DevSup.html

Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro 9 or higher
http://www.appointment10.com

For a quick overview -
http://www.appointment10.com/Appt10_Promo/Overview.html


--- End Message ---
--- Begin Message ---
Here's an example from the PHP website:

This demonstrates the behaviour:

<?php
function echocwd() { echo 'cwd: ', getcwd(), "\n"; }
echocwd();
register_shutdown_function('echocwd');
?>

Outputs:

cwd: /path/to/my/site/docroot/test
cwd: / 


http://php.net/manual/en/function.register-shutdown-function.php

It's a known problem but I can't see why this can't be fixed




________________________________
From: Ashley Sheridan <[email protected]>
To: Raymond Irving <[email protected]>
Cc: PHP-General List <[email protected]>
Sent: Thu, November 5, 2009 6:09:19 AM
Subject: Re: [PHP] Why getcwd() returs different results?

On Wed, 2009-11-04 at 17:36 -0800, Raymond Irving wrote: 
Hello,
>
>The getcwd() method returns a different path when called from inside a 
>shutdown function under Apache. On windows IIS it works just fine.
>
>Can't this be fixed so that the path returned is consistent across servers? 
>
>It would appear that PHP should set the CWD path before calling the shut down 
>functions
>
>__
>Raymond Irving
>
What shutdown functions are you meaning? Do you have an example which shows the 
problem?


Thanks,
Ash
http://www.ashleysheridan.co.uk

--- End Message ---
--- Begin Message ---
PHP Users,

I have a page that generates a PDF document using PHP. It takes form
data filled in by the user to fill out the PDF

When the user clicks "submit", it emails that PDF document to the
intended recipient.

However, I would like to add a "preview" function as well. But for a
variety of reasons, instead of submitting the form data through post and
re-filling all the fields with the selected data, I'd like to be able to
open a new window with an example PDF without actually submitting the form.

I think this might need JavaScript, but I'm not sure.

Is this possible?

Thank you for any advice.

-- 
Dave M G

--- End Message ---

Reply via email to