OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
From: php-general-digest-helplists.php.net
Date: Mon Aug 20 2001 - 00:01:47 CDT

  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

    php-general Digest 20 Aug 2001 05:01:47 -0000 Issue 826

    Topics (messages 63407 through 63451):

    Re: MySQL substrings?
            63407 by: Chris Lambert
            63438 by: David Robley

    HTTPS oddity
            63408 by: Nigel Jewell
            63422 by: Richard Lynch
            63431 by: speedboy

    Function to Build Trees
            63409 by: Sondra Russell
            63424 by: Richard Lynch

    Sessions in pop-up windows
            63410 by: Chris Cameron
            63415 by: Quentin Gillet
            63427 by: Richard Lynch

    Re: Errors
            63411 by: Steve Edberg

    Re: virtual() ignoring str_replace()
            63412 by: CC Zona
            63414 by: jimw.apache.org

    Re: Weird problems passing variables
            63413 by: JOHANSSON JÖRGEN

    FrontBase?
            63416 by: Stephen Cremin

    Two-Byte Regular Expressions
            63417 by: Stephen Cremin
            63433 by: Yasuo Ohgaki

    PHP to EJB (Sybase EP, Jaguar engine)
            63418 by: Alain Fontaine

    Passing variables to a file
            63419 by: Seb Frost

    Re: Help with weird error..
            63420 by: Richard Lynch

    Re: coding standards
            63421 by: Richard Lynch

    Re: Shuffle Cards Function
            63423 by: Richard Lynch
            63432 by: Tom Carter
            63442 by: Robert Schultz

    Re: sendmail
            63425 by: Richard Lynch

    Re: --enable-memory-limit - What does it do?
            63426 by: Richard Lynch

    Re: PHP based authentification -----------
            63428 by: Richard Lynch

    strange upload/db-insert problem with ie5.5
            63429 by: Serge Adamowsky

    showing submitted images
            63430 by: Simon Lysbjerg Hansen

    Include/requrie secure pages
            63434 by: TomazSa

    passing variables between PHP and Perl
            63435 by: Tom Beidler

    Using mcrypt in PHP
            63436 by: Dr. Evil
            63437 by: Jason Brooke

    array in and out
            63439 by: Chris Schneck
            63440 by: David Robley
            63444 by: CC Zona

    Re: array_unique() and count issue
            63441 by: David Robley

    option tags and WHILE
            63443 by: CGI GUY
            63445 by: CC Zona
            63451 by: David Robley

    Oudoor database website - waypoints - please review
            63446 by: WildOutThere

    Re: Count total
            63447 by: Don Read

    flash and mysql
            63448 by: Jack

    unix permission converter
            63449 by: Raphael Pirker

    security check - virtual host and mod php setup
            63450 by: Dave

    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:


    It'd help if you have us the mysql_error() returned.

    Try the following:

    SELECT *, substring_date AS SUBSTRING(date,5,2) FROM $table ORDER BY
    substring_date

    /* Chris Lambert, CTO - chriswhitecrown.net
    WhiteCrown Networks - More Than White Hats
    Web Application Security - www.whitecrown.net
    */

    ----- Original Message -----
    From: Seb Frost <sebraceshoot.com>
    To: Tom Carter <subsroundcorners.com>; <php-generallists.php.net>
    Sent: Sunday, August 19, 2001 11:19 AM
    Subject: RE: [PHP] MySQL substrings?

    | This doesn't work:
    |
    | $result = mysql_query("SELECT * FROM $table ORDER BY SUBSTRING(date,5,2)")
    |
    | Any idea why?
    |
    | - seb
    |
    | --
    | PHP General Mailing List (http://www.php.net/)
    | To unsubscribe, e-mail: php-general-unsubscribelists.php.net
    | For additional commands, e-mail: php-general-helplists.php.net
    | To contact the list administrators, e-mail: php-list-adminlists.php.net
    |
    |
    |

    attached mail follows:


    On Mon, 20 Aug 2001 02:12, Chris Lambert wrote:
    > It'd help if you have us the mysql_error() returned.
    >
    > Try the following:
    >
    > SELECT *, substring_date AS SUBSTRING(date,5,2) FROM $table ORDER BY
    > substring_date
    >

    Date is a reserved word in Mysql. Also, that might work better, after
    renaming the field from date, as

    SELECT *, SUBSTRING(datefield,5,2) AS substring_date FROM $table ORDER BY
     substring_date

    >
    > ----- Original Message -----
    > From: Seb Frost <sebraceshoot.com>
    > To: Tom Carter <subsroundcorners.com>; <php-generallists.php.net>
    > Sent: Sunday, August 19, 2001 11:19 AM
    > Subject: RE: [PHP] MySQL substrings?
    >
    > | This doesn't work:
    > |
    > | $result = mysql_query("SELECT * FROM $table ORDER BY
    > | SUBSTRING(date,5,2)")
    > |
    > | Any idea why?
    > |
    > | - seb
    > |

    -- 
    David Robley      Techno-JoaT, Web Maintainer, Mail List Admin, etc
    CENTRE FOR INJURY STUDIES      Flinders University, SOUTH AUSTRALIA  
    

    Oxymoron: Soviet Life.

    attached mail follows:


    Dear all,

    I have a SSL server set up and I check in PHP that its running over SSL by doing:

    if ($HTTPS) { ... }

    This has worked for ages - but sometime last night the behaviour of my/our server changed and now over an non-SSL connection, $HTTPS = ON and over a SSL connection $HTTPS = on (note the change in case). This is odd - and I can't find the source.

    Unfortunately I'm not the only one with admin access to the server - so someone may have changed something :(.

    Anyone got any ideas? Where to start looking?

    Thanks,

    Nige.

    --
    URL: http://www.grufty.co.uk
    

    attached mail follows:


    Try throwing a <?php phpinfo();?> on each port and see what else you are getting...

    --
    WARNING richardzend.com address is an endangered species -- Use
    ceol-i-e.com
    Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
    Volunteer a little time: http://chatmusic.com/volunteer.htm
    ----- Original Message -----
    From: Nigel Jewell <nigel.jewellpixexcel.co.uk>
    Newsgroups: php.general
    To: <php-generallists.php.net>
    Sent: Sunday, August 19, 2001 12:12 PM
    Subject: HTTPS oddity
    

    > Dear all, > > I have a SSL server set up and I check in PHP that its running over SSL by > doing: > > if ($HTTPS) { > .. > } > > This has worked for ages - but sometime last night the behaviour of my/our > server changed and now over an non-SSL connection, $HTTPS = ON and over a > SSL connection $HTTPS = on (note the change in case). This is odd - and I > can't find the source. > > Unfortunately I'm not the only one with admin access to the server - so > someone may have changed something :(. > > Anyone got any ideas? Where to start looking? > > Thanks, > > Nige. > > -- > URL: http://www.grufty.co.uk >

    attached mail follows:


    > Try throwing a <?php phpinfo();?> on each port and see what else you are > getting... > > > > This has worked for ages - but sometime last night the behaviour of my/our > > server changed and now over an non-SSL connection, $HTTPS = ON and over a > > SSL connection $HTTPS = on (note the change in case). This is odd - and I > > can't find the source.

    I can't remember what I did, but this happened to me as well. I have a check https function. I restarted apache and I think it worked. phpinfo still showed the $HTTPS variable but I could not use it inside a function even though I had it set as a global variable. Try restarting...

    attached mail follows:


    Hello everyone,

    I've been tearing my hair out trying to write a function in PHP that will accomplish the following:

    Given a multidimensional array with words as keys, I want to match the values of each array with the keys of the array and build a new array that reflects these relationships as a sort of tree. So, in the list below, "fruit", "apples", "oranges", "red" are the keys and in the "fruit" array are the values "apples" and "oranges", so I want the function to create a new array that looks like:

    ORIGINAL ARRAY: $array['fruits'] = array("apples","oranges","pears"); $array['apples'] = array("red","granny smith"); $array['oranges'] = array('mandarin'); $array['red'] = array("big red","small red");

    NEW ARRAY: $array['fruits'] = array(apples,oranges,pears); $array['fruits']['apples'] = array("red","granny smith"); $array['fruits']['oranges'] = array('mandarin');

    And then I want it further to figure out that "red", now in the array found at: $array['fruits']['apples'] matches a key in the original array so the final result looks like:

    FINAL ARRAY: $array['fruits'] = array(apples,oranges,pears); $array['fruits']['oranges'] = array('mandarin'); $array['fruits']['apples'] = array("red","granny smith"); $array['fruits']['apples']['red'] = array("big red","small red");

    So, you see how it builds a little tree, right?

    AND, I'd like this function to be able to handle any number (probably less that 30, but whatever) of initial array elements in an unpredictable order and the final tree could have up to five or six levels. You know?

    Is this impossible, or am I just going about the end result wrong?? It seemed like such a simple thing three days ago, but now I am about to cry uncle.

    Anyway, please write if you have any thoughts.

    Best, Sondra Russell

    attached mail follows:


    > Given a multidimensional array with words as keys, I want to match > the values of each array with the keys of the array and build a new > array that reflects these relationships as a sort of tree. So, in > the list below, "fruit", "apples", "oranges", "red" are the keys and > in the "fruit" array are the values "apples" and "oranges", so I want > the function to create a new array that looks like: > > ORIGINAL ARRAY: > $array['fruits'] = array("apples","oranges","pears"); > $array['apples'] = array("red","granny smith"); > $array['oranges'] = array('mandarin'); > $array['red'] = array("big red","small red"); > > NEW ARRAY: > $array['fruits'] = array(apples,oranges,pears); > $array['fruits']['apples'] = array("red","granny smith"); > $array['fruits']['oranges'] = array('mandarin');

    Something not unlike this:

    # UNTESTED CODE: # Change the 1's to 0's to get rid of debugging output: function buildTree(&$original, $key = 'fruits', $level = 1){ if (1) echo str_repeat('&gt;', $level), $key, "&nbsp;&nbsp;&nbsp;-&gt;", key($original), "<BR>\n"; $result = array(); if (is_array($original[$key])){ while (list($k, $v) = each($original[$key])){ $result[$key][$k] = buildTree($v, $k, $level++); } } else{ $result[$key][$k] = $value; } if (1) echo str_repeat('&lt;', $level), "<BR>\n"; return $result; }

    --
    WARNING richardzend.com address is an endangered species -- Use
    ceol-i-e.com
    Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
    Volunteer a little time: http://chatmusic.com/volunteer.htm
    

    attached mail follows:


    I'm having some issues passing a session to a pop-up window.

    The pop-up window is you average DreamWeaver popup: <a href="#" onClick="MM_openBrWindow('prod_detail_pop.php','','width=500,height=350')">Link</a>

    When you click on the link, the session doesn't get passed. I have trans-sid enabled.

    Any ideas on how I could go about passing my sid?

    Thanks, Chris

    -- 
    Chris Cameron
    System Administrator
    UpNIX Internet Services
    http://www.upnix.com/
    

    attached mail follows:


    be sure session.auto_start=1 and session.use_trans_sid=1 and that session.gc_maxlifetime has a reasonable value

    -----Message d'origine----- De : Chris Cameron [mailto:chrisupnix.com] Envoye : dimanche 19 aout 2001 20:28 A : php-generallists.php.net Objet : [PHP] Sessions in pop-up windows

    I'm having some issues passing a session to a pop-up window.

    The pop-up window is you average DreamWeaver popup: <a href="#" onClick="MM_openBrWindow('prod_detail_pop.php','','width=500,height=350')">L ink</a>

    When you click on the link, the session doesn't get passed. I have trans-sid enabled.

    Any ideas on how I could go about passing my sid?

    Thanks, Chris

    --
    Chris Cameron
    System Administrator
    UpNIX Internet Services
    http://www.upnix.com/
    

    -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribelists.php.net For additional commands, e-mail: php-general-helplists.php.net To contact the list administrators, e-mail: php-list-adminlists.php.net

    attached mail follows:


    If Cookies are off, you may need to provide more than just "#" as the HREF.

    While "#" will "work", it's not technically speaking a valid URL, and PHP is probably not inserting the SID into the URL, or else inserting it in the "wrong" place.

    Use "View Source" in your browser to see what PHP is doing to that HREF.

    --
    WARNING richardzend.com address is an endangered species -- Use
    ceol-i-e.com
    Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
    Volunteer a little time: http://chatmusic.com/volunteer.htm
    ----- Original Message -----
    From: Chris Cameron <chrisupnix.com>
    Newsgroups: php.general
    To: <php-generallists.php.net>
    Sent: Sunday, August 19, 2001 1:28 PM
    Subject: Sessions in pop-up windows
    

    > I'm having some issues passing a session to a pop-up window. > > The pop-up window is you average DreamWeaver popup: > <a href="#" > onClick="MM_openBrWindow('prod_detail_pop.php','','width=500,height=350')">L ink</a> > > When you click on the link, the session doesn't get passed. I have > trans-sid enabled. > > Any ideas on how I could go about passing my sid? > > Thanks, > Chris > > -- > Chris Cameron > System Administrator > UpNIX Internet Services > http://www.upnix.com/ >

    attached mail follows:


    Well, since you're getting a PHP error, PHP is obviously parsing the page. My guess is that your error reporting (in php.ini, httpd.conf or .htaccess) is set very high, so that uninitialized variables generate a warning. You could either (1) initialize $page at the top of your program:

    $page = false;

    or (2) lower the warning level:

    http://www.php.net/manual/en/features.error-handling.php http://www.php.net/manual/en/configuration.php http://www.php.net/manual/en/ref.errorfunc.php

    If $page is coming from somewhere else (eg; GET/POST parameters) then you can test for its existence like so:

    if (!isset($page)) { $page = false; }

    or $page = 0...whatever's appropriate.

    -steve

    At 4:45 PM +0200 8/19/01, BRACK wrote: >Hi > >I'm getting strange errors if I add >"LoadModule php4_module ../php/sapi/php4apache.dll" to http.conf >If I don't load it everything is working with php.exe without any >errors but as I >load it as a modul I get for example - >Warning: Undefined variable: page in d:\abria >sql\apache\htdocs\inc\page.inc on line 2 > here is the page.inc file: ><?php  >if (!$page): > $page = 1; >endif; >$limit = ($page * 10) - 10; >?> > >What is wrong? I need php as a modul but what do I do >wrong, I did everything according to install.txt in php >directory. > >Thank you > >Youri > ><>< <>< <>< <>< God is our provider ><> ><> ><> ><> >http://www.body-builders.org >

    -- 
    +------------------------ Open source questions? ------------------------+
    | Steve Edberg                           University of California, Davis |
    | sbedbergucdavis.edu                               Computer Consultant |
    | http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
    +----------- http://pgfsun.ucdavis.edu/open-source-tools.html -----------+
    

    attached mail follows:


    In article <B7A5566D.2116C%listsjumpinternet.com>, listsjumpinternet.com (Charlie Romero) wrote:

    > it just prints the virtual include w/out replacing > the word "window" w/ the word "DOG" in my example. What am I doing wrong? > > $results = virtual("/cgi-bin/search.cgi?q=hello&m=world"); > print str_replace("window", "DOG", $results);

    str_replace() is case-sensitive. If $results is returning a string like "Windows are nice" (it would help to see the actual string next time...hint hint), it won't match "window".

    -- 
    CC
    

    attached mail follows:


    Charlie Romero <listsjumpinternet.com> wrote: > $results = virtual("/cgi-bin/search.cgi?q=hello&m=world");

    virtual doesn't return the content of the subrequest, it sends it to the browser.

    you need to use something like popen() to do what you're trying to do.

    jim

    attached mail follows:


    Thanks dude, that looks way nicer. I did however get it working by changing the casting (tried to post my correction, but hit the wrong button), the corrected, and after Lynch's enlightening me on mktime´s behaviour even butt uglier code can be found below. (Change in arguments is solely due to a redesign of the form).

    On a mere philosophical level I'd like to know how the original code could work on IE5, it's also got a dead obvious bug in the zeroPadDate() function (didn't set $mstr or $dstr when month>=10 or day>=10). And no, it wasn't due to using different arguments to the script on the different browsers...

    Anyway, thanks! //Claes

    /* Function getDates(from, to) takes strings containing dates in the form "YYYY-MM-DD" and returns an array containing the dates between "from" and "to" inclusive */

    function getDates($f_year, $f_month, $f_date, $t_year, $t_month, $t_date) { $year=(int) $f_year; $month=(int) $f_month; $date=(int) $f_date; $to=zeroPadDate((int) $t_year, (int) $t_month,(int) $t_date); $datearray[0]=zeroPadDate($year, $month, $date); $current=$datearray[0]; while($current!=$to) { $date=$date+1; if(checkdate($month, $date, $year)) { $current=zeroPadDate($year, $month, $date); $datearray[]=$current; } else { $month=$month+1; $date=1; if (checkdate($month, $date, $year)) { $current=zeroPadDate($year, $month, $date); $datearray[]=$current; } else { $year=$year+1; $month=1; $current=zeroPadDate($year, $month, $date); $datearray[]=$current; } } } return $datearray; }

    /* Accessory function to getDates above. */

    function zeroPadDate($year, $month, $date) { if ($month<10) { $mstr="0$month"; } else { $mstr=$month; } if ($date<10) { $dstr="0$date"; } else { $dstr=$date; } return "$year-$mstr-$dstr"; }

    attached mail follows:


    The thread discussing the relative merits of mySQL and PostgreSQL have been very informative. I've been looking at the possibility of using FrontBase (http://www.frontbase.com/), primarily for its support of ACID and Unicode since I'm primarily working with Chinese, Japanese and Korean data. Moving from mySQL to FrontBase also seems to be relatively painless (although that isn't a consideration for me now choosing a database). Does anybody have good/bad experience working with FrontBase?

    Stephen

    attached mail follows:


    I note that the latest build of PHP4 comes with Japanese string support. Does this include support for two-byte regular expressions? If yes, does it also work with Chinese and Korean text? If no, what other options do I have without, for example, going through say JPerl or whatever?

    Stephen Cremin

    attached mail follows:


    "Stephen Cremin" <asianfilmlibrarymac.com> wrote in message news:20010819210056.XGVA20588.mta05-svc.ntlworld.com[62.252.202.64].. . > I note that the latest build of PHP4 comes with Japanese string support. > Does this include support for two-byte regular expressions? If yes, does it > also work with Chinese and Korean text? If no, what other options do I have > without, for example, going through say JPerl or whatever?

    mbstring module does not support multi-byte regex.

    There is multi-byte encoding regular expression module called mbregex which is not a std PHP extension. It probably works with EUC-TW/EUC-KR.

    ftp://night.fminn.nagano.nagano.jp/php4/

    I don't use it lately, but I think it comes with Japanese instruction only.

    --
    Yasuo Ohgaki
    

    attached mail follows:


    Hello,

    I'm looking for ressources, links, articles, or contacts regarding the above subject, namely interfacing PHP to an EJB, particularly Sybase Enterprise Portal (formerly known as Jaguar).

    Thanks for any input, I appreciate it.

    attached mail follows:


    OK I know this can be done like so:

    file.php4?foo=bar

    but what if I want to keep the value of foo secret from the user?

    - seb

    attached mail follows:


    > anyone know what > Fatal error: input in flex scanner failed in /home/k/kyle/public_html on line > means?

    Either the PHP compilation itself is whack, or you typed something so unlike PHP script that you've *really* managed to confuse it...

    Do other PHP scripts work?

    What's your source look like?

    --
    WARNING richardzend.com address is an endangered species -- Use
    ceol-i-e.com
    Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
    Volunteer a little time: http://chatmusic.com/volunteer.htm
    

    attached mail follows:


    > - Is declaring all variables a good idea - so theres no unassigned > variables hanging around ? (no warnings produced when error reporting > set to E_ALL)

    You mean INITIALIZING. There are no variable declarations in PHP.

    And, yes, it's a good idea so you're never surprised by a variable that you end up using twice.

    > - Naming of include files - .inc or .php ? > - naming of class files .inc or .php ?

    Name them .inc, *AND* move them outside the web tree if you can++, *AND* configure Apache to NEVER, EVER serve up an .inc file in any way, shape, or form.

    ++ The scale and scope of your project may require so many .inc files with the same names that you need to place them in the same directory as the PHP files that use them. Just be sure Apache won't serve them up.

    --
    WARNING richardzend.com address is an endangered species -- Use
    ceol-i-e.com
    Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
    Volunteer a little time: http://chatmusic.com/volunteer.htm
    

    attached mail follows:


    http://php.net/shuffle will be much faster and just as random...

    --
    WARNING richardzend.com address is an endangered species -- Use
    ceol-i-e.com
    Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
    Volunteer a little time: http://chatmusic.com/volunteer.htm
    ----- Original Message -----
    From: Robert Schultz <bertncinter.net>
    Newsgroups: php.general
    To: <php-generallists.php.net>
    Sent: Saturday, August 18, 2001 11:37 PM
    Subject: Shuffle Cards Function
    

    > I've written a ShuffleCards function that will actually shuffle a deck of > cards just like would happen in real life (divide the deck in half and stick > them into each other with 1-3 cards between each other card) > > function ShuffleCards(&$cardsArray, $times) > { > // Randomizes where to split within center (-3 to +3 from dead center) > (MINIMUM 10 CARDS IN DECK) > // Splits into two array. Randomizes how many cards from left and how > many cards from right (between 1 and 3) > // Alternates sides. Continues until both arrays are empty. > $arraySize = count($cardsArray); > > if($arraySize<10) > return; > > $deadCenter = $arraySize/2; > > for($i=0;$i<$times;$i++) > { > reset($cardsArray); > > $cutVariant = rand(-3, 3); > $cutLocation = $deadCenter+$cutVariant; > > $firstArray = array(); > $secondArray = array(); > > for($z=0;$z<$arraySize;$z++) > { > if($z<$cutLocation) > array_push($firstArray, $cardsArray[$z]); > else > array_push($secondArray, $cardsArray[$z]); > } > > $bottomFirst = rand(0, 1); > $cardsArray = array(); > > while(count($firstArray) && count($secondArray)) > { > $leftNewCards = array(); > $rightNewCards = array(); > > $leftVariant = rand(1, 3); > if($leftVariant>count($firstArray)) > $leftVariant = count($firstArray); > > $rightVariant = rand(1, 3); > if($rightVariant>count($secondArray)) > $rightVariant = count($secondArray); > > > for($x=0;$x<$leftVariant;$x++) > { > array_push($leftNewCards, array_shift($firstArray)); > } > > for($y=0;$y<$rightVariant;$y++) > { > array_push($rightNewCards, array_shift($secondArray)); > } > > if($bottomFirst==0) > { > $newCardsArray = array_merge($leftNewCards, $rightNewCards); > $bottomFirst = 1; > } > else > { > $newCardsArray = array_merge($rightNewCards, $leftNewCards); > $bottomFirst = 0; > } > > reset($newCardsArray); > > while(count($newCardsArray)) > { > array_push($cardsArray, array_shift($newCardsArray)); > } > } > > if(count($firstArray)) > { > while(count($firstArray)) > array_push($cardsArray, array_shift($firstArray)); > } > if(count($secondArray)) > { > while(count($secondArray)) > array_push($cardsArray, array_shift($secondArray)); > } > } > } > > Robert Schultz - bertncinter.net > > >

    attached mail follows:


    I could be wrong in thinking this, but wasn't the purpose of the presented function to shuffle a deck in a deliberately imperfecatly random way? ie. mimicking a human shuffler.... beats why one would want to do this as an academic excersize, but hey, I like it ;-) ----- Original Message ----- From: "Richard Lynch" <ceol-i-e.com> To: <php-generallists.php.net> Sent: Sunday, August 19, 2001 9:45 PM Subject: [PHP] Re: Shuffle Cards Function

    > http://php.net/shuffle will be much faster and just as random... > > -- > WARNING richardzend.com address is an endangered species -- Use > ceol-i-e.com > Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm > Volunteer a little time: http://chatmusic.com/volunteer.htm > ----- Original Message ----- > From: Robert Schultz <bertncinter.net> > Newsgroups: php.general > To: <php-generallists.php.net> > Sent: Saturday, August 18, 2001 11:37 PM > Subject: Shuffle Cards Function > > > > I've written a ShuffleCards function that will actually shuffle a deck of > > cards just like would happen in real life (divide the deck in half and > stick > > them into each other with 1-3 cards between each other card) > > > > function ShuffleCards(&$cardsArray, $times) > > { > > // Randomizes where to split within center (-3 to +3 from dead center) > > (MINIMUM 10 CARDS IN DECK) > > // Splits into two array. Randomizes how many cards from left and how > > many cards from right (between 1 and 3) > > // Alternates sides. Continues until both arrays are empty. > > $arraySize = count($cardsArray); > > > > if($arraySize<10) > > return; > > > > $deadCenter = $arraySize/2; > > > > for($i=0;$i<$times;$i++) > > { > > reset($cardsArray); > > > > $cutVariant = rand(-3, 3); > > $cutLocation = $deadCenter+$cutVariant; > > > > $firstArray = array(); > > $secondArray = array(); > > > > for($z=0;$z<$arraySize;$z++) > > { > > if($z<$cutLocation) > > array_push($firstArray, $cardsArray[$z]); > > else > > array_push($secondArray, $cardsArray[$z]); > > } > > > > $bottomFirst = rand(0, 1); > > $cardsArray = array(); > > > > while(count($firstArray) && count($secondArray)) > > { > > $leftNewCards = array(); > > $rightNewCards = array(); > > > > $leftVariant = rand(1, 3); > > if($leftVariant>count($firstArray)) > > $leftVariant = count($firstArray); > > > > $rightVariant = rand(1, 3); > > if($rightVariant>count($secondArray)) > > $rightVariant = count($secondArray); > > > > > > for($x=0;$x<$leftVariant;$x++) > > { > > array_push($leftNewCards, array_shift($firstArray)); > > } > > > > for($y=0;$y<$rightVariant;$y++) > > { > > array_push($rightNewCards, array_shift($secondArray)); > > } > > > > if($bottomFirst==0) > > { > > $newCardsArray = array_merge($leftNewCards, $rightNewCards); > > $bottomFirst = 1; > > } > > else > > { > > $newCardsArray = array_merge($rightNewCards, $leftNewCards); > > $bottomFirst = 0; > > } > > > > reset($newCardsArray); > > > > while(count($newCardsArray)) > > { > > array_push($cardsArray, array_shift($newCardsArray)); > > } > > } > > > > if(count($firstArray)) > > { > > while(count($firstArray)) > > array_push($cardsArray, array_shift($firstArray)); > > } > > if(count($secondArray)) > > { > > while(count($secondArray)) > > array_push($cardsArray, array_shift($secondArray)); > > } > > } > > } > > > > Robert Schultz - bertncinter.net > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribelists.php.net > For additional commands, e-mail: php-general-helplists.php.net > To contact the list administrators, e-mail: php-list-adminlists.php.net >

    attached mail follows:


    Well, I required a function to mimick a human shuffle. Because the online shuffle was to help the user predict what sort/types of deals he would get with a given deck based upon a normal human shuffle.

    Plus, I've heard some bad things about shuffle, and of course, shuffe doesn't mimick a non-perfect human shuffle.

    Robert Schultz - bertncinter.net

    ----- Original Message ----- From: "Tom Carter" <subsroundcorners.com> To: "Richard Lynch" <ceol-i-e.com>; <php-generallists.php.net> Sent: Sunday, August 19, 2001 7:00 PM Subject: Re: [PHP] Re: Shuffle Cards Function

    > I could be wrong in thinking this, but wasn't the purpose of the presented > function to shuffle a deck in a deliberately imperfecatly random way? ie. > mimicking a human shuffler.... beats why one would want to do this as an > academic excersize, but hey, I like it ;-) > ----- Original Message ----- > From: "Richard Lynch" <ceol-i-e.com> > To: <php-generallists.php.net> > Sent: Sunday, August 19, 2001 9:45 PM > Subject: [PHP] Re: Shuffle Cards Function > > > > http://php.net/shuffle will be much faster and just as random... > > > > -- > > WARNING richardzend.com address is an endangered species -- Use > > ceol-i-e.com > > Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm > > Volunteer a little time: http://chatmusic.com/volunteer.htm > > ----- Original Message ----- > > From: Robert Schultz <bertncinter.net> > > Newsgroups: php.general > > To: <php-generallists.php.net> > > Sent: Saturday, August 18, 2001 11:37 PM > > Subject: Shuffle Cards Function > > > > > > > I've written a ShuffleCards function that will actually shuffle a deck > of > > > cards just like would happen in real life (divide the deck in half and > > stick > > > them into each other with 1-3 cards between each other card) > > > > > > function ShuffleCards(&$cardsArray, $times) > > > { > > > // Randomizes where to split within center (-3 to +3 from dead > center) > > > (MINIMUM 10 CARDS IN DECK) > > > // Splits into two array. Randomizes how many cards from left and > how > > > many cards from right (between 1 and 3) > > > // Alternates sides. Continues until both arrays are empty. > > > $arraySize = count($cardsArray); > > > > > > if($arraySize<10) > > > return; > > > > > > $deadCenter = $arraySize/2; > > > > > > for($i=0;$i<$times;$i++) > > > { > > > reset($cardsArray); > > > > > > $cutVariant = rand(-3, 3); > > > $cutLocation = $deadCenter+$cutVariant; > > > > > > $firstArray = array(); > > > $secondArray = array(); > > > > > > for($z=0;$z<$arraySize;$z++) > > > { > > > if($z<$cutLocation) > > > array_push($firstArray, $cardsArray[$z]); > > > else > > > array_push($secondArray, $cardsArray[$z]); > > > } > > > > > > $bottomFirst = rand(0, 1); > > > $cardsArray = array(); > > > > > > while(count($firstArray) && count($secondArray)) > > > { > > > $leftNewCards = array(); > > > $rightNewCards = array(); > > > > > > $leftVariant = rand(1, 3); > > > if($leftVariant>count($firstArray)) > > > $leftVariant = count($firstArray); > > > > > > $rightVariant = rand(1, 3); > > > if($rightVariant>count($secondArray)) > > > $rightVariant = count($secondArray); > > > > > > > > > for($x=0;$x<$leftVariant;$x++) > > > { > > > array_push($leftNewCards, array_shift($firstArray)); > > > } > > > > > > for($y=0;$y<$rightVariant;$y++) > > > { > > > array_push($rightNewCards, array_shift($secondArray)); > > > } > > > > > > if($bottomFirst==0) > > > { > > > $newCardsArray = array_merge($leftNewCards, $rightNewCards); > > > $bottomFirst = 1; > > > } > > > else > > > { > > > $newCardsArray = array_merge($rightNewCards, $leftNewCards); > > > $bottomFirst = 0; > > > } > > > > > > reset($newCardsArray); > > > > > > while(count($newCardsArray)) > > > { > > > array_push($cardsArray, array_shift($newCardsArray)); > > > } > > > } > > > > > > if(count($firstArray)) > > > { > > > while(count($firstArray)) > > > array_push($cardsArray, array_shift($firstArray)); > > > } > > > if(count($secondArray)) > > > { > > > while(count($secondArray)) > > > array_push($cardsArray, array_shift($secondArray)); > > > } > > > } > > > } > > > > > > Robert Schultz - bertncinter.net > > > > > > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribelists.php.net > > For additional commands, e-mail: php-general-helplists.php.net > > To contact the list administrators, e-mail: php-list-adminlists.php.net > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribelists.php.net > For additional commands, e-mail: php-general-helplists.php.net > To contact the list administrators, e-mail: php-list-adminlists.php.net >

    attached mail follows:


    > I'm on virtual hosting that lets me configure anything with .htaccess > file. I was recomended by provider to specify location of sendmail in > case I want to use php mail() function I know that I may do it in > htaccess file by adding php_value sendmail_path > /usr/sbin/sendmail The qwestion is can I do anything else but > correcting the path in .htaccess, this is the last thing I want to do.

    First of all, you'll need:

    php_value sendmail_path "/usr/sbin/sendmail -t"

    Yes, you need the quotes. And possibly some other options inside quotes depending on your ISP's configuration of sendmail.

    I don't understand your ISP's rationale for requiring you to do this in .htaccess instead of just doing it himself... Either he's letting you use mail() or he's not.

    I also don't understand why you are loathe to do this... Unless you've heard ".htaccess is slow" (which it is). Alas, since your ISP has already turned on .htaccess support, you're *NOT* causing any additional significant slow-down to *utilize* the feature. The slowness is in Apache looking for the damn file, not in your putting (reasonable) stuff in it.

    Oh yeah, to answer your original question :-)

    You probably *COULD* set up an SMTP server on some other machine and just fsockopen() to that SMTP server and spew your emails to that. This will be way more faster anyway. Or, perhaps your ISP has an SMTP server that PHP can fsockopen() and spew to. Depends on how he configured it. There's all sorts of sample code for this SMTP spewing, so you needn't write it from scratch -- though it ain't rocket science. I did it, so it *CANNOT* be that difficult. :-)

    --
    WARNING richardzend.com address is an endangered species -- Use
    ceol-i-e.com
    Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
    Volunteer a little time: http://chatmusic.com/volunteer.htm
    

    attached mail follows:


    I think it allows you to COMPILE the darn thing when you've only got, like, 16Mb machine...

    Or *MAYBE* it's the thing in php.ini about limiting how much RAM a PHP script can chew up before puking...

    It *SHOULD* be documented on http://php.net in the Installation and Configuration section.

    --
    WARNING richardzend.com address is an endangered species -- Use
    ceol-i-e.com
    Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
    Volunteer a little time: http://chatmusic.com/volunteer.htm
    ----- Original Message -----
    From: Kai Schaetzl <maillistsconactive.com>
    Newsgroups: php.general
    To: <php-generallists.php.net>
    Sent: Sunday, August 19, 2001 11:27 AM
    Subject: --enable-memory-limit - What does it do?
    

    > Well, there's no explanation for it in the manual and I didn't find > any by searching all relevant archives with deja. So, what does it > EXACTLY do when I compile it in and are there configuration options > for it? (f.i. the amount of memory to limit to ;-) > > > Kai > > -- > > Kai Schätzl, Berlin, Germany > Get your web at Conactive Internet Services: http://www.conactive.com > IE-Center: http://ie5.de & http://msie.winware.org > ClubWin - Help for Windows Users: http://www.clubwin.com > > >

    attached mail follows:


    > How can I "logout" from a PHP based auth (with PHP_AUTH_USER and PHP_AUTH_PW > and appropriate headers sent at the beginning)? > It seems like unset($PHP_AUTH_USER) does not wotk in this case...

    unset() won't do anything because the *BROWSER* re-sends the username/password for that Realm when it gets the headers requiring them.

    This continues until the user quits the browser, *OR* you stop authenticating for that Realm and start authenticating for another.

    Thus, the way to "logout" is to maintain a dynamic unique dataset of "Realms" and require authentication in a new Realm for any user that is "logged out".

    --
    WARNING richardzend.com address is an endangered species -- Use
    ceol-i-e.com
    Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
    Volunteer a little time: http://chatmusic.com/volunteer.htm
    

    attached mail follows:


    dear community,

    i've got a script which handles the correct upload of certain documents. the way: 1)select the document, then upload through form with method post -> target same document 2)do the checking stuff with the document, if ok call the same script again for displaying the property-page -> form-target same document 3) if everything went well, document-properties are inserted in the db in two tables, then script displays js-redirect to do more stuff with the doc. the problem here is, that although no browser goes wrong, except explorer 5.5 (sp2). using this version, the document's properties are inserted twice, both relating to the same physical doc but with different ids. did anyone ever had same effects or even the remedy for this particular problem? (remedy "get rid of stinkin' ms-junk" won't help, since customer is tied to this trash ;)

    thanks serge

    attached mail follows:


    Please help,

    I'm trying to submit a .jpg image via a html form and showing it with the following piece of code

    <?php if ($submit) { header("Content-type: $form_data_type"); $data = fread(fopen($form_data, "r"), filesize($form_data)); echo $data; } else { ?> <form method="post" action="<?php echo $PHP_SELF ?>" enctype="multipart/form-data"> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000"> <br>File to show:<br> <input type="file" name="form_data" size="40"> <p><input type="submit" name="submit" value="submit"> </form> <?php } ?>

    but I only get the binary contents of the .jpg file. What's wrong?

    My hostmaster has an infobar running at the top of my page [check www.oss-fodbold.dk to see what I mean]. Is this the problem?

    Thanks in advance

    Simon

    attached mail follows:


    I can not include / require secure pages (https). Is that the way it is in php? If so how can I do that another way?

    lp, tomaz

    attached mail follows:


    I'm integrating a telephony service into a clients site. I'm pretty handy with PHP but I don't have much knowledge of perl. I've setup up my client's site using PHP and the service provided me with a Perl script to make the telephone connection. I used virtual() in my PHP script to pass variables to the Perl script but now I need to deal with passing the results from the Perl back to PHP.

    Is there something like virtual() in Perl that I could use to relay the variables back to my script? Can I call up the Perl variables from my PHP script after virtual()?

    Any help would be appreciated.

    Tom

    attached mail follows:


    There seems to be no reliable information in the manual about how to do this. I'm trying to use mcrypt 2.4 with php4.06, which should be a compatible combination.

    So far, I have gotten it to work like this:

    $cypher = MCRYPT_RIJNDAEL_128; $encrypted = mcrypt_encrypt($cypher, $key, $plaintext, MCRYPT_MODE_ECB); $decrypted = mcrypt_decrypt($cypher, $key, $encrypted, MCRYPT_MODE_ECB);

    However, when I do this, I get an error saying:

    Warning: attempt to use an empty IV, which is NOT recommend in

    So I tried to do the same thing with an IV:

    $iv = mcrypt_create_iv(mcrypt_get_iv_size($cypher, MCRYPT_MODE_ECB), MCRYPT_RANDOM);

    and then added this $iv as an argument to encrypt and decrypt. At this point, it doesn't work, because the iv is different in the encrypt and decrypt functions, because it is randonly generated. Is it true that I need the same iv to encrypt as to decrypt? I'm just not understanding how to use this. All I want to do is to encrypt stuff and then decrypt it, using a key, right? It used to work.

    Thanks.

    attached mail follows:


    hopefully someone who knows what they're doing can reply to you, but in the meantime this should get you going - it works for me:

    $td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "/usr/lib/mcrypt-modes"); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, "your key string here", $iv);

    then just use mdecrypt_generic($td, $data) and mcrypt_generic($td, $data) where $data is your string to encrypt

    ----- Original Message ----- From: "Dr. Evil" <drevilsidereal.kz> To: <php-generallists.php.net> Sent: Monday, August 20, 2001 11:03 AM Subject: [PHP] Using mcrypt in PHP

    > > There seems to be no reliable information in the manual about how to > do this. I'm trying to use mcrypt 2.4 with php4.06, which should be a > compatible combination. > > So far, I have gotten it to work like this: > > $cypher = MCRYPT_RIJNDAEL_128; > $encrypted = mcrypt_encrypt($cypher, $key, $plaintext, MCRYPT_MODE_ECB); > $decrypted = mcrypt_decrypt($cypher, $key, $encrypted, MCRYPT_MODE_ECB); > > However, when I do this, I get an error saying: > > Warning: attempt to use an empty IV, which is NOT recommend in > > So I tried to do the same thing with an IV: > > $iv = mcrypt_create_iv(mcrypt_get_iv_size($cypher, MCRYPT_MODE_ECB), > MCRYPT_RANDOM); > > and then added this $iv as an argument to encrypt and decrypt. At > this point, it doesn't work, because the iv is different in the > encrypt and decrypt functions, because it is randonly generated. Is > it true that I need the same iv to encrypt as to decrypt? I'm just > not understanding how to use this. All I want to do is to encrypt > stuff and then decrypt it, using a key, right? It used to work. > > Thanks. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribelists.php.net > For additional commands, e-mail: php-general-helplists.php.net > To contact the list administrators, e-mail: php-list-adminlists.php.net > >

    attached mail follows:


    Since i have little experience with arrays, and the manuals / readme files online havent been able to help me, I was wondering if anyone had any ideas why this code doesnt work?

    // get the keywords from db $keyquery = ("select fld_keyword_word from tbl_keyword order by rand()"); $keyresult = mysql_query($keyquery) or die ("couldnt randomize words"); // put them into an array

    while ($keyrow = mysql_fetch_array($keyresult)) { $keyword[] = '$keyrow["fld_keyword_word"]'; }

    // print the keywords with a function $mykeywords = implode(", ", $keyword);

    function print_keywords() { echo ($mykewords); }

    attached mail follows:


    On Mon, 20 Aug 2001 11:25, Chris Schneck wrote: > Since i have little experience with arrays, and the manuals / readme > files online havent been able to help me, I was wondering if anyone had > any ideas why this code doesnt work? > > // get the keywords from db > $keyquery = ("select fld_keyword_word from tbl_keyword order by > rand()"); > $keyresult = mysql_query($keyquery) or die ("couldnt randomize > words"); > // put them into an array > > while ($keyrow = mysql_fetch_array($keyresult)) > { > $keyword[] = '$keyrow["fld_keyword_word"]'; > } > > // print the keywords with a function > $mykeywords = implode(", ", $keyword); > > function print_keywords() > { > echo ($mykewords); > }

    What part doesn't work?

    $keyword[] = '$keyrow["fld_keyword_word"]';

    would possibly be better without the single quotes, and I don't se where youe are calling the print_keywords function; which wouldn't work as is because it doesn't have access to the variable $mykeywords either from being passed as a parameter or made available as a global.

    Also you misspelled $mykeywords in the function :-)

    -- 
    David Robley      Techno-JoaT, Web Maintainer, Mail List Admin, etc
    CENTRE FOR INJURY STUDIES      Flinders University, SOUTH AUSTRALIA  
    

    If a fly has no wings would you call him a walk?

    attached mail follows:


    In article <010101c1291b$378fa0a0$0200a8c0no.shawcable.net>, chrishubcityhosting.com (Chris Schneck) wrote:

    > function print_keywords() > { > echo ($mykewords); > }

    $mykeywords is a global var; it's undefined in the function's local scope. Either pass it into the function as a parameter, add it to the $GLOBALS array, or declare it as global within the function.

    <http://php.net/global>

    -- 
    CC
    

    attached mail follows:


    On Sat, 18 Aug 2001 17:27, CGI GUY wrote: > OK, I want to count the number of unique elements in > an array, then print the total. However, both methods > I've tried return "1"; the man pages explain that the > count() function will return 1 if the var is set but > not an array. But if you look at the 2nd method esp., > I've set an if-else !is_set() alert which doesn't > appear... Either way, it's a 1. Help! > > Method 1: > > <? > > $count = > array_unique(mysql_fetch_array($mysql_result)); > > $total = count($count); > > print($total); > > ?>

    mysql_fetch_array only grabs the content of one row returned from a DB query, and puts it in an array - so your array here only has one element.

    > Method 2: > > <? > > $array = mysql_fetch_array($mysql_result); > > $newarray = array_values($array); > > if (!is_array($newarray)) { > print("Not an array"); > > } else { > > $count = array_unique($newarray); > > foreach($count as $key => $value) { > $count[$key] = $value++; > } > > print($value); > > > } > ?>

    As above. You need to cycle through the results from the DB and add them all to the array.

    But having said that, it seems to me that what you are really trying to do is to return unique entries from the database? In this case, look at using the DISTINCT keyword in your SQL query.

    -- 
    David Robley      Techno-JoaT, Web Maintainer, Mail List Admin, etc
    CENTRE FOR INJURY STUDIES      Flinders University, SOUTH AUSTRALIA  
    

    Breathing may be hazardous to your health.

    attached mail follows:


    What's wrong with this code? I keep getting a parse error at the form/select lines...

    $array = mysql_fetch_array($mysql_result) or die("no go");

    print ("<form>"); print ("<select>"); while ($array[1] => $array[0]) { print ("<option value=\"$array[0]\ ">$array[1]</option>\n"); } print ("</select>"); print ("</form>"); ?>

    __________________________________________________ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/

    attached mail follows:


    In article <20010820025346.3445.qmailweb13106.mail.yahoo.com>, cgi_guy1313yahoo.com (Cgi Guy) wrote:

    > What's wrong with this code? I keep getting a parse > error at the form/select lines...

    > print ("<option value=\"$array[0]\">$array[1]</option>\n");

    See if adding curly braces, {$array[1]}, doesn't work better for you.

    -- 
    CC
    

    attached mail follows:


    On Mon, 20 Aug 2001 12:23, CGI GUY wrote: > What's wrong with this code? I keep getting a parse > error at the form/select lines... > > $array = mysql_fetch_array($mysql_result) or die("no > go"); > > print ("<form>"); > print ("<select>"); > while ($array[1] => $array[0]) { > print ("<option value=\"$array[0]\ > ">$array[1]</option>\n"); > } > print ("</select>"); > print ("</form>"); > ?>

    That's an, er, interesting script. But it's not going ever to do what I think you expect it to.

    You need to use while to loop through the rows returned by your SQL query, and for each iteration in the while loop, print the values you need. Also, if you use extract, you can directly access variables that have the same names as the rows in your table, so you don't have to refer to array elements.

    Frinstance, if you are fetching fields named value and label for this exercise, something like:

    echo '<FORM><SELECT>'; while ($array = mysql_fetch_array($mysql_result)) { extract($array); echo '<OPTION VALUE="' . $value . '">' . $label . '</OPTION>'; } echo '</SELECT></FORM>';

    Of course, you'll need to put some more info in your <FORM> tag and add submit buttons and so forth.

    -- 
    David Robley      Techno-JoaT, Web Maintainer, Mail List Admin, etc
    CENTRE FOR INJURY STUDIES      Flinders University, SOUTH AUSTRALIA  
    

    Ensign Expendable, step on that rock! - Kirk

    attached mail follows:


    I just got done (am still improving) building a website to share waypoints and file related. Database is still thin, but i want to know if the features work and are intuitive.

    www.wildoutthere.com

    Features include: online sketching on maps and topos user rating system slide shows upload files search features driving directions (thanks mapblast) topo maps (thanks topozone)

    attached mail follows:


    On 19-Aug-2001 Martin Kampherbeek wrote: > Hi, > > Who can help me with the following problem? > I have the tables score and totalscore. > > Score: > id > userid > name > score > > Totalscore: > userid > name > totalscore > > In the table score one user can have mutiple scores. But in totalscore the > userid is unique. Now I want to count all the score's of a user en place > this at the same user in totalscore. > > Example of score: > 1 1 Martin 10 > 2 2 John 5 > 3 3 Richard 12 > 4 1 Martin 3 > 5 3 Richard 8 > 6 1 Martin 7 > 7 2 John 15 > > So I would like to know the total score of each user. > But I don't know how to do this. Who can help me out? >

    REPLACE INTO Totalscore SELECT userid,name,sum(score) from Score GROUP BY userid;

    Regards,

    -- 
    Don Read                                       dreadtexas.net
    -- It's always darkest before the dawn. So if you are going to 
       steal the neighbor's newspaper, that's the time to do it.
    

    attached mail follows:


    Hi people I want to make a flash file with dynamic content, driven by database(Mysql in this case), is there anyone know where can I get more information about this? Jack jackyactivelifestyle.com "Love your enemies, it will drive them nuts"

    attached mail follows:


    Hi,

    I have written a "Permission Converter" which converts unix permissions (the ones we know from CHMOD) into a "-" delimited string of numbers. I also made it that it supports one more level (unix only has 3 different types of permissions, (r,w,x) while mine can handle a fourth one. Since I'm just a newbie to PHP, I was wondering whether there is a shorter way of achieving the same thing. Here is my code:

    // $num is the number (range: 1-15) $done = ""; $result = "";

    while ($done != 1) {

    if ($num > 8) { $num = $num - 8; $result = "8-"; } elseif ($num = 8) { $result = 8; $done = 1; } elseif ($num > 4) { $num = $num - 4; $result .= "4-"; } elseif ($num = 4) { $result .= 4; $done = 1; } elseif ($num > 2) { $result .= "2-1"; $done = 1; } elseif ($num = 2) { $result .= "2-"; $done = 1; } else { $result .= "1"; $done = 1; }

    }

    if ((strrpos($result, "-") = strlen($result)-1) && strlen($result) > 1) { $result = strrev($result); $result = substr($result, 1); $result = strrev($result); }

    echo $result;

    TIA,

    Raphael

    attached mail follows:


    please hack apart this solution and point out the error/insecure nature of the setup.

    goal, provide php access to name based virtual hosts on FreeBSD boxes

    problem, security of PHP access to base system and other user scripts

    solution,

    apache compiled with suexec # set user and group to unique chown USERID:USERID /path/to/user/html/directory

    # no public access to any files under here that # you don't want public reading, like scripts # with database login information in them chmod -R 0750 /path/to/user/html/directory

    # set group sticky execution... we will run # apache as this unique group so may not be needed chmod g+s /path/to/user/html/directory

    >in apache's httpd.conf # set each virtual host to run any accesses # as the group USERID giving them only access # to this directory... defeats PHP directory # and shell scripts as long as no public read bits # are set <virtual *> ServerName whatever.com Group USERID </virtual>

    Sufficient?

    you end up with http://test1.com and http://test2.com being unable to create PHP scripts or do listings of any other virtual user directory since they are not of the same group, but accesses to the site are made by invoking apache as that group for that session.

    directory tree drwxr-s--- 2 user1 user1 512 Aug 19 18:23 vtest1 drwxr-s--- 2 user2 user2 512 Aug 19 18:26 vtest2

    with directory groups set in the httpd.conf for user1 in vtest1 and user2 in vtest2, neither user should be able to use PHP filesystem functions to browse the other directories as long as no public bits are set, and apache server requests still server the documents from the directories since each users directory has an Group user1 (or user2) set for his directory in the directory or virtual container, thus executing the apache requsts as the appropriate user and not the generic www user.

    Please feel free to point out any errors in my logic... it appears pretty solid from here.

    Dave