php-general Digest 19 Jun 2004 23:38:14 -0000 Issue 2831

Topics (messages 188636 through 188672):

Re: triggering scripts through apache configuration
        188636 by: Marek Kilimajer

PHP DL and UL Speed Test
        188637 by: Anton Krall

sessions & cookies
        188638 by: Scott Taylor
        188639 by: Michael Sims

Re: building php 4.3.7 with sablot 1.0.1 and gcc 3.3.3
        188640 by: Per Jessen

mod_rewrite Issues
        188641 by: Stephen Craton
        188654 by: Michal Migurski

Re: UPLOAD scripts refuse to function
        188642 by: Nick W

how to iterate over fields names with mysql_fetch_assoc
        188643 by: grahama.siren.cc
        188648 by: Robin Vickery
        188657 by: grahama.siren.cc

variable question
        188644 by: water_foul
        188645 by: Robin Vickery
        188646 by: water_foul
        188647 by: water_foul

umm i am confused...
        188649 by: water_foul
        188650 by: Adrian
        188651 by: water_foul

Regular Expressions Tester/designer
        188652 by: Al
        188653 by: Joel Kitching

cookie question
        188655 by: water_foul
        188656 by: Joel Kitching
        188658 by: water_foul
        188660 by: water_foul
        188661 by: water_foul
        188662 by: Joel Kitching
        188664 by: water_foul
        188665 by: Joel Kitching
        188666 by: water_foul

Why is PHP Segmentation Faulting?!?!?!?
        188659 by: Jeff

Why is PHP Segmentation Faulting?!?!?!?  --- ANOTHER HINT
        188663 by: Jeff

quick question
        188667 by: water_foul
        188668 by: water_foul

cookie
        188669 by: water_foul

cookie question...
        188670 by: water_foul

Re: Regular Expression - it works but uses way too much memory ?
        188671 by: Ulrik S. Kofod

hellllppp my php kills the browser
        188672 by: water_foul

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 --- Chris Wagner wrote --- napísal::
hello,

wondering how you might go about triggering PHP scripts from an apache
configuration file, for certain events...

for instance, how might i trigger a script whenever a file was accessed
within a given directory.  and, would it be possible to know which file
was accessed?

if the above is possible, could you also trigger different scripts for
when a "file download begins" and when a "file download finishes"?

thanks.


Seems you want mod_rewrite. Lets say you have /download/ directory, then you put this in /download/.htaccess


RewriteEngine on
RewriteRule ^.*$    handler.php

handler.php will be the script that will be triggered for all requests to /download/ directory, you can find out the real request from $_SERVER['REQUEST_URI'], do whatever magic you need to do. But don't forget that you will have to output the file yourself, in handler.php, including the right headers.
--- End Message ---
--- Begin Message ---
Guys... Anybody knows of a php script that can help measure download and
upload speed tests?

Thank you for any comments.

Anton Krall

--- End Message ---
--- Begin Message ---
How exactly do sessions work? I've heard that if cookies are disabled that a session will then pass it's variables in the url (through GET). Yet when I manually disable cookies none of my pages work (because the $_SESSION variables do not seem to be working).


Any ideas?

Best Regards,

Scott Taylor


--- End Message ---
--- Begin Message ---
Scott Taylor wrote:
> How exactly do sessions work?  I've heard that if cookies are disabled
> that a session will then pass it's variables in the url (through GET).
> Yet when I manually disable cookies none of my pages work (because the
> $_SESSION variables do not seem to be working).

The variables themselves aren't passed, only a session ID, and that is only
passed through GET/POST if transparent SID support is enabled (it is
disabled by default).  You can change the "session.use_trans_sid" setting in
your php.ini file or if your server supports .htaccess you can create one
and add "php_flag session.use_trans_sid on" to it.  For more information see
the manual: http://www.php.net/manual/en/ref.session.php

--- End Message ---
--- Begin Message ---
Per Jessen wrote:

> I'm trying to build php 4.3.7 with sablot 1.0.1 and expat 1.95.7 - I'm using
> gcc3.3.3.
> sablot and expat built fine, but when I build/link php:
> /usr/lib/libsablot.so: undefined reference to `operator new[](unsigned)'
[snip]

After some research, I can answer my own question - I did try out gcc3.3.2 and
gcc 3.3.4 before I found the following:

http://archive.gingerall.cz/archives/public/sablot2002/msg00517.html

>I have been having the same Sablotron/gcc3/etc.. linking problem and solved the
>issue by adding a compiler instruction/reference to the standard C++
>libraries/symbols by adding the following LDFLAGS option to my Apache
>configure statement:
> 
>LDFLAGS='-lstdc++'

Might it not be a Good Thing to add this and/or an explanation to the build
instructions (unless it's already there, in which case it would be a Good Thing
for me to read them).


/Per Jessen, Zurich

--- End Message ---
--- Begin Message ---
This isn't exactly a PHP issue, but they seem to go rather hand in hand...
 
Right now I'm just running my own apache server on my computer and I'm
trying to protect my scripts using mod_rewrite. I uncommented all the
mod_rewrite lines in the apache configuration file and restarted it all. I
got no errors doing this, so I assume it compiled fine.
 
The problem is, I can put a rewrite rule in the httpd.conf file or a
.htaccess file but it never rewrites any URLs... For example:
 
RewriteEngine on
RewriteRule ^/woot$ /beta
 
I tried that as a test in a .htaccess file and put it in my root C:\htdocs
folder. I went to http://localhost/woot but it didn't show anything, gave me
a 404. I went to http://localhost/beta and it showed exactly what it was
supposed to. I assume it's something I'm doing wrong with my code, but I've
followed this sitepoint article to the point pretty much. Any help here
would be greatly appreciated...
 
Thanks,
Stephen Craton
http://www.melchior.us <http://www.melchior.us/> 
 

--- End Message ---
--- Begin Message ---
> This isn't exactly a PHP issue, but they seem to go rather hand in
> hand...
>
> Right now I'm just running my own apache server on my computer and I'm
> trying to protect my scripts using mod_rewrite. I uncommented all the
> mod_rewrite lines in the apache configuration file and restarted it all. I
> got no errors doing this, so I assume it compiled fine.
>
> The problem is, I can put a rewrite rule in the httpd.conf file or a
> .htaccess file but it never rewrites any URLs... For example:
>
> RewriteEngine on
> RewriteRule ^/woot$ /beta

You may need to add a RewriteCond:
        http://httpd.apache.org/docs/mod/mod_rewrite.html#RewriteCond


---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca            http://mike.teczno.com/contact.html

--- End Message ---
--- Begin Message ---
On June 18, 2004 10:26 pm, cory wrote:
> ok, someone please lend me some advice here.  I am trying create a upload
> form for my site.
>
> Sure that sounds easy right?  well I have tried at least 10 different php
> scripts as well as a handful of cgi.  Same resuls with everyone of
> them...nothing in my specified tmp folder.  After contactig my host so many
> times, they know my name by voice, I have made no progress and here I sit
> without a very neccessary aspect of our website.  Anyone have any idea on
> this...is there something server side that would prohibit me from executing
> my upload scripts?  (yes chmod the folder...done)
>
> I have no problem with ANY other cgi or php script that I have used.
>
> Thanks in advance for any insight...

Are uploads enabled in php.ini?

>
> -Cory

--- End Message ---
--- Begin Message ---
How do I iterate over fields when I perform the below script:


each row has: artist_name,urlPath,biography as fields

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

# if the current field name  is 'artist_name', do something
switch($GetCurrentFieldNameintheCurrentRow)
 {
        case $row[ 'field name is now: artist_name']
        //do something
        break;
 }

If I write the below code, I only get the first field name of each row...which makes sense
In this case, I get 'artist_name'


while ($row = mysql_fetch_assoc($result))
        {
        $fieldName= key($row);
        echo 'fieldName is: '.$fieldName."\n";
        }


many thanks :)

--- End Message ---
--- Begin Message ---
On Sat, 19 Jun 2004 13:25:54 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> 
> How do I iterate over fields when I perform the below script:
...
> If I write the below code, I only get the first field name of each
> row...which makes sense
> In this case, I get 'artist_name'
> 
> while ($row = mysql_fetch_assoc($result))
>        {
>        $fieldName= key($row);
>        echo 'fieldName is: '.$fieldName."\n";
>        }

<?php
while ($row = mysql_fetch_assoc($result)) {
   foreach ($row as $fieldName => $fieldValue) {
      echo 'fieldName is: '.$fieldName."\n";
      echo 'fieldValue is: '.$fieldValue."\n";
   }
}
?>

--- End Message ---
--- Begin Message ---
thanks...that is what  I  had used previously :)

Another php coder had given me a hint that I could just take each incoming row on the fly with $row['artist_name'] without reading everything into an array:

What I had previously was:
while ($row = mysql_fetch_assoc($result))
{
  $playlist[] = $row;  //read in entire array before doing anything
 }

# get row count
$c= count($playlist);

for ($x = 0; $x < $c; $x++)
{
  foreach($playlist[$x] as $key => $val)
  {
    switch ($key)
        {
        # if key name is 'artist_name', do something
        case 'artist_name' :
        
        break;

        # if key name is 'urlPath', do something
        case 'urlPath' :
        
        break;
        }
}
}

is there a way to grab the info on the fly without reading the $result into an array ?

many thanks as I am on my 3rd week with php....



On Jun 19, 2004, at 1:45 PM, Robin Vickery wrote:

On Sat, 19 Jun 2004 13:25:54 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

How do I iterate over fields when I perform the below script:
...
If I write the below code, I only get the first field name of each
row...which makes sense
In this case, I get 'artist_name'

while ($row = mysql_fetch_assoc($result))
       {
       $fieldName= key($row);
       echo 'fieldName is: '.$fieldName."\n";
       }

<?php while ($row = mysql_fetch_assoc($result)) { foreach ($row as $fieldName => $fieldValue) { echo 'fieldName is: '.$fieldName."\n"; echo 'fieldValue is: '.$fieldValue."\n"; } } ?>

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


--- End Message ---
--- Begin Message ---
is there a way to use one variable to create another?
Example
$poo=1
and i want
$lie1
OR
$poo=2
and i want
$lie2

--- End Message ---
--- Begin Message ---
On Sat, 19 Jun 2004 14:25:27 -0600, water_foul
<[EMAIL PROTECTED]> wrote:
> 
> is there a way to use one variable to create another?
> Example
> $poo=1
> and i want
> $lie1
> OR
> $poo=2
> and i want
> $lie2

If I understand you right, you want:

  ${'lie' . $poo}

when $poo is 1, that will give you $lie1, and when $poo is 2, it'll
give you $lie2.

You're almost certain to be better off using arrays though,,,

  -robin

--- End Message ---
--- Begin Message ---
sorry i didn't say this before but please hurry i need this to finish a php
script

--- End Message ---
--- Begin Message ---
Thanks oh so much

"Robin Vickery" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Sat, 19 Jun 2004 14:25:27 -0600, water_foul
> <[EMAIL PROTECTED]> wrote:
> >
> > is there a way to use one variable to create another?
> > Example
> > $poo=1
> > and i want
> > $lie1
> > OR
> > $poo=2
> > and i want
> > $lie2
>
> If I understand you right, you want:
>
>   ${'lie' . $poo}
>
> when $poo is 1, that will give you $lie1, and when $poo is 2, it'll
> give you $lie2.
>
> You're almost certain to be better off using arrays though,,,
>
>   -robin

--- End Message ---
--- Begin Message ---
i get the following error
----------------------------
Parse error: parse error, unexpected T_STRING in
C:\Inetpub\localroot\aichlmayr.net\sites\aaron\module\personal\links.php on
line 21
----------------------------------
for the following code and i cant figure out why (you may need to maxamise
to read it right)
--------------------------------------------
<?php
//the function for adding new addresses
function loop_new_address($loopnum,$url,$name){
//the ${'link' . $loopnum} says put $link and add $loopnum to the end
if(isset(${'link' . $loopnum . '})){
loop_new_adderss($loopnum+1,$url,$name);
};
else{
setcookie("link" . $loopnum . "",$url,time()+3600*200);
setcookie("name" . $loopnum . "",$name,time()+3600*200);
print(<a href=$url>$name</a> was added);
};
};
if(isset($_GET[new])) {
loop_new_address(1,$_GET[name],$_GET[url]);
};
print(<table>);
print(<tr><td><form Method="GET"
action="module/personal/delete.php">delete</td></tr>);
//write code
$writenum=1;
while(isset(${'link' . $writenum . ''}));
print(<a href=${'link' . $writenum . ''}>${'name' . $writenum . ''}</a>);
};
include('links.htm')
?>
<tr><td><input type=submit value="Delete Checked"></form></td></tr>
</table>
<table>
<tr><td><form METHOD="GET" ACTION="module/personal/links.php"><input
type=hidden name=new value=1></td><td></td></tr>
<tr><td>Site name</td><td><INPUT TYPE=text NAME="name" VALUE=""></td></tr>
<tr><td>site url (if it is not on this site it MUST contain
"http://";)</td><td><INPUT TYPE=text NAME="url" VALUE=""></td></tr>
<tr><td></td><td><INPUT TYPE="SUBMIT" VALUE="Continue"></form></td></tr>
</table>
-------------------------------------------------

--- End Message ---
--- Begin Message ---
action="module/personal/delete.php">delete</td></tr>);
replace this with
action="module/personal/delete.php">delete</td></tr>;

and remove the ; after } - it's ugly and useless ;)

--- End Message ---
--- Begin Message ---
I figured it out
"Water_foul" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> i get the following error
> ----------------------------
> Parse error: parse error, unexpected T_STRING in
> C:\Inetpub\localroot\aichlmayr.net\sites\aaron\module\personal\links.php
on
> line 21
> ----------------------------------
> for the following code and i cant figure out why (you may need to maxamise
> to read it right)
> --------------------------------------------
> <?php
> //the function for adding new addresses
> function loop_new_address($loopnum,$url,$name){
> //the ${'link' . $loopnum} says put $link and add $loopnum to the end
> if(isset(${'link' . $loopnum . '})){
> loop_new_adderss($loopnum+1,$url,$name);
> };
> else{
> setcookie("link" . $loopnum . "",$url,time()+3600*200);
> setcookie("name" . $loopnum . "",$name,time()+3600*200);
> print(<a href=$url>$name</a> was added);
> };
> };
> if(isset($_GET[new])) {
> loop_new_address(1,$_GET[name],$_GET[url]);
> };
> print(<table>);
> print(<tr><td><form Method="GET"
> action="module/personal/delete.php">delete</td></tr>);
> //write code
> $writenum=1;
> while(isset(${'link' . $writenum . ''}));
> print(<a href=${'link' . $writenum . ''}>${'name' . $writenum . ''}</a>);
> };
> include('links.htm')
> ?>
> <tr><td><input type=submit value="Delete Checked"></form></td></tr>
> </table>
> <table>
> <tr><td><form METHOD="GET" ACTION="module/personal/links.php"><input
> type=hidden name=new value=1></td><td></td></tr>
> <tr><td>Site name</td><td><INPUT TYPE=text NAME="name" VALUE=""></td></tr>
> <tr><td>site url (if it is not on this site it MUST contain
> "http://";)</td><td><INPUT TYPE=text NAME="url" VALUE=""></td></tr>
> <tr><td></td><td><INPUT TYPE="SUBMIT" VALUE="Continue"></form></td></tr>
> </table>
> -------------------------------------------------

--- End Message ---
--- Begin Message --- Anyone know of a good regular expressions tester/designer for php coding running windows.

I've looked at the Rad Software Regular Expressions Designer and it looks pretty good except that it is intended for .net and it really doesn't seem to be entirely PCRE compatible.

Thanks....
--- End Message ---
--- Begin Message ---
On Sat, 19 Jun 2004 17:23:53 -0400, Al <[EMAIL PROTECTED]> wrote:
> 
> Anyone know of a good regular expressions tester/designer for php coding
> running  windows.
> 
> I've looked at the Rad Software Regular Expressions Designer and it
> looks pretty good except that it is intended for .net and it really
> doesn't seem to be entirely PCRE compatible.
> 
> Thanks....
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

You could always just use a simple online one like...

http://www.quanetic.com/regex.php

--- End Message ---
--- Begin Message ---
whats wrong with this script
setcookie('link' . $loopnum . '',$url,time()+3600*200);
setcookie('name' . $loopnum . '',$name,time()+3600*200);
it doesn't write the cookies

--- End Message ---
--- Begin Message ---
Did you do this before you sent some outut?  This would send headers,
therefore causing you to not be able to send the "cookie" header.

On Sat, 19 Jun 2004 15:51:00 -0600, water_foul
<[EMAIL PROTECTED]> wrote:
> 
> whats wrong with this script
> setcookie('link' . $loopnum . '',$url,time()+3600*200);
> setcookie('name' . $loopnum . '',$name,time()+3600*200);
> it doesn't write the cookies
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

--- End Message ---
--- Begin Message ---
all i did was a function and some conditionals
"Joel Kitching" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Did you do this before you sent some outut?  This would send headers,
> therefore causing you to not be able to send the "cookie" header.
>
> On Sat, 19 Jun 2004 15:51:00 -0600, water_foul
> <[EMAIL PROTECTED]> wrote:
> >
> > whats wrong with this script
> > setcookie('link' . $loopnum . '',$url,time()+3600*200);
> > setcookie('name' . $loopnum . '',$name,time()+3600*200);
> > it doesn't write the cookies
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >

--- End Message ---
--- Begin Message ---
lemme clarify what i mean by function, i created a function
"Water_foul" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> all i did was a function and some conditionals
> "Joel Kitching" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Did you do this before you sent some outut?  This would send headers,
> > therefore causing you to not be able to send the "cookie" header.
> >
> > On Sat, 19 Jun 2004 15:51:00 -0600, water_foul
> > <[EMAIL PROTECTED]> wrote:
> > >
> > > whats wrong with this script
> > > setcookie('link' . $loopnum . '',$url,time()+3600*200);
> > > setcookie('name' . $loopnum . '',$name,time()+3600*200);
> > > it doesn't write the cookies
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >

--- End Message ---
--- Begin Message ---
sorry i misse dsomething else i should say, this is in the function but i
haven't sent any output before i call the function
"Water_foul" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> lemme clarify what i mean by function, i created a function
> "Water_foul" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > all i did was a function and some conditionals
> > "Joel Kitching" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> > > Did you do this before you sent some outut?  This would send headers,
> > > therefore causing you to not be able to send the "cookie" header.
> > >
> > > On Sat, 19 Jun 2004 15:51:00 -0600, water_foul
> > > <[EMAIL PROTECTED]> wrote:
> > > >
> > > > whats wrong with this script
> > > > setcookie('link' . $loopnum . '',$url,time()+3600*200);
> > > > setcookie('name' . $loopnum . '',$name,time()+3600*200);
> > > > it doesn't write the cookies
> > > >
> > > > --
> > > > PHP General Mailing List (http://www.php.net/)
> > > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > >
> > > >

--- End Message ---
--- Begin Message ---
Are you sure you're trying to access them properly, and on the next
page refresh?

ex)

<?php
// Print an individual cookie
echo $_COOKIE["TestCookie"];
echo $HTTP_COOKIE_VARS["TestCookie"];

// Another way to debug/test is to view all cookies
print_r($_COOKIE);
?> 

On Sat, 19 Jun 2004 15:56:36 -0600, water_foul
<[EMAIL PROTECTED]> wrote:
> 
> all i did was a function and some conditionals
> "Joel Kitching" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> 
> 
> > Did you do this before you sent some outut?  This would send headers,
> > therefore causing you to not be able to send the "cookie" header.
> >
> > On Sat, 19 Jun 2004 15:51:00 -0600, water_foul
> > <[EMAIL PROTECTED]> wrote:
> > >
> > > whats wrong with this script
> > > setcookie('link' . $loopnum . '',$url,time()+3600*200);
> > > setcookie('name' . $loopnum . '',$name,time()+3600*200);
> > > it doesn't write the cookies
> > >
> > > --
> > > 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
> 
>

--- End Message ---
--- Begin Message ---
i did that and it doesn't say that theere there, how do you set cookies so
that theyy dont expire (maby the expiration is set wrong...... i'm a newb
with cookies
"Joel Kitching" <[EMAIL PROTECTED]> wrote
Are you sure you're trying to access them properly, and on the next
> page refresh?
>
> ex)
>
> <?php
> // Print an individual cookie
> echo $_COOKIE["TestCookie"];
> echo $HTTP_COOKIE_VARS["TestCookie"];
>
> // Another way to debug/test is to view all cookies
> print_r($_COOKIE);
> ?>
>
> On Sat, 19 Jun 2004 15:56:36 -0600, water_foul
> <[EMAIL PROTECTED]> wrote:
> >
> > all i did was a function and some conditionals
> > "Joel Kitching" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >
> >
> > > Did you do this before you sent some outut?  This would send headers,
> > > therefore causing you to not be able to send the "cookie" header.
> > >
> > > On Sat, 19 Jun 2004 15:51:00 -0600, water_foul
> > > <[EMAIL PROTECTED]> wrote:
> > > >
> > > > whats wrong with this script
> > > > setcookie('link' . $loopnum . '',$url,time()+3600*200);
> > > > setcookie('name' . $loopnum . '',$name,time()+3600*200);
> > > > it doesn't write the cookies
> > > >
> > > > --
> > > > 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
> >
> >

--- End Message ---
--- Begin Message ---
There are many examples (in the comments) at the manual entry for
set_cookie at php.net; go try one of those.

On Sat, 19 Jun 2004 16:07:34 -0600, water_foul
<[EMAIL PROTECTED]> wrote:
> 
> i did that and it doesn't say that theere there, how do you set cookies so
> that theyy dont expire (maby the expiration is set wrong...... i'm a newb
> with cookies
> 
> "Joel Kitching" <[EMAIL PROTECTED]> wrote
> Are you sure you're trying to access them properly, and on the next
> > page refresh?
> >
> > ex)
> >
> > <?php
> > // Print an individual cookie
> > echo $_COOKIE["TestCookie"];
> > echo $HTTP_COOKIE_VARS["TestCookie"];
> >
> > // Another way to debug/test is to view all cookies
> > print_r($_COOKIE);
> > ?>
> >
> > On Sat, 19 Jun 2004 15:56:36 -0600, water_foul
> > <[EMAIL PROTECTED]> wrote:
> > >
> > > all i did was a function and some conditionals
> > > "Joel Kitching" <[EMAIL PROTECTED]> wrote in message
> > > news:[EMAIL PROTECTED]
> > >
> > >
> > > > Did you do this before you sent some outut?  This would send headers,
> > > > therefore causing you to not be able to send the "cookie" header.
> > > >
> > > > On Sat, 19 Jun 2004 15:51:00 -0600, water_foul
> > > > <[EMAIL PROTECTED]> wrote:
> > > > >
> > > > > whats wrong with this script
> > > > > setcookie('link' . $loopnum . '',$url,time()+3600*200);
> > > > > setcookie('name' . $loopnum . '',$name,time()+3600*200);
> > > > > it doesn't write the cookies
> > > > >
> > > > > --
> > > > > 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
> 
>

--- End Message ---
--- Begin Message ---
i figured it out ty
"Joel Kitching" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> There are many examples (in the comments) at the manual entry for
> set_cookie at php.net; go try one of those.
>
> On Sat, 19 Jun 2004 16:07:34 -0600, water_foul
> <[EMAIL PROTECTED]> wrote:
> >
> > i did that and it doesn't say that theere there, how do you set cookies
so
> > that theyy dont expire (maby the expiration is set wrong...... i'm a
newb
> > with cookies
> >
> > "Joel Kitching" <[EMAIL PROTECTED]> wrote
> > Are you sure you're trying to access them properly, and on the next
> > > page refresh?
> > >
> > > ex)
> > >
> > > <?php
> > > // Print an individual cookie
> > > echo $_COOKIE["TestCookie"];
> > > echo $HTTP_COOKIE_VARS["TestCookie"];
> > >
> > > // Another way to debug/test is to view all cookies
> > > print_r($_COOKIE);
> > > ?>
> > >
> > > On Sat, 19 Jun 2004 15:56:36 -0600, water_foul
> > > <[EMAIL PROTECTED]> wrote:
> > > >
> > > > all i did was a function and some conditionals
> > > > "Joel Kitching" <[EMAIL PROTECTED]> wrote in message
> > > > news:[EMAIL PROTECTED]
> > > >
> > > >
> > > > > Did you do this before you sent some outut?  This would send
headers,
> > > > > therefore causing you to not be able to send the "cookie" header.
> > > > >
> > > > > On Sat, 19 Jun 2004 15:51:00 -0600, water_foul
> > > > > <[EMAIL PROTECTED]> wrote:
> > > > > >
> > > > > > whats wrong with this script
> > > > > > setcookie('link' . $loopnum . '',$url,time()+3600*200);
> > > > > > setcookie('name' . $loopnum . '',$name,time()+3600*200);
> > > > > > it doesn't write the cookies
> > > > > >
> > > > > > --
> > > > > > 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
> >
> >

--- End Message ---
--- Begin Message ---
Hey all....

Total PHP newbie here. I posted a day ago about php working
'intermittently'. I was told to check my apache logs which was a good hint
cause php is seg faulting. I've broken it down to my connection script to my
database and I ran it in gdb to see if it would tell me anything. Since I am
linux-tarded I don't have any clue what the problem is.

Here is my php code!!! It is stored in a file called dbConnect.php

<?PHP
//DEFINE GLOBAL VARIABLES TO BE USED BY ALL DATABASE FUNCTIONS
global $g_dbConn;

function dbConnect($HostName, $UserName, $Password)
{
 global $g_dbConn;
 if($HostName & $UserName & $Password)
 {
   print($HostName);
   print($UserName);
   print($Password);
   $g_dbConn = mysql_connect($HostName, $UserName, $Password);
   if($g_dbConn)
     {

       print("\n" . $g_dbConn);
       mysql_select_db("dba",$g_dbConn);
       print("\npast select\n");
     }
 }
}

function dbIsConnected()
{
 if($GLOBALS["g_dbConn"])
 {
  return true;
 }
 else
 {
  return false;
 }
}

print("start\n");
dbConnect("localhost", "root", "CantSeeThis");
print("finish\n");
?>


Here is the output in GDB!!!
(gdb) run dbConnect.php
Starting program: /usr/bin/php dbConnect.php
(no debugging symbols found)...(no debugging symbols found)...(no debugging
symbols found)...
(no debugging symbols found)...(no debugging symbols found)...(no debugging
symbols found)...
(no debugging symbols found)...(no debugging symbols found)...(no debugging
symbols found)...
(no debugging symbols found)...(no debugging symbols found)...(no debugging
symbols found)...[New Thread 1080622560 (LWP 29396)]
X-Powered-By: PHP/4.2.2
Content-type: text/html

start
localhostrootCantSeeThis
Resource id #1
past select
finish


Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1080622560 (LWP 29396)]
0x4207492e in _int_free () from /lib/tls/libc.so.6



Here is the backtrace!!!!

(gdb) bt
#0  0x4207492e in _int_free () from /lib/tls/libc.so.6
#1  0x42073908 in free () from /lib/tls/libc.so.6
#2  0x0812b20d in _efree ()
#3  0x40962a35 in _close_mysql_link (rsrc=0x0)
    at /usr/src/redhat/BUILD/php-4.2.2/ext/mysql/php_mysql.c:253
#4  0x081407f2 in list_entry_destructor ()
#5  0x0813f3c8 in zend_hash_clean ()
#6  0x0813f46c in zend_hash_graceful_reverse_destroy ()
#7  0x081409bf in zend_destroy_rsrc_list ()
#8  0x081320fd in shutdown_executor ()
#9  0x0813a145 in zend_deactivate ()
#10 0x0806f078 in php_request_shutdown ()
#11 0x0806d5d5 in main ()
#12 0x42015704 in __libc_start_main () from /lib/tls/libc.so.6
(gdb)



WTF is the problem. I have a feeling my script sucks and I am doing
something totally stupid

--- End Message ---
--- Begin Message ---
I don't know if this helps... but when I comment out all of the print
functions it seg faults at a totally different spot...

SCRIPT!!!

<?PHP
//DEFINE GLOBAL VARIABLES TO BE USED BY ALL DATABASE FUNCTIONS
global $g_dbConn;

function dbConnect($HostName, $UserName, $Password)
{
 global $g_dbConn;
 if($HostName & $UserName & $Password)
 {
   //print($HostName);
   //print($UserName);
   //print($Password);
   $g_dbConn = mysql_connect($HostName, $UserName, $Password);
   if($g_dbConn)
     {

       //print("\n" . $g_dbConn);
       mysql_select_db("dba",$g_dbConn);
       //print("\npast select\n");
     }
 }
}

function dbIsConnected()
{
 if($GLOBALS["g_dbConn"])
 {
  return true;
 }
 else
 {
  return false;
 }
}

//print("start\n");
dbConnect("localhost", "root", "CantSeeThis");
//print("finish\n");
?>



GDB RUN!!!

(gdb) run dbConnect.php
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /usr/bin/php dbConnect.php
(no debugging symbols found)...(no debugging symbols found)...(no debugging
symbols found)...
(no debugging symbols found)...(no debugging symbols found)...(no debugging
symbols found)...
(no debugging symbols found)...(no debugging symbols found)...(no debugging
symbols found)...
(no debugging symbols found)...(no debugging symbols found)...(no debugging
symbols found)...[New Thread 1080622560 (LWP 29412)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1080622560 (LWP 29412)]
0x4207441c in _int_malloc () from /lib/tls/libc.so.6
(gdb)



BACKTRACE

(gdb) bt
#0  0x4207441c in _int_malloc () from /lib/tls/libc.so.6
#1  0x4207378d in malloc () from /lib/tls/libc.so.6
#2  0x409caa4a in my_malloc () from /lib/libmysqlclient.so.12
#3  0x409db73a in vio_new () from /lib/libmysqlclient.so.12
#4  0x409c71bb in mysql_real_connect () from /lib/libmysqlclient.so.12
#5  0x40963161 in php_mysql_do_connect (ht=0, return_value=0x8221604,
this_ptr=0x0,
    return_value_used=1, persistent=0)
    at /usr/src/redhat/BUILD/php-4.2.2/ext/mysql/php_mysql.c:662
#6  0x40963d9e in zif_mysql_connect (ht=1108554344, return_value=0x42133268,
    this_ptr=0x42133268, return_value_used=1108554344)
    at /usr/src/redhat/BUILD/php-4.2.2/ext/mysql/php_mysql.c:714
#7  0x0815355c in execute ()
#8  0x081532ce in execute ()
#9  0x0813a7c6 in zend_execute_scripts ()
#10 0x080705ca in php_execute_script ()
#11 0x0806d648 in main ()
#12 0x42015704 in __libc_start_main () from /lib/tls/libc.so.6
(gdb)

--- End Message ---
--- Begin Message ---
how do you set a system path to the top level, i allredy tried '/' but it
ignores the last '.

--- End Message ---
--- Begin Message ---
I would also like to know how to set a cookie to all dirs in a domain
> how do you set a system path to the top level, i allredy tried '/' but it
ignores the last '.

--- End Message ---
--- Begin Message ---
how do you set a cookie to mutiple directories?

--- End Message ---
--- Begin Message ---
how do i read a cookie created by this code
setcookie('link1',blah,time()+3600,'/');

--- End Message ---
--- Begin Message ---
Robin Vickery sagde:
>
> The S modifier that you're using means that it's storing the studied
> expression. If the regexp changes each time around the loop then over
> 30000 iterations, that'll add up. See if removing that modifier helps
> at all.
>
The S modifier wasn't needed, I added it because I thought it would speed it up but
it didn't. Removing it didn't help on the memory usage, but it performs a little
better without.

> If that's not it, then these *might* save you some memory, although
> I've not tested them:
>
> I'm not entirely sure why you're matching (.*) at the end then putting
> it back in with your replacement text. Without running it, I'd have
> thought that you could leave out the (.*) from your pattern and the $4
> from your replacement and get exactly the same effect.
>

I tried removing $4 and (.*) but the result isn't the same, actually my first reg.
exp. didn't have $4, but I had to add it. Without it 51 of the 1246 texts isn't
processed right? Also there isn't really any difference in how it performs with or
without it.

>
> You could use a non-capturing subpattern for $2 which you're not using
> in your replacement.
>
>   $replace = "/^((?:[a-z]+?[^a-z]+?){".($count)."})(".$typedmask.")/i";

I didn't know you could do that.. cool :), this made the script run a little faster
but it still uses the same amount of memory.

>
> And maybe a look-behind assertion for the first subpattern rather than
> a capturing pattern then re-inserting $1.
>
>   $replace = "/^(?<=(?:[a-z]+?[^a-z]+?){".($count)."})(".$typedmask.")/i";
>   $with = "<error-start sourcetext=".$corr['sourcetext']." id=".$corr['id']."
>   ...
>

With ?<= I get a lot of warnings:

here is an example:
$replace is '/^(?<=(?:[a-z]+?[^a-z]+?){50})(go)(.*)/i'
$with is '<error-start sourcetext=3 id=49 group="-" class="-" corrected-from="go"
corrected-to="god">$2<error-end sourcetext=3 id=49>$3'
<br />
<b>Warning</b>:  Compilation failed: lookbehind assertion is not fixed length at
offset 34


with the corrections added the reg.exp. looks like this:
$typedmask = preg_replace("/\s+/",".*?",$corr['typed']);

$replace = '/^((?:[a-z]+?[^a-z]+?){'.($count).'})('.$typedmask.')(.*)/i';

$with = '$1<error-start sourcetext='.$corr['sourcetext'].' id='.$corr['id'].'
group="'.$corr['grupper'].'" class="'.$corr['ordklasse'].'"
corrected-from="'.$corr['typed'].'"
corrected-to="'.$corr['corrected'].'">$2<error-end
sourcetext='.$corr['sourcetext'].' id='.$corr['id'].'>$3';

$text = $skipText[0] . preg_replace ($replace,$with,$text,1);

It completes a little faster and the output is exactly the same as before,
but it still uses way too much memory.

[EMAIL PROTECTED] testextract]# time php ../export.php > export6.txt
real    1m15.851s
user    0m18.720s
sys     0m1.750s

>From "top" just before the script completed:
  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
 7843 root      17   0  269M 269M  3328 R    41.7 53.6   0:19 php

This isn't a huge problem anymore, as we have been allowed to move the project to a
3 times faster server with less activity (because of this).

But I would still like to know if there is a solution to this because it seems quite
insane that it allocates more than 250MB memory generate 4MB output.

Thanks Robin! I really appreciate your answer.

Brgds Ulrik

--- End Message ---
--- Begin Message ---
i dont know why but the following code "kills" the browser:
<?php
//the function for adding new addresses
function loop_new_address($loopnum,$url,$name){
//the ${'link' . $loopnum} says put $link and add $loopnum to the end
if(isset($_COOKIE['link' . $loopnum . ''])){
loop_new_address_help($loopnum+1,$url,$name);
}
else{
setcookie('link' . $loopnum . '',$url,time()+3600,'/');
setcookie('name' . $loopnum . '',$name,time()+3600,'/');
setcookie('link' . $loopnum . '',$url,time()+3600);
setcookie('name' . $loopnum . '',$name,time()+3600);
print('<a href=$url>' . $name . '</a> was added');
};
};
//A function to let loop_new_address loop
function loop_new_address_help($loopnum,$url,$name){
loop_new_address($loopnum,$url,$name);
};
if(isset($_GET['new'])) {
loop_new_address(1,$_GET['url'],$_GET['name']);
};
print('<table>');
print('<tr><td><form Method="GET"
action="module/personal/delete.php">delete</td></tr>');
//write code
$writenum=1;
while(isset($_COOKIE['link' . $writenum . ''])==true){
print('<a href=' . $_COOKIE['link' . $writenum . ''] . '>' . $_COOKIE['name'
. $writenum . ''] . '</a>');
};
include('links.htm')
?>
<tr><td><input type=submit value="Delete Checked"></form></td></tr>
</table>
<table>
<tr><td><form METHOD="GET" ACTION="module/personal/links.php"><input
type=hidden name=new value=1></td><td></td></tr>
<tr><td>Site name</td><td><INPUT TYPE=text NAME="name" VALUE=""></td></tr>
<tr><td>site url (if it is not on this site it MUST contain
"http://";)</td><td><INPUT TYPE=text NAME="url" VALUE=""></td></tr>
<tr><td></td><td><INPUT TYPE="SUBMIT" VALUE="Continue"></form></td></tr>
</table>

--- End Message ---

Reply via email to