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 17 Jul 2005 12:15:35 -0000 Issue 3572

php-general-digest-helplists.php.net
Date: Sun Jul 17 2005 - 07:15:35 CDT


php-general Digest 17 Jul 2005 12:15:35 -0000 Issue 3572

Topics (messages 218819 through 218828):

Re: Trimming Text
        218819 by: Al
        218827 by: Ben-Nes Yonatan

Session warning
        218820 by: Thomas Bonham
        218821 by: Jasper Bryant-Greene
        218822 by: Thomas Bonham
        218823 by: Rasmus Lerdorf
        218824 by: Thomas Bonham
        218825 by: Rasmus Lerdorf

Re: Echo array string index?
        218826 by: Ben-Nes Yonatan

blob and long blob
        218828 by: timothy johnson

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:


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  
> 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.

attached mail follows:


André Medeiros wrote:
> On Fri, 2005-07-15 at 16:03 +0100, Richard Davey wrote:
>
>>Hello André,
>>
>>Friday, July 15, 2005, 4:24:23 PM, you wrote:
>>
>>AM> I am trying to trim some text containing HTML tags. What I want to
>>AM> do is to trim the text without trimming the tags or html entities
>>AM> like &nbsp; and such, wich completelly break the design.
>>
>>The problem as I see it, is that while it's easy to trim some text and
>>then check to see if you were inside an HTML tag or not, it becomes
>>MUCH harder to check if you were inside nested tags (for example
>><strong><em>)
>>
>>If there are no nested tags then it's much easier.. just trim the
>>string at X characters and then search for the last occurrence of a
>>'>' and the last occurance of '<' - if the first is LESS than the second
>>value, then you're in the middle of a tag.
>>
>>This of course doesn't handle nested tags.
>>
>>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
>>
>
>
> Yeah... that's the point :( Nested tags are very possible.
>
> I am not sure how one would go here tho
>

sorry that i didnt have time to read everything word by word but did you
try to run strip_tags()?

attached mail follows:


Hello All,
I'm working on session and I'm getting this warning. Maybe someone can
help fixing this problem. Below is the following code.

Warning:
Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at
/var/www/html/bonham/cornerstone-data/property/adminlogin.php:2) in
/var/www/html/bonham/cornerstone-data/property/adminlogin.php on line
3

Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at
/var/www/html/bonham/cornerstone-data/property/adminlogin.php:2) in
/var/www/html/bonham/cornerstone-data/property/adminlogin.php on line
3

Then I get my login fields.

Code:
<?php
         session_start();
         require("functlib.php");
   ?>
   <html>
   <head>
         <title>CIS166AE - Admin Login</title>
         <link rel="stylesheet" type="text/css" href="/../../css/table.css">
   </head>
   <body>
   
   
   <?php
         if(isset($_POST['txtUser']) && isset($_POST['txtPass']))
         {
                  if(CheckUser($_POST['txtUser'],$_POST['txtPass']))
                $_SESSION['valid_user']=$_POST['txtUser'];
         }
         
         if(CheckAuth()==false)
         {
         //Code to make authentication
         ?>
        <form method="post" action="adminlogin.php" name="login">
        Please Login
        Username:
        <input name="txtUser" type="text">
        Password:
        <input name="txtPass" type="password">
        <input type="submit" value="Login">
        <input type="reset" value="Clear">"
        </form>
        <?php
        }
        else
        {
                //Code if authenticated
                echo "Thank you, you have been authenticated as
<b>".$_SESSION['valid_user']."</b><br>";
                                          
        }
                ?>
                
                <?php if(isset($_SESSION['valid_user'])){echo "<a
href=\"adminlogout.php\">Logout</a>";}?>
        
</body>
</html>

Function FIle:
<?php
//PHP Functions that can be included in pages

function CheckAuth()
{
        if(isset($_SESSION['valid_user']))
                return true;
        else
                return false;
}

function CheckUser($username, $password)
{
                $db = new mysqli('localhost','bonham','password_goes here','bonham');
                
                $sql="Select * from auth where username = '".$username."' and
                password = '".$password."'";
                $result=$db->query($sql);
                $db->close();
                if($result->num_rows>0)
                        return true;
                else
                        return false;
}

?>

Thank for the help.
Thomas
--
------------------------------------------------------------------
Thomas Bonham
thomasbbonhamgmail.com
bonhamlinux.org
Cell 602-402-9786

attached mail follows:


Thomas Bonham wrote:
> Hello All,
> I'm working on session and I'm getting this warning. Maybe someone can
> help fixing this problem. Below is the following code.
>
> Warning:
> Warning: session_start() [function.session-start]: Cannot send session
> cookie - headers already sent by (output started at
> /var/www/html/bonham/cornerstone-data/property/adminlogin.php:2) in
> /var/www/html/bonham/cornerstone-data/property/adminlogin.php on line
> 3

Are you absolutely sure that there is *no* output before the
session_start() in adminlogin.php?

If there is it won't work. Even a space before the first <?php, or a
Unicode BOM, or any kind of output can screw it up.

Jasper

attached mail follows:


Jasper Bryant-Greene wrote:
> Thomas Bonham wrote:
>
>> Hello All,
>> I'm working on session and I'm getting this warning. Maybe someone can
>> help fixing this problem. Below is the following code.
>>
>> Warning: Warning: session_start() [function.session-start]: Cannot
>> send session
>> cookie - headers already sent by (output started at
>> /var/www/html/bonham/cornerstone-data/property/adminlogin.php:2) in
>> /var/www/html/bonham/cornerstone-data/property/adminlogin.php on line
>> 3
>
>
> Are you absolutely sure that there is *no* output before the
> session_start() in adminlogin.php?
>
> If there is it won't work. Even a space before the first <?php, or a
> Unicode BOM, or any kind of output can screw it up.
>
> Jasper

The first thing at is in my code is the start session command.

Thomas

attached mail follows:


On Sat, 16 Jul 2005, Thomas Bonham wrote:
> Jasper Bryant-Greene wrote:
> > Thomas Bonham wrote:
> >
> >> Hello All,
> >> I'm working on session and I'm getting this warning. Maybe someone can
> >> help fixing this problem. Below is the following code.
> >>
> >> Warning: Warning: session_start() [function.session-start]: Cannot
> >> send session
> >> cookie - headers already sent by (output started at
> >> /var/www/html/bonham/cornerstone-data/property/adminlogin.php:2) in
> >> /var/www/html/bonham/cornerstone-data/property/adminlogin.php on line
> >> 3
> >
> >
> > Are you absolutely sure that there is *no* output before the
> > session_start() in adminlogin.php?
> >
> > If there is it won't work. Even a space before the first <?php, or a
> > Unicode BOM, or any kind of output can screw it up.
> >
> > Jasper
>
> The first thing at is in my code is the start session command.

The error message indicates that your start_session() call is on line 3
and that output was started at line 2. Try pasting the first 5 lines of
that adminlogin.php script here. The other thing that is normally useful
is to have a look at the raw bytes in the file. Try this:

  od -c adminlogin.php | head

from your command line. That will tell you exactly what is in the file.
Sometimes editors try to be a little bit too smart for their own good.

-Rasmus

attached mail follows:


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.

[thomasthomas 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
[thomasthomas property]$

Thanks
Thomas

On 7/16/05, Rasmus Lerdorf <rasmusphp.net> wrote:
> On Sat, 16 Jul 2005, Thomas Bonham wrote:
> > Jasper Bryant-Greene wrote:
> > > Thomas Bonham wrote:
> > >
> > >> Hello All,
> > >> I'm working on session and I'm getting this warning. Maybe someone can
> > >> help fixing this problem. Below is the following code.
> > >>
> > >> Warning: Warning: session_start() [function.session-start]: Cannot
> > >> send session
> > >> cookie - headers already sent by (output started at
> > >> /var/www/html/bonham/cornerstone-data/property/adminlogin.php:2) in
> > >> /var/www/html/bonham/cornerstone-data/property/adminlogin.php on line
> > >> 3
> > >
> > >
> > > Are you absolutely sure that there is *no* output before the
> > > session_start() in adminlogin.php?
> > >
> > > If there is it won't work. Even a space before the first <?php, or a
> > > Unicode BOM, or any kind of output can screw it up.
> > >
> > > Jasper
> >
> > The first thing at is in my code is the start session command.
>
> The error message indicates that your start_session() call is on line 3
> and that output was started at line 2. Try pasting the first 5 lines of
> that adminlogin.php script here. The other thing that is normally useful
> is to have a look at the raw bytes in the file. Try this:
>
> od -c adminlogin.php | head
>
> from your command line. That will tell you exactly what is in the file.
> Sometimes editors try to be a little bit too smart for their own good.
>
> -Rasmus
>

--
------------------------------------------------------------------
Thomas Bonham
thomasbbonhamgmail.com
bonhamlinux.org
Cell 602-402-9786

attached mail follows:


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.
>
> [thomasthomas 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

attached mail follows:


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
>

Unless I didnt understood you.. you can easily use foreach() for that.
If you want to loop over it again and again and echo it inside you can
also just make a for() loop and in it make print_r(), if you want to use
the values of the array inside the for() you can again use foreach()
inside it just remember that after the foreach() end you need to do
reset() to the array to repeat the process again with the for().

Cheers,
Ben-Nes Yonatan

attached mail follows:


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?