php-general Digest 25 Sep 2005 02:17:16 -0000 Issue 3701

Topics (messages 223118 through 223135):

Re: php 4 script with php 5.
        223118 by: Torgny Bjers
        223119 by: Dwayne Hottinger
        223120 by: Torgny Bjers
        223121 by: Dwayne Hottinger

LINKS
        223122 by: php . net mines
        223123 by: Gustav Wiberg
        223131 by: Rory Browne

Re: Is PHP the language for me???
        223124 by: Gustav Wiberg
        223133 by: Jasper Bryant-Greene

Cross Tabulation
        223125 by: Shaun

Using fopen('php://stdout') with apache
        223126 by: andrew morton

OT - database and indexes... but anyone please?
        223127 by: Gustav Wiberg
        223130 by: Rory Browne

How to Looking at Raw Binary Data with PHP and curl
        223128 by: Graham Anderson
        223129 by: Jasper Bryant-Greene

Re: basic user/input form questions... more validation!
        223132 by: bruce
        223134 by: Jasper Bryant-Greene

serialize
        223135 by: blackwater dev

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:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Dwayne Hottinger wrote:

>I am trying to transfer some databases and php scripts that populate them to a
>new server.  Server is running Fedora core 4 with mysql 4.x and php 5.0.5.
>Original scripts were writen with php 4.x and worked fine.  I get a PHP Notice:
> Undefined variable: return_array when running them on the new server and the
>database doesnt get populated.  Mysql database and mysql user rights seem to be
>correct.  Do I have to rewrite the script for php 5.x or should it work and I
>need to dig for another problem?  Im quite new to php and dont know quite which
>way to go for help. I hope I have posted this on the right list.
>
>ddh
>

Hello Dwayne,

This is easy enough, all you need to do is define return_array. I've
included an example here, it's mailer code, but, should illustrate what
you need to do.

function test()
{
$return_array = null;
if (...) {
    $return_array = $db->getAll("SELECT * FROM table", DB_FETCHMODE_ASSOC);
}
return $return_array;
}

That means, you need to assign or indicate that return_array exists
before you use it in something like return or other PHP function. Your
php.ini file for PHP 4 could have been more forgiving coming to these
notices/warnings.

Warm Regards,
Torgny Bjers

--- End Message ---
--- Begin Message ---
Thanks Torgny,
Im a real newby here at php scripting.  What should I put in the (....)? 
Copying the snip into the script complains about that.  This is in a db.php
which defines how another script should utilize the database.  I could copy the
db.php into an email for someone to look over.

thanks,

ddh


Quoting Torgny Bjers <[EMAIL PROTECTED]>:

> Dwayne Hottinger wrote:
>
> >I am trying to transfer some databases and php scripts that populate them to
> a
> >new server.  Server is running Fedora core 4 with mysql 4.x and php 5.0.5.
> >Original scripts were writen with php 4.x and worked fine.  I get a PHP
> Notice:
> > Undefined variable: return_array when running them on the new server and
> the
> >database doesnt get populated.  Mysql database and mysql user rights seem to
> be
> >correct.  Do I have to rewrite the script for php 5.x or should it work and
> I
> >need to dig for another problem?  Im quite new to php and dont know quite
> which
> >way to go for help. I hope I have posted this on the right list.
> >
> >ddh
> >
>
> Hello Dwayne,
>
> This is easy enough, all you need to do is define return_array. I've
> included an example here, it's mailer code, but, should illustrate what
> you need to do.
>
> function test()
> {
> $return_array = null;
> if (...) {
>     $return_array = $db->getAll("SELECT * FROM table", DB_FETCHMODE_ASSOC);
> }
> return $return_array;
> }
>
> That means, you need to assign or indicate that return_array exists
> before you use it in something like return or other PHP function. Your
> php.ini file for PHP 4 could have been more forgiving coming to these
> notices/warnings.
>
> Warm Regards,
> Torgny Bjers
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


--
Dwayne Hottinger
Network Administrator
Harrisonburg City Public Schools

--- End Message ---
--- Begin Message ---
Don't top-post (on mailing lists, always respond below the other
person's post). Please see below for my reply.

Dwayne Hottinger wrote:

>Thanks Torgny,
>Im a real newby here at php scripting.  What should I put in the (....)? 
>Copying the snip into the script complains about that.  This is in a db.php
>which defines how another script should utilize the database.  I could copy the
>db.php into an email for someone to look over.
>
>thanks,
>
>ddh
>
>
>Quoting Torgny Bjers <[EMAIL PROTECTED]>:
>
>  
>
>>Dwayne Hottinger wrote:
>>
>>    
>>
>>>I am trying to transfer some databases and php scripts that populate them to
>>>      
>>>
>>a
>>    
>>
>>>new server.  Server is running Fedora core 4 with mysql 4.x and php 5.0.5.
>>>Original scripts were writen with php 4.x and worked fine.  I get a PHP
>>>      
>>>
>>Notice:
>>    
>>
>>>Undefined variable: return_array when running them on the new server and
>>>      
>>>
>>the
>>    
>>
>>>database doesnt get populated.  Mysql database and mysql user rights seem to
>>>      
>>>
>>be
>>    
>>
>>>correct.  Do I have to rewrite the script for php 5.x or should it work and
>>>      
>>>
>>I
>>    
>>
>>>need to dig for another problem?  Im quite new to php and dont know quite
>>>      
>>>
>>which
>>    
>>
>>>way to go for help. I hope I have posted this on the right list.
>>>
>>>ddh
>>>
>>>      
>>>
>>Hello Dwayne,
>>
>>This is easy enough, all you need to do is define return_array. I've
>>included an example here, it's mailer code, but, should illustrate what
>>you need to do.
>>
>>function test()
>>{
>>$return_array = null;
>>if (...) {
>>    $return_array = $db->getAll("SELECT * FROM table", DB_FETCHMODE_ASSOC);
>>}
>>return $return_array;
>>}
>>
>>That means, you need to assign or indicate that return_array exists
>>before you use it in something like return or other PHP function. Your
>>php.ini file for PHP 4 could have been more forgiving coming to these
>>notices/warnings.
>>
>>Warm Regards,
>>Torgny Bjers
>>    
>>

The (...) was just an illustration if you had an if statement that
didn't fire, then $return_array wouldn't be defined at all. Just put
$return_array = null; in the top of the script somewhere so that it is
defined at all times, that way you don't have to worry about the actual
notice about it not being defined.

You can then also make a simple check to see if it is an array, for
instance:

if (!emtpy($return_array) && is_array($return_array)) {
    /* Code to do something with $return_array */
}

That would be a good idea if you for instance are going to iterate the
items in the array somewhere, if you don't check first, you might
attempt to iterate a variable that doesn't contain an array but null,
then PHP will yell at you for that.

You are welcome to mail the script to me privately and I can take a look
at it for you.

Warm Regards,
Torgny

--- End Message ---
--- Begin Message ---
Quoting Torgny Bjers <[EMAIL PROTECTED]>:

> Don't top-post (on mailing lists, always respond below the other
> person's post). Please see below for my reply.
>
> Dwayne Hottinger wrote:
>
> >Thanks Torgny,
> >Im a real newby here at php scripting.  What should I put in the (....)?
> >Copying the snip into the script complains about that.  This is in a db.php
> >which defines how another script should utilize the database.  I could copy
> the
> >db.php into an email for someone to look over.
> >
> >thanks,
> >
> >ddh
> >
> >
> >Quoting Torgny Bjers <[EMAIL PROTECTED]>:
> >
> >
> >
> >>Dwayne Hottinger wrote:
> >>
> >>
> >>
> >>>I am trying to transfer some databases and php scripts that populate them
> to
> >>>
> >>>
> >>a
> >>
> >>
> >>>new server.  Server is running Fedora core 4 with mysql 4.x and php 5.0.5.
> >>>Original scripts were writen with php 4.x and worked fine.  I get a PHP
> >>>
> >>>
> >>Notice:
> >>
> >>
> >>>Undefined variable: return_array when running them on the new server and
> >>>
> >>>
> >>the
> >>
> >>
> >>>database doesnt get populated.  Mysql database and mysql user rights seem
> to
> >>>
> >>>
> >>be
> >>
> >>
> >>>correct.  Do I have to rewrite the script for php 5.x or should it work
> and
> >>>
> >>>
> >>I
> >>
> >>
> >>>need to dig for another problem?  Im quite new to php and dont know quite
> >>>
> >>>
> >>which
> >>
> >>
> >>>way to go for help. I hope I have posted this on the right list.
> >>>
> >>>ddh
> >>>
> >>>
> >>>
> >>Hello Dwayne,
> >>
> >>This is easy enough, all you need to do is define return_array. I've
> >>included an example here, it's mailer code, but, should illustrate what
> >>you need to do.
> >>
> >>function test()
> >>{
> >>$return_array = null;
> >>if (...) {
> >>    $return_array = $db->getAll("SELECT * FROM table", DB_FETCHMODE_ASSOC);
> >>}
> >>return $return_array;
> >>}
> >>
> >>That means, you need to assign or indicate that return_array exists
> >>before you use it in something like return or other PHP function. Your
> >>php.ini file for PHP 4 could have been more forgiving coming to these
> >>notices/warnings.
> >>
> >>Warm Regards,
> >>Torgny Bjers
> >>
> >>
>
> The (...) was just an illustration if you had an if statement that
> didn't fire, then $return_array wouldn't be defined at all. Just put
> $return_array = null; in the top of the script somewhere so that it is
> defined at all times, that way you don't have to worry about the actual
> notice about it not being defined.
>
> You can then also make a simple check to see if it is an array, for
> instance:
>
> if (!emtpy($return_array) && is_array($return_array)) {
>     /* Code to do something with $return_array */
> }
>
> That would be a good idea if you for instance are going to iterate the
> items in the array somewhere, if you don't check first, you might
> attempt to iterate a variable that doesn't contain an array but null,
> then PHP will yell at you for that.
>
> You are welcome to mail the script to me privately and I can take a look
> at it for you.
>
> Warm Regards,
> Torgny
>
>
Torgny,

Sorry about the top posting.  Force of habit.  I'll look over the info you have
given me and get back with you.  Thanks I really appreciate the help

ddh


--
Dwayne Hottinger
Network Administrator
Harrisonburg City Public Schools

--- End Message ---
--- Begin Message ---
Hi all

is there a way to have a program detecting when a link was clicked and automatically opening another window (that can "plugged-in" in any website - running php of course)?
I know... I hate pop-ups too but a client asked for it...

Thanks

M
--- End Message ---
--- Begin Message --- ----- Original Message ----- From: "php @ net mines" <[EMAIL PROTECTED]>
To: <php-general@lists.php.net>
Sent: Saturday, September 24, 2005 4:34 PM
Subject: [PHP] LINKS


Hi all

is there a way to have a program detecting when a link was clicked and automatically opening another window (that can "plugged-in" in any website - running php of course)?
I know... I hate pop-ups too but a client asked for it...

Thanks

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

Hi!

I don't if I really understand you're question, but as I see it is done on the clientside (webbrowser)

<a href="Javascript:popup(url1, url2);">Link is clicked</a>

the popup-function in Javascript opens url1 in one window and url2 opens up in a new window.
So a tip is to consult a Javascript-mailinglist.

/G
http://www.varupiraten.se/

--- End Message ---
--- Begin Message ---
On 9/24/05, php @ net mines <[EMAIL PROTECTED]> wrote:
> Hi all
>
> is there a way to have a program detecting when a link was clicked and
> automatically opening another window (that can "plugged-in" in any website -
> running php of course)?

That would be done using client-side JS.

you would define a JS function to do the opening, and then you would
iterate through all <a> tags setting the onClick handler to call your
function.

Then again on the other hand, maybe you shouldn´t. Maybe you should
just tell your client where to stick his pop-up.  I personally
consider an unrequested pop-up to be a virus, and send it straight to
my pop-up blocker.


> I know... I hate pop-ups too but a client asked for it...
>
> Thanks
>
> M
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message --- ----- Original Message ----- From: "Emily McCall" <[EMAIL PROTECTED]>
To: <php-general@lists.php.net>
Sent: Friday, September 23, 2005 11:07 PM
Subject: [PHP] Is PHP the language for me???


I am trying to figure out whether php will help me to set up a website which is essentially just links to donwloadable material.

I have directories in place and am using flash to auto fill the directory names on to an index page, however i cant use this to access the files themselves. So I am after a language i can use to read all the file names in the directory and display them with a bit of 'niceness' onto a webpage so as they can be used as links to the files.

Thanks


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


No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.5/110 - Release Date: 2005-09-22

Hi there!

I have read some posts about this issue, but one point that is essential that I've not read about is the future! I mean, what are your plans in the future? Or what plans is it for the website. Just because it's only simple links now, it might be right to consider if for example object-oriented programming would be an issue in the future. PHP5 has that implementation, but not PHP4 so this might depend on the webserver/webhost...

This was just a spontanious thought! And yes, I just love PHP if I compare with ASP which maybe is the most relevant!? comparision.. (The two largest languages for dynamic web out there? Don't know if maybe Perl is larger though).

/G
http://www.varupiraten.se/

--- End Message ---
--- Begin Message ---
Gustav Wiberg wrote:
I have read some posts about this issue, but one point that is essential that I've not read about is the future! I mean, what are your plans in the future? Or what plans is it for the website. Just because it's only simple links now, it might be right to consider if for example object-oriented programming would be an issue in the future. PHP5 has that implementation, but not PHP4 so this might depend on the webserver/webhost...

PHP4 has OO as well. It's just an inferior and slower implementation. OO does not suit every case and you need to decide whether the additional time and work spent writing the code in OO is going to pay off in the future. If it isn't likely to, then I would suggest procedural might be a better choice.

This was just a spontanious thought! And yes, I just love PHP if I compare with ASP which maybe is the most relevant!? comparision.. (The two largest languages for dynamic web out there? Don't know if maybe Perl is larger though).

ASP isn't actually a language, it's just a framework for dynamic ("active") server pages, that provides a bunch of common objects and stuf. In classic ASP you can write VBScript or JScript, and in ASP.NET you can write VB.NET, JScript or C#. Both classic and .NET allow you to add additional languages of your choice with a bit of work.

I still prefer PHP though; just thought I'd point out the difference...

--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--- End Message ---
--- Begin Message ---
Hi,

The following article describes cross tabulation within MySQL and ends with 
a Perl application that automates the process, does anyone know of a PHP 
version?

http://dev.mysql.com/tech-resources/articles/wizard/index.html

Thanks for your advice. 

--- End Message ---
--- Begin Message ---
I'm trying to move some code that was written for the CLI to the web. It
makes extensive use fprintf() and fputs() and under Apache2 it give no
output.

The simple test case that demonstrates the problem looks like:
<?php
$fp = fopen('php://stdout', 'w');
if ($fp === false) {
    die('open failed.');
}
print "You can see this with the CLI and Apache.\n";
fputs($fp, "This only shows up on the CLI...\n");
fclose($fp);
?>

Using php-cli on FreeBSD:
  [EMAIL PROTECTED]:/home/www/multivac> php phptest.php
  You can see this with the CLI and Apache.
  This only shows up on the CLI...

Viewing the page using Apache2 and mod_php5:
  You can see this with the CLI and Apache.

Anyone know how to get a reference to the standard output to work with
the Apache2 SAPI?

Thanks,
andrew

--- End Message ---
--- Begin Message ---
Hi there!

This is not strictly PHP...

but if there's anyone out there with good knowledge of indexes, please mail me off-list.
My question: If I delete an index, what is the WORST thing that can happen?

/G
http://www.varupiraten.se/

--- End Message ---
--- Begin Message ---
I'm not an expert on databases, and I haven't a notion of mailing you
off-list, with information that could potentially benifit others as
well, but from my understanding, deleting an index(a good index that
is) would slow the db down in certain cases. Deleting a "bad index"
would speed certain operations up.

On 9/24/05, Gustav Wiberg <[EMAIL PROTECTED]> wrote:
> Hi there!
>
> This is not strictly PHP...
>
> but if there's anyone out there with good knowledge of indexes, please mail
> me off-list.
> My question: If I delete an index, what is the WORST thing that can happen?
>
> /G
> http://www.varupiraten.se/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message --- How do you display raw binary data of a file sent from a server with curl ?

When I curl a movie file with curl -l -i "path2file/file.php",I get the below output in my Terminal.

file.php:
$find = array($find1,$find2,$find3,$find4);
$replace = array($replace1,$replace2,$replace3,$replace4);

    if( $fd  = fopen($filepath, 'rb')){
     while(!feof($fd)) {
echo str_replace($find,$replace, fread($fd, $chunkSize)); //read and encode
 }
     fclose ($fd);
     exit;
   }

I want to encrypt the file with something akin to str_replace and decode it on the other side with a custom data handler Just want to make sure that I am str_replace'ing the actual data and not a representation of it :)


I am am bit new to this and deep in experimentation so any help is appreciated :)

g

--------------------
output:
ETag: 26a774b8e648b52c24f01c7277ce597f
Accept-Ranges: bytes
Content-Length: 24113190
Cache-Control: no-cache, must-revalidate
Content-Type: video/quicktime

ftypqt qt [EMAIL PROTECTED]@$edtselst-?S?mdia mdhd??׾???D?:hdlrmhlrsounapplyApple Sound Media HandlerS|minfsmhd9hdlrdhlralisappl?Apple Alias Data Handler$dinfdref alisSstbl?stsd?mp4a???Dcwave frmamp4a mp4a3esds???"[EMAIL PROTECTED]:kNXstsc?

123? 56789:;????????????????????????????????????????????????????????????????? ???????????????????????????????????????




--- End Message ---
--- Begin Message ---
Graham Anderson wrote:
How do you display raw binary data of a file sent from a server with curl ?

You can probably just use file_get_contents() if allow_url_fopen is enabled (it is by default).

For binary data, base64_encode and it's friend base64_decode allow you to encode and decode binary data in a normal ASCII string.

http://php.net/file_get_contents
http://php.net/base64_encode

I want to encrypt the file with something akin to str_replace and decode it on the other side with a custom data handler Just want to make sure that I am str_replace'ing the actual data and not a representation of it :)

str_replace is not for encryption. You might want to look at mcrypt, as using str_replace is probably just as bad as sending the unencrypted string. It's not going to be secure.

http://php.net/mcrypt

--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--- End Message ---
--- Begin Message ---
chris...

i would agree, and didn't think it made sense.. but i don't know what you
mean by the phrase 'escape all output'!! i don't see the need to escape all
output from the mysql db/tbl... so i'm not sure you meant this.

for my $0.02, i'd quote/escape all 'strings/date' vars that would be
inserted/used within the mysql db. i'd simply go ahead and insert numeric
data with no quotes. i'd thoroughly verify/validate using regex or other
methods all data before using it in the sql commands.

as fars as getting data from the mysql db/tbl, i'd simply use the sql
command/query. i'd extract the resulting data, and use the data in vars that
i've defined to be the specific data type.

this allows me to farily consistenly know what data types i'm using, and how
to then present the data to the user if i have to, as well as how to use the
vars/data in other parts of the given application.

-bruce


-----Original Message-----
From: Chris Shiflett [mailto:[EMAIL PROTECTED]
Sent: Friday, September 23, 2005 9:22 PM
To: [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Subject: Re: [PHP] basic user/input form questions... more validation!


bruce wrote:
> my question was directed towards trying to understand if you were
> meaning that an app should escape all output from the mysql db?

If you think about that for a moment, I think you'll see that it doesn't
make a lot of sense. Data that you get from a remote source is input,
not output. Data that you send to a remote source is output.

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

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

--- End Message ---
--- Begin Message ---
bruce wrote:
i would agree, and didn't think it made sense.. but i don't know what you
mean by the phrase 'escape all output'!! i don't see the need to escape all
output from the mysql db/tbl... so i'm not sure you meant this.

Output can be (among other things):

* Your script => MySQL
* Your script => User's browser
* Your script => Shell

Anything that leaves the realms of your PHP script is considered output from that script, and should be escaped.

* Output from your script to MySQL should be escaped with mysql_real_escape_string() * Output from your script to the user's browser should be escaped with htmlspecialchars() * Output from your script to the shell should be escaped with escapeshellcmd() and escapeshellarg()

[snip]
as fars as getting data from the mysql db/tbl, i'd simply use the sql
command/query. i'd extract the resulting data, and use the data in vars that
i've defined to be the specific data type.

And hopefully htmlspecialchars() it if you intend outputting it to the user's browser...

--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--- End Message ---
--- Begin Message ---
I have an app that stores evaluation scores so I have 30+ values all
within a certain range, currently in the db, each of these values has
it's own column:

Table test
   id
   user_id
   motivation
   caring
   personal_characteristics
   creativity,
   ...etc.

If the client decides they want to trap more characteristics, it
requires changes to the table structure and the table quickly gets
large with 30+ columns.  I was thinking of just compacting all of
these down to one column and then using serialize/unserialize and
storing an array of the test scores....is this the best way??

Thanks!

--- End Message ---

Reply via email to