OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
php-general Digest 15 Jul 2005 08:37:43 -0000 Issue 3568

php-general-digest-helplists.php.net
Date: Fri Jul 15 2005 - 03:37:43 CDT


php-general Digest 15 Jul 2005 08:37:43 -0000 Issue 3568

Topics (messages 218708 through 218729):

Re: Tired and feeling dumb...maths question....
        218708 by: Ezra Nugroho
        218709 by: Chris W. Parker
        218711 by: Ryan A
        218712 by: Lawrence Kennon
        218713 by: Matt Darby

captcha on bugs.php.net/report.php doesn't work
        218710 by: aRZed

404 Not Found -> refresh to directory
        218714 by: Terry Romine
        218716 by: Chris W. Parker
        218727 by: Andras Kende

Re: Big file encryption
        218715 by: Skippy

Re: cannot connect to MySQL server and not sure why
        218717 by: yanghshiqi

Re: Echo array string index?
        218718 by: yanghshiqi

Re: Dynamic Images and File Permissions
        218719 by: Brian V Bonini

array help
        218720 by: Fletcher Mattox
        218722 by: Robert Cummings
        218723 by: Richard Davey
        218725 by: Fletcher Mattox

SimpleXML doesn't work with one single XML tag line...
        218721 by: Daevid Vincent

SimpleXML returns false positives
        218724 by: Daevid Vincent

PDO Error
        218726 by: Holografix
        218728 by: Marek Kilimajer

PHP5, Tidy: node and parent node
        218729 by: Markus Fischer

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

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

attached mail follows:


The result should be between 1 - 5.

Can you clarify the following:
> Basically, I have these two fields:
> $pic_no_of_votes
> $vote_total_pts

What do they hold? Sums or individual votes?

> and this totals them up and keeps the average:
> $average_pts
>
> people vote on a scale of 1-5, so the average should be between 1-5 (right??
> am not even sure of this!)

Be clear, help us help you.

attached mail follows:


Ryan A <mailto:ryancoinpass.com>
    on Thursday, July 14, 2005 12:17 PM said:

> Hey,

Hey.

> people vote on a scale of 1-5, so the average should be between 1-5
> (right?? am not even sure of this!)

Yes.

> I was thinking of rounding it with a 2 decimal point...eg:
> round(5.045, 2)
>
> Just need to solve this and them am hitting the sack, any help
> appreciated.

Solve what? I must have missed the problem.

Chris.

attached mail follows:


> > people vote on a scale of 1-5, so the average should be between 1-5
> > (right?? am not even sure of this!)
>
> Yes.
>
> > I was thinking of rounding it with a 2 decimal point...eg:
> > round(5.045, 2)
> >
> > Just need to solve this and them am hitting the sack, any help
> > appreciated.
>
> Solve what? I must have missed the problem.

Oops, sorry guys...girlfriends on holiday so have not had my "medicine"
:-)
and am also braindead right now...

basically...how do I get the average?

 $pic_no_of_votes --- > holds the total number of votes (eg: 212)
 $vote_total_pts ----> holds the total points from all those votes (eg:
1027)

how do i get the average down to something like: 3.23 or 1.02 or 4.11 etc

Thanks,
Ryan

attached mail follows:


> basically...how do I get the average?
>
> $pic_no_of_votes --- > holds the total number of votes (eg: 212)
> $vote_total_pts ----> holds the total points from all those votes (eg:
> 1027)
>
> how do i get the average down to something like: 3.23 or 1.02 or 4.11 etc

average = 1027 (total pts) / 212 (number of votes) = 4.84 (rounded)

attached mail follows:


$average = round(($votes/$pts),2);

;)

Ryan A wrote:

>>>people vote on a scale of 1-5, so the average should be between 1-5
>>>(right?? am not even sure of this!)
>>>
>>>
>>Yes.
>>
>>
>>
>>>I was thinking of rounding it with a 2 decimal point...eg:
>>> round(5.045, 2)
>>>
>>>Just need to solve this and them am hitting the sack, any help
>>>appreciated.
>>>
>>>
>>Solve what? I must have missed the problem.
>>
>>
>
>
>Oops, sorry guys...girlfriends on holiday so have not had my "medicine"
>:-)
>and am also braindead right now...
>
>basically...how do I get the average?
>
> $pic_no_of_votes --- > holds the total number of votes (eg: 212)
> $vote_total_pts ----> holds the total points from all those votes (eg:
>1027)
>
>how do i get the average down to something like: 3.23 or 1.02 or 4.11 etc
>
>Thanks,
>Ryan
>
>
>

attached mail follows:


hy!

i have a simple problem when i try to report a bug. the captcha doesn't
work. the script doesn't send any output at all. so i think my
bug-report must wait ...
is anybody else expieriencing this problem?

attached mail follows:


I have a website that has several hundred agents in a mysql database. The client wants to be able to enter the domain.com/agentname and be redirected to a standard page where we show the agent information. An example would be an agent named John Smith whose agentname would be jsmith. So the user would enter domain.com/jsmith and get the agent's profile.

I tried initially to dummy up a 404 page, where if the link was like: domain.com/jsmith that it would parse the agent name and pass it through to domain.com/agent_profile.php?agent=jsmith. It failed to work, ending up with a recursive call to the 404 page and getting hung.

Right now, I have directories set up for each agent, with an index.php that does the redirect. It's really getting to be a mess with so many directories.

I need to be able to check the mysql database for the agent name, and if found, do a redirect (header("Location: agent_profile.php?agent=agentID") and if not, continue to a standard 404 error page, or a "sorry not found" page.

I think my question is: is there an easy way to use a 404 page written in php to capture the parameters from the missing page request and test against a db, resulting in either a valid page redirect or a not found redirect?

Terry

attached mail follows:


Terry Romine <mailto:terry_romineearthlink.net>
    on Thursday, July 14, 2005 1:52 PM said:

> I have a website that has several hundred agents in a mysql database.
> The client wants to be able to enter the domain.com/agentname and be
> redirected to a standard page where we show the agent information.

[snip/]

> I think my question is: is there an easy way to use a 404 page
> written in php to capture the parameters from the missing page
> request and test against a db, resulting in either a valid page
> redirect or a not found redirect?

Never tried it, but this is super easy to do with mod_rewrite and
.htaccess.

## DEFINE REWRITE RULES
RewriteEngine on
RewriteRule ^([\w-]+)$ yourpage.php?agent=$1

Should work (maybe).

Chris.

attached mail follows:


-----Original Message-----
From: Terry Romine [mailto:terry_romineearthlink.net]
Sent: Thursday, July 14, 2005 3:52 PM
To: php
Subject: [PHP] 404 Not Found -> refresh to directory

I have a website that has several hundred agents in a mysql database. The
client wants to be able to enter the domain.com/agentname and be redirected
to a standard page where we show the agent information. An example would be
an agent named John Smith whose agentname would be jsmith. So the user would
enter domain.com/jsmith and get the agent's profile.

I tried initially to dummy up a 404 page, where if the link was like:
domain.com/jsmith that it would parse the agent name and pass it through to
domain.com/agent_profile.php?agent=jsmith. It failed to work, ending up with
a recursive call to the 404 page and getting hung.

Right now, I have directories set up for each agent, with an index.php that
does the redirect. It's really getting to be a mess with so many
directories.

I need to be able to check the mysql database for the agent name, and if
found, do a redirect (header("Location: agent_profile.php?agent=agentID")
and if not, continue to a standard 404 error page, or a "sorry not found"
page.

I think my question is: is there an easy way to use a 404 page written in
php to capture the parameters from the missing page request and test against
a db, resulting in either a valid page redirect or a not found redirect?

Terry

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

.htaccess:
RewriteEngine on
RewriteRule ^([\w-]+)$ index.php/$1

index.php:
<?php
$uriparams = explode("/",$REQUEST_URI);
$uriparams = explode("?",$REQUEST_URI);
$agent = $uriparams[0];
$agent = eregi_replace("/","",$agent);

// Select from mysql where agent = agent etc.. etc..

echo ("Location: agent_profile.php?agent=".$agent);
?>

Best regards,

Andras Kende
http://www.kende.com

attached mail follows:


On Thu, 14 Jul 2005 16:24:25 +0200 "david forums" <dforumsvieonet.com>
wrote:
> Not at all cause the chunk are beeing free every time it is write in
> the file.
> so it does not excide the amount you set.

What I meant was that if the encryption algorithm inserts some magic info
at the beginning of every chunk, then simply concatenating several
encrypted pieces won't produce a valid piece, the same way concatenating
several zip files won't produce a big valid zip file.

--
Skippy - Romanian Web Developers - http://ROWD.ORG

attached mail follows:


Make sure that your ip is granted too.

 
 
 
Best regards,
Shiqi Yang
-----Original Message-----
From: Bruce Gilbert [mailto:webguyncgmail.com]
Sent: Thursday, July 14, 2005 11:27 PM
To: php-generallists.php.net
Subject: [PHP] cannot connect to MySQL server and not sure why

I am having trouble connecting to MySQL server through a PHP script
and I am not sure why.

the error I receive is:

Warning: mysql_pconnect(): Access denied for user:
'bruceg_webmaster69.90.88.155' (Using password: YES) in
/hsphere/local/home/bruceg/inspired-evolution.com/search/include/connect.php
on line 6
Cannot connect to database, check if username, password and host are
correct.

trying to connect with the following script:

?php
        $database="bruceg_search";
        $mysql_user = "bruceg_webmaster";
        $mysql_password = " password";
        $mysql_host = "server-10.existhost.com";
        mysql_pconnect ($mysql_host, $mysql_user, $mysql_password);
        if (!$success)
                die ("<b>Cannot connect to database, check if username,
password and
host are correct.</b>");
    $success = mysql_select_db ($database);
        if (!$success) {
                print "<b>Cannot choose database, check if database name is
correct.";
                die();
        }
?>

I double checked the database and I have created a database called
bruceg_search and added a user called bruceg_webmaster with all of the
editing privileges. Of course 'password' is changes with the password
used to connect in the actual script. and I double checked that to be
correct as well. Any suggestions?

--
::Bruce::

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

attached mail follows:


Yeah, you can use foreach.
But *may be* you just find sth called array_keys().

 
 
 
Best regards,
Shiqi Yang

-----Original Message-----
From: Joe Harman [mailto:cjharmangmail.com]
Sent: Thursday, July 14, 2005 4:45 PM
To: php-generallists.php.net
Subject: Re: [PHP] Re: Echo array string index?

Hey Matt,
 you can print out the contents of your array by using print_r($arr)
 but more useful is using this
 foreach ($arr as $key => $value)
 {
 echo "Key : ".$key." Value : ".$value;
}
 Adios
Joe
 On 7/13/05, Adam Hubscher <webmasteroffbeat-zero.net> wrote:
>
> Matt Darby wrote:
> > I have an array setup as such: *$arr['generated text']='generated
> number';*
> >
> > What would be the best way to echo the key in a loop?
> > Seems pretty easy but I've never attempted...
> >
> > Thanks all!
> > Matt Darby
> >
> I'm not sure I understand the question.
>
> You could do foreach($arr as $key => $value) { print($key); }.
>
> There are also a number of functions that get the current key on the
> array's pointer:
>
> http://us2.php.net/manual/en/function.key.php
> http://us2.php.net/manual/en/function.array-keys.php
>
> But once again, it really comes down to what exactly it is you want to
> do...
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
Joe Harman
---------
Do not go where the path may lead, go instead where there is no path and
leave a trail. - Ralph Waldo Emerson

attached mail follows:


On Thu, 2005-07-14 at 12:09, Adam Hubscher wrote:
> My questions are this:
>
> A) Is there any way to set the permissions on the file on creation of
> the image?

Set umask 002 on the user php is running as.

--

s/:-[(/]/:-)/g

Brian GnuPG -> KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu
======================================================================
gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC
Key Info: http://gfx-design.com/keys
Linux Registered User #339825 at http://counter.li.org

attached mail follows:


How does one represent a MySQL table as a two dimensional array
using the column names as one of the indices? My naive attempt
went something like this:

        while ($row = mysqli_fetch_assoc($result))
                $table[] = $row;

but that generated this error;

        Fatal error: [] operator not supported for strings

Ok. So then I try to explicitly assign each row, like this:

        while ($row = mysqli_fetch_assoc($result))
                $table[$i++] = $row;

While that generates no error, $table contains nothing useful when
I'm done. So then I try to assign each row and column, like this:

        while ($row = mysqli_fetch_assoc($result)) {
                foreach ( $row as $col => $val)
                        $table[$i][$col] = $val;
                $i++;
        }

And that got me this error:

        Fatal error: Cannot use string offset as an array

So clearly my understanding of PHP arrays is lacking.
Please help.

Thanks
Fletcher

attached mail follows:


Did you bother to initialize $table as an array() or are you another
lazy slob of a programmer that expects the engine to read your mind
(cluttered as that may be)?

Cheers,
Rob.

On Thu, 2005-07-14 at 18:33, Fletcher Mattox wrote:
> How does one represent a MySQL table as a two dimensional array
> using the column names as one of the indices? My naive attempt
> went something like this:
>
> while ($row = mysqli_fetch_assoc($result))
> $table[] = $row;
>
> but that generated this error;
>
> Fatal error: [] operator not supported for strings
>
> Ok. So then I try to explicitly assign each row, like this:
>
> while ($row = mysqli_fetch_assoc($result))
> $table[$i++] = $row;
>
> While that generates no error, $table contains nothing useful when
> I'm done. So then I try to assign each row and column, like this:
>
> while ($row = mysqli_fetch_assoc($result)) {
> foreach ( $row as $col => $val)
> $table[$i][$col] = $val;
> $i++;
> }
>
> And that got me this error:
>
> Fatal error: Cannot use string offset as an array
>
> So clearly my understanding of PHP arrays is lacking.
> Please help.
>
> Thanks
> Fletcher
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

attached mail follows:


Hello Fletcher,

Thursday, July 14, 2005, 11:33:36 PM, you wrote:

FM> while ($row = mysqli_fetch_assoc($result))
FM> $table[] = $row;

FM> but that generated this error;

FM> Fatal error: [] operator not supported for strings

The above WILL work providing that (1) $table hasn't been set
elsewhere in your script as a string, or (2) $table has been set as an
array ($table = array()) prior to being used.

Best regards,

Richard Davey
--
 http://www.launchcode.co.uk - PHP Development Services
 "I do not fear computers. I fear the lack of them." - Isaac Asimov

attached mail follows:


Rob writes:

> Did you bother to initialize $table as an array() or are you another
> lazy slob of a programmer that expects the engine to read your mind
> (cluttered as that may be)?

Bingo.

You seem to have no trouble reading my mind, why can't php? :)
Years of perl programming has promoted a certain sloth in my character.
It manifests in many different insidious forms. Ask my wife.

Thanks!
Fletcher "lazy slob" Mattox

attached mail follows:


Maybe I'm missing something about XML specifications, but this doesn't seem
right to me.

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

Here is a code fragment I use:

$xml = simplexml_load_string($returnData);
var_dump($xml);
if (is_object($xml))
{
        //first lets make sure we didn't get an <ERROR>
        if ($xml->error)
        {
                echo "An ERROR was encountered\n";
                echo "CODE: ".((string)$xml->error->code)."\n";
                echo "STRING: ".((string)$xml->error->string)."\n";
                exit;
        }

        ...
}

I have my XML setup such that if there is an error, I return:

        <?xml version="1.0" encoding="iso-8859-1" ?>
        <error code="tbd" string="user not found." />

But simple XML will not detect this as illustrated by var_dump($xml)

        object(SimpleXMLElement)#1 (0) {
        }

However, if I change my output to be:

        <?xml version="1.0" encoding="iso-8859-1" ?>
        <error>
          <code>tbd</code>
          <string>user not found with those credentials.</string>
        </error>

Then I get...

        object(SimpleXMLElement)#1 (2) {
          ["code"]=>
          string(3) "tbd"
          ["string"]=>
          string(38) "user not found."
        }

Notice also that my object is not nested inside an ["error"] as I would
expect it to be.
So I would expect to get this (in BOTH cases actually):

object(SimpleXMLElement)#1 (1) {
  ["error"]=>
        object(SimpleXMLElement)#1 (2) {
          ["code"]=>
          string(3) "tbd"
          ["string"]=>
          string(38) "user not found."
        }
}

More useful information:

rootDAEVID:/lockdown/includes/api# php -v
PHP 5.0.3 (cli) (built: Jul 11 2005 12:33:48)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies
    with Zend Extension Manager v1.0.6, Copyright (c) 2003-2004, by Zend
Technologies
    with Zend Optimizer v2.5.7, Copyright (c) 1998-2004, by Zend
Technologies

attached mail follows:


Am I just completely missing something with this SimpleXML functions?

Something else I noticed that seems broken to me...
I can change the "if ($xml->error)" line to "if ($xml->foo)"
and I still get the text echo'd to the screen. ?!!?!

If I change it to "if ($xml->error->code)" then I don't get the text.
Which sort of makes sense, since there is
no "$xml->error" object in the var_dump.

"if (is_object($xml->error))" also return true and outputs the text.

object(SimpleXMLElement)#1 (2) {
  ["code"]=>
  string(3) "tbd"
  ["string"]=>
  string(38) "user not found."
}

The way that I've hacked around this for now is
"if ( (string)$xml->code != '')"

Ideas on what I'm doing wrong, or is this function just completely bunk.

> -----Original Message-----
> Here is a code fragment I use:
>
> $xml = simplexml_load_string($returnData);
> var_dump($xml);
> if (is_object($xml))
> {
> //first lets make sure we didn't get an <ERROR>
> if ($xml->error)
> {
> echo "An ERROR was encountered\n";
> echo "CODE: ".((string)$xml->error->code)."\n";
> echo "STRING: ".((string)$xml->error->string)."\n";
> exit;
> }
>
> ...
> }

attached mail follows:


Hi. When using this example from
http://netevil.org/talks/index.php?t=pdo&s=20, the site of pdo's author I
have this error:

Fatal error: Call to a member function fetchAll() on a non-object in
/www/home/testes/pdo_my1.php on line 17

$dbh = new PDO('mysql:host=localhost;dbname=dbtest', 'user', 'pass');
$stmt = $dbh->query("SELECT * FROM foo");
$rows = $stmt->fetchAll();
$count = count($rows);
foreach ($rows as $row) {
    print_r($row);
}
$stmt = null;

Wht's wrong with the example?

Greetings
holografix

attached mail follows:


Holografix wrote:
> Hi. When using this example from
> http://netevil.org/talks/index.php?t=pdo&s=20, the site of pdo's author I
> have this error:
>
> Fatal error: Call to a member function fetchAll() on a non-object in
> /www/home/testes/pdo_my1.php on line 17
>
>
> $dbh = new PDO('mysql:host=localhost;dbname=dbtest', 'user', 'pass');
> $stmt = $dbh->query("SELECT * FROM foo");

what does print_r($stmt); print here?

> $rows = $stmt->fetchAll();
> $count = count($rows);
> foreach ($rows as $row) {
> print_r($row);
> }
> $stmt = null;
>
> Wht's wrong with the example?
>
> Greetings
> holografix
>

attached mail follows:


Hi,

I'm trying to figure out the parent of a node in tidy. As it seems to me
there's no property/method available for this.

I really want to avoid traversing the whole document and build the
relation myself; this is getting pretty slow.

Any ideas on this?

thanks,
- Markus