php-general Digest 18 Jul 2005 00:31:03 -0000 Issue 3573

Topics (messages 218829 through 218841):

Re: Session warning
        218829 by: Thomas Bonham

Re: blob and long blob
        218830 by: Ben-Nes Yonatan

Re: Trimming Text
        218831 by: Al
        218834 by: André Medeiros

searchbot script
        218832 by: jenny mathew
        218833 by: Marco Tabini

Re: Question about apache-php concurrent process control
        218835 by: André Medeiros

Re: Displaying HTML safely
        218836 by: Lauri Harpf

Need help with PHP / MySQL connect problem
        218837 by: Linda H
        218838 by: Matt Darby
        218839 by: Linda H
        218840 by: Mikey
        218841 by: Matt Darby

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 ---
Thanks is for the help.
That is a very good command.

Here is what I have now.
[EMAIL PROTECTED] property]$ od -c adminlogin.php | head
0000000   <   ?   p   h   p           s   e   s   s   i   o   n   _   s
0000020   t   a   r   t   (   )   ;       r   e   q   u   i   r   e   (
0000040   "   f   u   n   c   t   l   i   b   .   p   h   p   "   )   ;
0000060       ?   >  \r  \n               <   h   t   m   l   >  \r  \n
0000100               <   h   e   a   d   >  \r  \n  \t       <   t   i
0000120   t   l   e   >   L   o   g   i   n   <   /   t   i   t   l   e
0000140   >  \r  \n  \t       <   l   i   n   k       r   e   l   =   "
0000160   s   t   y   l   e   s   h   e   e   t   "       t   y   p   e
0000200   =   "   t   e   x   t   /   c   s   s   "       h   r   e   f
0000220   =   "   .   .   /   .   .   /   c   s   s   /   t   a   b   l
[EMAIL PROTECTED] property]$

Also I gess I can't have the null line at the top of my file.

Again Thanks of the help.
Thomas

On 7/16/05, Rasmus Lerdorf <[EMAIL PROTECTED]> wrote:
> Thomas Bonham wrote:
> > Ok that is some help.
> >
> > The first five lines of the file are the following.
> >
> >
> >    <?php
> >        session_start();
> >        require("functlib.php");
> >    ?>
> >
> > od -c adminlogin.php | head out put the folowing.
> >
> > [EMAIL PROTECTED] property]$ od -c adminlogin.php | head
> > 0000000  \r  \n               <   ?   p   h   p      \r  \n  \t       s
> > 0000020   e   s   s   i   o   n   _   s   t   a   r   t   (   )   ;  \r
> > 0000040  \n  \t       r   e   q   u   i   r   e   (   "   f   u   n   c
> > 0000060   t   l   i   b   .   p   h   p   "   )   ;      \r  \n
> > 0000100       ?   >  \r  \n               <   h   t   m   l   >  \r  \n
> > 0000120               <   h   e   a   d   >  \r  \n  \t       <   t   i
> > 0000140   t   l   e   >   C   I   S   1   6   6   A   E       -       A
> > 0000160   d   m   i   n       L   o   g   i   n   <   /   t   i   t   l
> > 0000200   e   >  \r  \n  \t       <   l   i   n   k       r   e   l   =
> > 0000220   "   s   t   y   l   e   s   h   e   e   t   "       t   y   p
> 
> well, there is your answer.  Your file starts with \r\n
> So your PHP tag is not the first thing in your file and PHP will output
> that leading \r\n.
> 
> -Rasmus
> 


-- 
------------------------------------------------------------------
Thomas Bonham
[EMAIL PROTECTED]
bonhamlinux.org
Cell 602-402-9786

--- End Message ---
--- Begin Message ---
timothy johnson wrote:
I am building a database that houses photo, I thought everything was
going fine til I went to upload a file that was bigger then 2MB. I
check my HTML int he form I have it set to 10MB, in php.ini I have it
set to 32MB, and then in mysql I am using a longblob so shouldnt that
handle like 4GB. Anyone have anyone idea, on why files above 2MB arent
working?


It passed sometime since I made such a thing but check about: ini_set("memory_limit","18M"); // here its set to 18MB and also I know that PostgreSQL got functions which are specific for dealing with large objects, maybe MySQL got something similar also.

Cheers,
Ben-Nes Yonatan

--- End Message ---
--- Begin Message ---
Al wrote:
André Medeiros wrote:

Greetings.

I am trying to trim some text containing HTML tags. What I want to do is
to trim the text without trimming the tags or html entities like &nbsp;
and such, wich completelly break the design.

Has anyone succeded on doing such a thing? phpclasses.org won't help :(

Thanks in advance.
André


Consider...

Making a preg pattern to capture everything between tags and then use preg_replace_callback() process the "captured text" with the called function.

It will work; but it's a bit tricky.

Here is a similiar code snip to get you started...

$pattern= "%<[\w-/]+>%";
$text= preg_replace_callback($pattern, create_function('$matches', 'return strtolower($matches[0]);'), $text);
This converts all tags to lowercase.

You probably should use a regular callback function rather than creating one.


Here is a pattern that will get you close
$pattern= "%(<[\s\S]+?>)([\s\S]+?)(</[\s\S]+?>)%";

The first bracket will get your first tag; second bracket, your text; third, 
the end tag.

Try this...

$num= preg_match_all("$pattern", $your_string, $matches);

print_r($matches);

I didn't test this; but, you should see all your tags and text neatly in an 
array.

You can then use foreach($matches[x] $key=>$value) {

        your code to trim, etc.

        $new_array[$key}= $new_string;
}

From the print_r() you can see what "x should be.  And, you'll need to 
reassemble your $new_array.

Finally, reconstruct your output string with another foreach()

The preg_replace_callback() will do all the foreach() stuff in one line. Your argument for the callback function will be "x".
--- End Message ---
--- Begin Message ---
I've succeded on doing this task :)

I had to make a few assumptions (like HTML is formatted correctly),
but, other than that, it worked just fine.

I'll post the code on monday.

Thanks for all your help guys. You've been GRRRREAT (you know... like
Tony says ;) )

On 7/17/05, Al <[EMAIL PROTECTED]> wrote:
> Al wrote:
> > André Medeiros wrote:
> >
> >> Greetings.
> >>
> >> I am trying to trim some text containing HTML tags. What I want to do is
> >> to trim the text without trimming the tags or html entities like &nbsp;
> >> and such, wich completelly break the design.
> >>
> >> Has anyone succeded on doing such a thing? phpclasses.org won't help :(
> >>
> >> Thanks in advance.
> >> André
> >
> >
> > Consider...
> >
> > Making a preg pattern to capture everything between tags and then use
> > preg_replace_callback() process the "captured text" with the called
> > function.
> >
> > It will work; but it's a bit tricky.
> >
> > Here is a similiar code snip to get you started...
> >
> > $pattern= "%<[\w-/]+>%";
> >
> > $text=
> > preg_replace_callback($pattern,
> > create_function('$matches', 'return strtolower($matches[0]);'), $text);
> >
> > This converts all tags to lowercase.
> >
> > You probably should use a regular callback function rather than creating
> > one.
> 
> 
> Here is a pattern that will get you close
> $pattern= "%(<[\s\S]+?>)([\s\S]+?)(</[\s\S]+?>)%";
> 
> The first bracket will get your first tag; second bracket, your text; third, 
> the end tag.
> 
> Try this...
> 
> $num= preg_match_all("$pattern", $your_string, $matches);
> 
> print_r($matches);
> 
> I didn't test this; but, you should see all your tags and text neatly in an 
> array.
> 
> You can then use foreach($matches[x] $key=>$value) {
> 
>         your code to trim, etc.
> 
>         $new_array[$key}= $new_string;
> }
> 
>  From the print_r() you can see what "x should be.  And, you'll need to 
> reassemble your $new_array.
> 
> Finally, reconstruct your output string with another foreach()
> 
> The preg_replace_callback() will do all the foreach() stuff in one line.  
> Your argument for the
> callback function will be "x".
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

--- End Message ---
--- Begin Message ---
hello group,
is it possible to make write a program in php ,so that only search bots can 
see the output of that program.i mean to say that a program echoes a line at 
the footer which only search bots can see,it will be invisible to general 
visitors.

--- End Message ---
--- Begin Message ---
You can--you need to check the signature of the visiting client and
determine whether it is a spider (for example, Google indexers are called
"googlebot"s). This is in $_SERVER['HTTP_USER_AGENT']. Here's a thread on
the subject:

http://news.php.net/php.general/217460

You can also use the browscap-related functionality to extract more
information from the user-agent string, although this is not always 100%
reliable:

http://ca.php.net/get-browser

Remember, however, that most search engines shun this practice and may drop
your site from their indices if you adopt it.


Marco


On 7/17/05 10:55 AM, "jenny mathew" <[EMAIL PROTECTED]> wrote:

> hello group,
> is it possible to make write a program in php ,so that only search bots can
> see the output of that program.i mean to say that a program echoes a line at
> the footer which only search bots can see,it will be invisible to general
> visitors.

--- End Message ---
--- Begin Message ---
I did something like that for a newsletter sending script. Basiclly, I
had two scripts:

a) AddEdit.php that would list the newsletter's items and allow it to send
b) Send.php that was a script I ran on the background

When pressed "Send" on AddEdit, it would do something like

$tempName = tempnam( '/tmp', 'newsletter' );
$fp = fopen( $tempName, 'w+' );
fputs( $fp, "#!/bin/sh\n/path/to/script/Send.php 12 &\n" );
fclose( $fp );
chmod( $tempName, 0755 );
system( $tempName . ' &' );

That way, it would launch the second script into the background,
checking if the script altered the newsletter's state for "Sent"
everytime a user saw the newsletter's details.

Hope it helped.

On 7/16/05, Rory Browne <[EMAIL PROTECTED]> wrote:
> On 7/16/05, rouvas <[EMAIL PROTECTED]> wrote:
> > Hi Liang,
> >
> > trying to get conclusive results with browsers is futile. Use a command-line
> > tool (like curl) to invoke the web pages and get the results. Or you can use
> Although personally I think that telnet-to-port-80 would be a better
> idea, in this case when you're trying to check what is outputted
> first. Either that or a TCP sniffer.
> 
> I also agree with the microtime() suggestion, mentioned below. It will
> get you around the problem of caches - which is a major problem for
> something like this. I'm not sure what the situation with apache is
> regarding caches.
> 
> > PHP's own function to query the web server and do your own timing with
> > microtime() function or another suitable for your purposes.
> >
> > In order for flush() results to reach you (in a browser) they have to pass
> > from multiple caches like PHP's, Apache's, the occasional proxies and 
> > finally
> > the browser's own cache. So you cannot get dependaple results measuring 
> > times
> > or responses from your browser. Try the methods above.
> >
> > And a final tip... When Rasmus speaks, you don't question him:-) Period.
> 
> Unless you didn't understand what he said and want clarification.
> 
> 
> >
> > Have a nice day,
> > -Stathis
> >
> > On Saturday 16 July 2005 04:41, Liang ZHONG wrote:
> > > Hi Rasmus,
> > >
> > > You are right. It was the problem with the browser. I used Mozilla Firefox
> > > to try, and do not know what consideration it just serialized the 
> > > identical
> > > url http requests. I then turned to use 2 IE 6.0 windows, 2 tabs within
> > > Maxthon browser, one IE windows and one Firefox, to test. Then I got the
> > > conclusion as you told. Thank you very much for the help.
> > >
> > > BTW, I could not get the flush() work, neither flush() with ob_flush(). I
> > > tried almost all methods mentioned in the followed posts under
> > > http://us2.php.net/flush, but none of them can really pushed the buffer
> > > out. The site is configurated with http://liang.ns2user.info/php/info.php
> > > on Red head, kernel 2.4.29. What can I do to get it work?
> > >
> > > Thank you again.
> > >
> > > >Liang ZHONG wrote:
> > > > > Could you please explain it a little bit more?
> > > > > I did test this way.
> > > > >
> > > > > The code is the same for a.php and b.php
> > > > > <?php
> > > > >
> > > > >        sleep(20);
> > > > >        print  Done. <br />";
> > > > >
> > > > > ?>
> > > > >
> > > > > I place request from 2 browser windows.
> > > > > First time, I placed with http://baseURL/a.php with both 2 browsers,
> > > > > starting times have 5 second interval. Then the first "Done" shows
> > > > > after 20 seconds and the second "Done" shows 20 seconds after the 
> > > > > first
> > > >
> > > >"Done".
> > > >
> > > > > Then, I placed one browser with http://baseURL/a.php and the second 
> > > > > one
> > > > > with http://baseURL/b.php, with starting time of 5 second interval.
> > > > > Then I got the first browser showing "Done" after 20 seconds and 5
> > > > > seconds later, the second browser showed "Done", too.
> > > > >
> > > > > Thus it seems that the apache can spoon out multiple php interpreters
> > > > > responding to http requests, while php can not deal with concurrent
> > > > > process from one program.
> > > >
> > > >I have no idea what you did to configure it this way.  I wouldn't even
> > > >know how to do that if you asked me to.  As far as PHP is concerned it
> > > >has no idea which processes are handling which script files at any one
> > > >point.  So whether you request a.php and b.php at the same time or a.php
> > > >twice at the same time, it makes absolutely no difference to PHP.  If
> > > >you are really seeing this, then the limitation is in your browser or
> > > >somewhere else.  Try making a.php output stuff so it becomes easier to
> > > >see.  As in for($i=0;$i<20;$i++) { echo $i; flush(); sleep(1); }
> > > >You should see the counter start counting as soon as you hit the page.
> > > >
> > > >-Rasmus
> > > >
> > > >--
> > > >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 ---
> Something like this (you might like to check the syntax, I'm working from 
> memory here) might work:
>
> header('Content-Disposition: attachment; filename=somefile.html');

Thanks, I'll have to try that.

As for security, looks like I will need to watch out for the extensions. 
Turns out that the server I'm on executes .php files as long as the 
directory they are located in is chmod'ed 755. Permissions on the .php file 
itself don't seem to matter.

Apparently, anything else than 755 on the directory prevents Apache from 
bringing up the HTML files. I thought that 644 would have been enough for 
HTML, but I guess I was mistaken.

- Lauri Harpf 

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

I'm running MySQL 4.0.21, Apache 2.0.52 and PHP 5.0.2 on a Windows XP system. I can run scripts with PHP and HTML statements and see correct output in my browser. But when I try to connect to MySQL I get nothing, including no error messages.

One book I have says to run the following scrip to test the connection. It should print either the Resource name or an error message:

<?php
echo mysql_connect ('localhost','calendar','pass1234'); # host, user, password
?>

I get no output at all, and if the statement is placed in a larger script, above html/PHP output, it suppresses that as well.

Using the mysql monitor from the DOS command prompt, I can connect as user 'calendar' with password 'pass1234', select a database and execute SQL statements successfully.

Can anyone help me figure out why I can't seem to connect, please?

Linda
--- End Message ---
--- Begin Message ---
Using this at the top of your script will allow PHP and MySQL to interact.
$_POST['dbconn']=mysql_select_db("database_name", mysql_connect("server_name","user_name","password"));

It does sound like you have notices and warnings turned off in php.ini:
Find php.ini (not sure where it installs to in Windows version), and set error_reporting = E_ALL. This will show all notices and warnings generated by your PHP code; extremely usefull in debugging.

Matt Darby

Linda H wrote:

Hi,

I'm running MySQL 4.0.21, Apache 2.0.52 and PHP 5.0.2 on a Windows XP system. I can run scripts with PHP and HTML statements and see correct output in my browser. But when I try to connect to MySQL I get nothing, including no error messages.

One book I have says to run the following scrip to test the connection. It should print either the Resource name or an error message:

<?php
echo mysql_connect ('localhost','calendar','pass1234'); # host, user, password
?>

I get no output at all, and if the statement is placed in a larger script, above html/PHP output, it suppresses that as well.

Using the mysql monitor from the DOS command prompt, I can connect as user 'calendar' with password 'pass1234', select a database and execute SQL statements successfully.

Can anyone help me figure out why I can't seem to connect, please?

Linda

--- End Message ---
--- Begin Message ---
Thanks for the advice, Matt, but it doesn't seem to solve my problem.

php.ini is in the C:Program Files/WINDOWS directory and error_reporting was set to E_ALL.

I found php5ts.dll in the WINDOWS/system32 directory. I copied it to WINDOWS/system, just in case. My install instructions said to put it with my other dlls, which might be in either directory. Most of them are in system32.

Using this at the top of your script will allow PHP and MySQL to interact.
$_POST['dbconn']=mysql_select_db("database_name", mysql_connect("server_name","user_name","password"));

I put this in my script (changing parameters as appropriate) but got no results and no error messages. Any other ideas. I've spent hours on this, trying everything I could think of and I'm very frustrated.

The rest of my output is still suppressed if I put the connect script above it in the file.

It does sound like you have notices and warnings turned off in php.ini:
Find php.ini (not sure where it installs to in Windows version), and set error_reporting = E_ALL. This will show all notices and warnings generated by your PHP code; extremely usefull in debugging.

Matt Darby

Linda H wrote:

I'm running MySQL 4.0.21, Apache 2.0.52 and PHP 5.0.2 on a Windows XP system. I can run scripts with PHP and HTML statements and see correct output in my browser. But when I try to connect to MySQL I get nothing, including no error messages.

One book I have says to run the following scrip to test the connection. It should print either the Resource name or an error message:

<?php
echo mysql_connect ('localhost','calendar','pass1234'); # host, user, password
?>

I get no output at all, and if the statement is placed in a larger script, above html/PHP output, it suppresses that as well.

Using the mysql monitor from the DOS command prompt, I can connect as user 'calendar' with password 'pass1234', select a database and execute SQL statements successfully.

--- End Message ---
--- Begin Message ---
Matt Darby wrote:

Using this at the top of your script will allow PHP and MySQL to interact. $_POST['dbconn']=mysql_select_db("database_name", mysql_connect("server_name","user_name","password"));

It does sound like you have notices and warnings turned off in php.ini:
Find php.ini (not sure where it installs to in Windows version), and set error_reporting = E_ALL. This will show all notices and warnings generated by your PHP code; extremely usefull in debugging.

Matt Darby

Linda H wrote:

Hi,

I'm running MySQL 4.0.21, Apache 2.0.52 and PHP 5.0.2 on a Windows XP system. I can run scripts with PHP and HTML statements and see correct output in my browser. But when I try to connect to MySQL I get nothing, including no error messages.

One book I have says to run the following scrip to test the connection. It should print either the Resource name or an error message:

<?php
echo mysql_connect ('localhost','calendar','pass1234'); # host, user, password
?>

I get no output at all, and if the statement is placed in a larger script, above html/PHP output, it suppresses that as well.

Using the mysql monitor from the DOS command prompt, I can connect as user 'calendar' with password 'pass1234', select a database and execute SQL statements successfully.

Can anyone help me figure out why I can't seem to connect, please?

Linda


From the manual:


   Return Values

Returns a MySQL link identifier on success, or *FALSE* on failure.

So if your connection is failing then it will not print anything to screen, try:

echo (mysql_connect ('localhost','calendar','pass1234')) ? "connected" : mysql_error();

HTH,

Mikey

--- End Message ---
--- Begin Message ---
Try this just for kicks:

<?
   aslkdjfalsd;
<?

See if this will output errors. It's rather hard to debug without error messages ;)
If I remember correctly, isn't php.ini supposed to be in c:/PHP?

Linda H wrote:

Thanks for the advice, Matt, but it doesn't seem to solve my problem.

php.ini is in the C:Program Files/WINDOWS directory and error_reporting was set to E_ALL.

I found php5ts.dll in the WINDOWS/system32 directory. I copied it to WINDOWS/system, just in case. My install instructions said to put it with my other dlls, which might be in either directory. Most of them are in system32.

Using this at the top of your script will allow PHP and MySQL to interact. $_POST['dbconn']=mysql_select_db("database_name", mysql_connect("server_name","user_name","password"));


I put this in my script (changing parameters as appropriate) but got no results and no error messages. Any other ideas. I've spent hours on this, trying everything I could think of and I'm very frustrated.

The rest of my output is still suppressed if I put the connect script above it in the file.

It does sound like you have notices and warnings turned off in php.ini:
Find php.ini (not sure where it installs to in Windows version), and set error_reporting = E_ALL. This will show all notices and warnings generated by your PHP code; extremely usefull in debugging.

Matt Darby

Linda H wrote:

I'm running MySQL 4.0.21, Apache 2.0.52 and PHP 5.0.2 on a Windows XP system. I can run scripts with PHP and HTML statements and see correct output in my browser. But when I try to connect to MySQL I get nothing, including no error messages.

One book I have says to run the following scrip to test the connection. It should print either the Resource name or an error message:

<?php
echo mysql_connect ('localhost','calendar','pass1234'); # host, user, password
?>

I get no output at all, and if the statement is placed in a larger script, above html/PHP output, it suppresses that as well.

Using the mysql monitor from the DOS command prompt, I can connect as user 'calendar' with password 'pass1234', select a database and execute SQL statements successfully.



--- End Message ---

Reply via email to