Jump to content

Gorf

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Gorf's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am trying to build an algorithm that will essentially do this: $this_month = October $third_sunday = CalculateThirdSunday(October) if ( ( TodaysDate before $third_sunday ) | ( TodaysDate == $third_sunday ) do something else CalculateThirdSunday(November) do something else So the sorta pseudo-code above should reveal that I want a function that will always take the current month and calculate the third Sunday. Then if it's on or before that third sunday do something. However if it is after the the third Sunday, then we will calculate the third sunday of next month and then do something. I can calculate what the third sunday out from now() is quite trivially: <?PHP echo date('l jS F (Y-m-d)', strtotime('third Sunday')); ?> But anyone got any idea how to find the third sunday from the beginning of the month? I tried something like <?PHP echo date('l jS F (Y-m-d)', strtotime('2009-10-01 +third Sunday')); ?> but that appears to not work. It tells me the next sunday is in Feb. LOL
  2. Of course. However that doesn't really give me any real-world information that is useful. I have since noted that I am hitting MaxClients so I changed up my worker config to be: <IfModule worker.c> StartServers 2 ServerLimit 100 MaxClients 2500 MinSpareThreads 25 MaxSpareThreads 75 ThreadsPerChild 25 MaxRequestsPerChild 0 </IfModule> That seems to have helped with the MaxClients problem. But I'm still a little surprised that at 600 - 700 concurrent connections per server (and an average spit of about 250mb/s per server) that I am running the CPU up to 100%. So that's why I am here... looking for some real world suggestions from people.
  3. Sorry I should also comment that this is completely static content.
  4. Grettings. Our company runs a series of download servers for our content that are all Apache 2.0 on Dell servers (dual Xeon 3.06GHz with 2G memory). The content resides on a RAID 0 disk array to maximize data through put. We currently use the worker MPM configuration with the default install of Apache from Red Hat Enterprise Server 4. This is our configuration for the worker: ServerTokens Prod ServerRoot "/etc/httpd" PidFile run/httpd.pid Timeout 300 KeepAlive Off MaxKeepAliveRequests 100 KeepAliveTimeout 15 EnableSendfile On ServerLimit 60 <IfModule worker.c> StartServers 2 MaxClients 1500 MinSpareThreads 25 MaxSpareThreads 75 ThreadsPerChild 25 MaxRequestsPerChild 0 </IfModule> These servers move a lot of data. 6 servers saw 1400mb of traffic today. I really want to make sure I am maximizing these for performance. Recently I have been noticing that in ps there are as many as 50 or 60 httpd.worker processes and the memory is completely consumed. And to top it all off recently when I use scp to copy content to all the servers it seems to break Apache. It runs the CPU up to 100% (100% wa), and when I try to stop the service is hangs all the processes saying "httpd.worker <defunct>" in ps. Any thoughts or advice?
  5. It's in your own comments: [code]# Allow blank referrer RewriteCond %{HTTP_REFERER} !^$[/code] When you type a URL into your web browser directly, there is no referrer set.  Thus this Condition is caught if the referrer is NOT (!) blank.  Removing the ! should make this work properly. Your best bet though would just to be to create one rule, whereby anything without a referrer from your domain is blocked.  I do that for all sorts of stuff like CSS directories, image directories, javascript directories, etc.
  6. [quote author=google_man2000 link=topic=107820.msg433217#msg433217 date=1158118406] i dont tallk about  use  any tools "  i want write programme  like as ( internet explorer in windwos xp) when user write : www.phpfreaks.com/forum/ take this site name sed to ROOT DNS Server to get  it's ip address www.phpfreaks.com/forum ------->>DNS server ----->> ip address how i do it but  i haven't use  any tools  or soft  i want write programme thanks [/quote] google_man2000, what language are you interested in writing your program in?  Most languages have built in functions and operating system API's to resolve host -> IP information. DNS works like this: The client application requests to know what the IP address of www.google.com is.  The system that the client is on has DNS servers configured.  The system queries those DNS servers to tell it the IP of www.google.com.  The servers may or may not know what the anser is (either it hosts that zone or it has it cached and is less then the TTL of the zone).  If it doesn't know, it does a recursive query (normally) to the ROOT DNS servers on the internet.  There are currently 13 official ROOT servers, A - M.  The ROOT server that is queried, looks up who the authoritative DNS server is for google.com domain and responds with that, the hosts DNS servers then query those servers for the hostname www.google.com. That's it in a nutshell.  There are lots of good tutorials on how to do name resolution progromatically.  Since you are here... I'm assuming you are interested in doing it in PHP?
  7. Can someone comment on your experiences using the perchild MPM threading model as opposed to the prefork and how it affected PHP 4.x?  I'm interested in configuring it to create some filesystem/security isolation for virtual hosts that I have created.  A lot of documentation says that PHP is unstable in the perchild setup.  And that I should maintain the prefork configuration and use suexec, however suexec doesn't create the seperation I am looking for, especially when it comes to the execution of PHP scripts. Can someone comment on your experiences with this?  I'm looking for either Apache 2.0 or 2.2 and either PHP 4.x or 5.x. Thanks
  8. A couple websites that our group runs has some contact forms that users can fill out to request information or make contact with various agents in the group.  Where possible we force users to choose from options via radio buttons, drop down boxes, etc.  But in some instances it is a requirement that we allow user text input like setting thier name, or email address.  However in order to be RFC compliant we have to allow a large text input for email addresses.  That leads to some very unique opportunities to hack the page via some string injections.  Then when we compose the mail message on the back end things like malformed SMTP headers result and spam can be sent through the form.  We've taken some good steps to mitigate this with a two-step confirmation process before you can send email, and by using PHPMailer (http://phpmailer.sourceforge.net) on the backend.  However I am still looking for some suggestions and criticism on how I am sanitizing user input for these forms. Currently all the forms ONLY allow the user to input thier name and email address and a body created from either a textarea or by various other inputs that get formatted on the backend into the body.  Once of the most common string injections is simply to do something like this for the email input: "to:bob@nowhere.com\nSubject:BUYVIAGRA!..." etc. Ok so anyways I use two functions: [code]     //Adds slashes and removes HTML tags from text that we accept from the end user.     function clean_data( $str )     {     $str = strip_tags( $str );     $str = addslashes( $str );     return str ;     }         //defang_userinput stops people from doing things like injecting URL encoded line breaks     //into a variable that normally would get set in the SMTP header.  It also removes line     //breaks.  Line breaks should never be allowed in the SMTP header.     function defang_userinput( $str )     {         $remove = array( "\r", "\n" );         $str = str_replace( $remove, "", urldecode( $str ) );                 //With the string URL decoded, and the new lines removed, we now hand it off to the         //clean_data function.         return clean_data( $str );     } [/code] The only other thing that I do is I chop strings down to reasonable size.  While the RFC allows 64 characters for the local-address part of an email address and 255 characters for the domain, I don't actually allow that in the form.  The text input has a maxlength set and I double check that by chopping the input down to the same size just in case.  This seems to work ok.  Can anyone offer any additional suggestions or critisisms for how I go about sanitizing user input for these email forms? Thanks
  9. Well if anyone is curious, I solved the problem. It appears to have something funny to do with leaving the page via a header( "location: xxx" ). So I wrapped the whole page into a if statement. [code] if ( isset( $_POST['something'] ) ) {   Do the code for the POST;   Set the SESSION variable;   Use the header function to redirect to the page; } else {   Show the normal page HTML; } [/code] That seems to fix it right up. Nor sure why, but there it is.
  10. Well it appears to be a phenomenon unique to when I redirect the page back to itself. I'm not sure I understand why, but if I change my header( "location: xxx" ); line to be a different page, the code works perfectly. Now I am really stumped, but that works for me for now I guess.
  11. [!--quoteo(post=358034:date=Mar 24 2006, 03:09 PM:name=lead2gold)--][div class=\'quotetop\']QUOTE(lead2gold @ Mar 24 2006, 03:09 PM) [snapback]358034[/snapback][/div][div class=\'quotemain\'][!--quotec--] [code]     if ( isset($_SESSION['ERROR']))     {         echo "<p>";         echo "- ->".$_SESSION['ERROR']."<-<br />\n";         echo "</p>";                  //clear session variable for next use             unset($_SESSION['ERROR']);          } ... [/code] [/quote] Using that exact piece of code, the html that is produced is this: [code]     <span class="announce">     </span> [/code] As you can see, the SESSION variable is being unset before the if statement is being evaluated. Otherwise I should be getting something like this at least: [code]     <span class="announce">           <p>         - -><-<br />         </p>     </span> [/code]
  12. I have a site with a form. When the form submits, the page is processed, and then depending on the outcome of the code, sets a session variable and then redirects back to the page. That way the user never has a refresh situation where the browser alerts them about it needing to resubmit POST data and ends up submitting the data twice, or three times, or etc. So first here is the code, for now it's an emailer basically: [code] **this is contact.php** <?PHP require( "includes/include.general.php" ); require( "class.phpmailer.php" ); //The user has posted to the page to submit an email request if ( isset( $_POST['sendmail'] ) ) {     $from_name  = defang_urlencoding( chop_string( 30, $_POST['name'] ) );     $from_email = defang_urlencoding( chop_string( 30, $_POST['email'] ) );     $message    = clean_data( $_POST['message'] );          $mail = new PHPMailer();          // set mailer to use SMTP     $mail->IsSMTP();          // specify main and backup server, and the envelope information                           $mail->Host         = "localhost";           $mail->From         = $from_email;     $mail->FromName     = $from_name;     $mail->AddAddress(                         $CONTACT['Email'],                         $CONTACT['Name']                      );                          // set word wrap to 50 characters     $mail->WordWrap     = 80;            // set email format to plain text                 $mail->IsHTML( false );                       $mail->Subject      = "[SbS] Web contact";     $mail->Body         = "This email was sent from the IP: ".get_ip( )."\n".                           "on ".date( "M j" )." at ".date( "H:i:s" )."\n\n\n".$message;          if ( $mail->Send( ) )     {         $_SESSION['ERROR'] = "Your email was sent successfully.";         header( "location: contact.php" );     }     else     {         $_SESSION['ERROR'] = "An error has occurred sending your email.  Please try again later.";         header( "location: contact.php" );     } } require( "includes/overall.header.php" ); ?> <div class="content">     <script language="JavaScript">     function valid(form) {         if ((form.name.value==null)||(form.name.value=="")){             alert("Please enter your name.")             form.name.focus()             return false         }         if ((form.email.value==null)||(form.email.value=="")){             alert("Please enter your email address.")             form.email.focus()             return false         }                  alert("Just to be sure, is your email address:\n"+form.email.value+"\n\n Is this correct?")     }     </script>     <span class="announce">     <?PHP          //This is for any errors that occur, they can be announced here     if ( $_SESSION['ERROR'] != "" )     {         echo "<p>";         echo "- ->".$_SESSION['ERROR']."<-<br />\n";         echo "</p>";                  //clear session variable for next use             $_SESSION['ERROR'] = "";          }          ?>     </span>     <p>     Please use this form to contact us about any of the animals you see on this site, or to inquire about     the possibility of other animals.     </p>     <form action="contact.php" method="POST" enctype="multipart/form-data" onSubmit="return valid(this)">             <p>         Please feel free to contact us by email.  This email system requires that you have a         legitimate email address.  This email system does log your IP address, however privacy         is important to us, so your contact information is not stored anywhere in our system.         </p>                      Your Name:<br />         <input type="text" name="name" size="40" maxlength="30"><br />         <br />         Your Email Address:<br />         <input type="text" name="email" size="40" maxlength="30"><br />         <br />         Text message:<br />         <textarea name="message" rows="8" cols="50"></textarea><br />         <br />         <input name="sendmail" value="submit" type="submit">     </form>     <p />     This email system is for contacting representatives of Snakes by Sasquatch only.  Any other     use is stricly prohibited. </div> <?PHP require( "includes/overall.footer.php" ); ?> [/code] The include.general.php at the beginning of the code contains the session start information as well as a bunch of all purpose functions only a couple of which are used in the contact.php file: [code] <?PHP     //Start the session     session_start( );     //This is a fix for Internet Exploder for SessionID's     header("Cache-Control: private");       //Include the config for the site     include_once("includes/config.php");     //Include the class for the site database connectivity     include_once( "includes/class.database.php" );      *snip* [/code] If you look in contact.php file you will see where I clear the session variable ERROR for next use. The problem I am running into is that no matter what I do to clear that session variable, it clears it globally for the whole page. I could clear it at the bottom of my code, and it still will only echo out "" back at the top. I have tried assigning the session variable to a different variable, and again I still get the exact same scenario. However if I take the statement out all together, the SESSION variable stays around, and it gets printed as expected. The downside of course is that it stays that way until it gets set to something else. It's like the processor sets the SESSION variable to "" before it does the HTML and the echo statement. I am very confused here. Can anyone offer some insight?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.