Auto down counter

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by bigjoe4, Apr 26, 2008.

  1. bigjoe4

    bigjoe4 New Member

    Messages:
    907
    Likes Received:
    0
    Trophy Points:
    0
    I sell products on my site, and on this page: http://www.lights4yourpc.com/buy.html I want to make it count down how many are left in stock automatically, and display a different page when there are none left in stock.

    Once the contact form is sent, the visitor is redirected to another page, so I need it so that it counts down each time someone visits that page.

    I also need to be able to manually update the number left in stock when new stock arrives.

    I have absolutely no idea of how to do this, but I assume I will need databases and PHP and stuff. You will have to explain in detail exactly what I need to do as I know nothing about PHP and databases.

    I will pay generous credits to whoever gets this working for me.
     
  2. lszanto

    lszanto New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    You said once the contact has been sent they are redirected to another page, what is this page?
     
  3. bigjoe4

    bigjoe4 New Member

    Messages:
    907
    Likes Received:
    0
    Trophy Points:
    0
    well the page is imbeded in the contact form code file which is called "FormToEmail.php", the code for the page that they are redirected to is at the bottom :
    Code:
    <?php
    
    /*
    
    Thank you for choosing FormToEmail by FormToEmail.com
    
    COPYRIGHT FormToEmail.com 2003 - 2007
    
    For support, please visit: http://formtoemail.com/support/
    
    ---------------------------------------------------------------------------------------------------
    
    
    ---------------------------------------------------------------------------------------------------
    
    FormToEmail DESCRIPTION
    
    FormToEmail is a contact-form processing script written in PHP. It allows you to place a form on your website which your visitors can fill out and send to you.  The contents of the form are sent to the email address (or addresses) which you specify below.  The form allows your visitors to enter their name, email address and comments.  The script will not allow a blank form to be sent.
    
    Your visitors (and nasty spambots!) cannot see your email address.  The script cannot be hijacked by spammers.
    
    When the form is sent, your visitor will get a confirmation of this on the screen, and will be given a link to continue to your homepage, or other page if you specify it.
    
    Should you need the facility, you can add additional fields to your form, which this script will also process without making any additional changes to the script.  You can also use it to process other forms.  The script will handle the "POST" or "GET" methods.  It will also handle multiple select inputs and multiple check box inputs.  If using these, you must name the field as an array using square brackets, like so: <select name="fruit[]" multiple>.  The same goes for check boxes if you are using more than one with the same name, like so: <input type="checkbox" name="fruit[]" value="apple">Apple<input type="checkbox" name="fruit[]" value="orange">Orange<input type="checkbox" name="fruit[]" value="banana">Banana
    
    ** PLEASE NOTE **  If you are using the script to process your own forms (or older FormToEmail forms) you must ensure that the email field is named correctly in your form, thus: <input type="text" name="email" etc>.  Note the lower case "email".  If you don't do this, you won't be able to see who the email is from and the script won't be able to check the validity of the email.  If you are using the form code below, you don't need to check for this.
    
    This is a PHP script.  In order for it to run, you must have PHP (version 4.1.0 or later) on your webhosting account, and have the PHP mail() function enabled and working.  If you are not sure about this, please ask your webhost about it.
    
    SETUP INSTRUCTIONS
    
    Step 1: Put the form on your webpage
    Step 2: Enter your email address and (optional) continue link below
    Step 3: Upload the files to your webspace
    
    Step 1:
    
    To put the form on your webpage, copy the code below as it is, and paste it into your webpage:
    
    <form action="FormToEmail.php" method="post">
    <table border="0" bgcolor="#ececec" cellspacing="5">
    <tr><td>Name</td><td><input type="text" size="30" name="name"></td></tr>
    <tr><td>Email address</td><td><input type="text" size="30" name="email"></td></tr>
    <tr><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr>
    <tr><td>&nbsp;</td><td><input type="submit" value="Send"><font face="arial" size="1">&nbsp;&nbsp;<a href="http://FormToEmail.com">Form Mail</a> by FormToEmail.com</font></td></tr>
    </table>
    </form>
    
    Step 2:
    
    Enter your email address.
    
    Enter the email address below to send the contents of the form to.  You can enter more than one email address separated by commas, like so: $my_email = "bob@example.com,sales@example.co.uk,jane@example.com";
    
    */
    
    $my_email = "joe@lights4yourpc.com";
    
    /*
    
    Enter the continue link to offer the user after the form is sent.  If you do not change this, your visitor will be given a continue link to your homepage.
    
    If you do change it, remove the "/" symbol below and replace with the name of the page to link to, eg: "mypage.htm" or "http://www.elsewhere.com/page.htm"
    
    */
    
    $continue = "continue.html";
    
    /*
    
    Step 3:
    
    Save this file (FormToEmail.php) and upload it together with your webpage containing the form to your webspace.  IMPORTANT - The file name is case sensitive!  You must save it exactly as it is named above!  Do not put this script in your cgi-bin directory (folder) it may not work from there.
    
    THAT'S IT, FINISHED!
    
    You do not need to make any changes below this line.
    
    */
    
    $errors = array();
    
    // Remove $_COOKIE elements from $_REQUEST.
    
    if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
    
    // Check all fields for an email header.
    
    function recursive_array_check_header($element_value)
    {
    
    global $set;
    
    if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}}
    else
    {
    
    foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);}
    
    }
    
    }
    
    recursive_array_check_header($_REQUEST);
    
    if($set){$errors[] = "You cannot send an email header";}
    
    unset($set);
    
    // Validate email field.
    
    if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
    {
    
    if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";}
    
    $_REQUEST['email'] = trim($_REQUEST['email']);
    
    if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}
    
    }
    
    // Check referrer is from same site.
    
    if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}
    
    // Check for a blank form.
    
    function recursive_array_check_blank($element_value)
    {
    
    global $set;
    
    if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
    else
    {
    
    foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}
    
    }
    
    }
    
    recursive_array_check_blank($_REQUEST);
    
    if(!$set){$errors[] = "You cannot send a blank form";}
    
    unset($set);
    
    // Display any errors and exit if errors exist.
    
    if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}
    
    if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}
    
    // Build message.
    
    function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
    
    $message = build_message($_REQUEST);
    
    $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you for using FormToEmail from http://FormToEmail.com";
    
    $message = stripslashes($message);
    
    $subject = "FormToEmail Comments";
    
    $headers = "From: " . $_REQUEST['email'];
    
    mail($my_email,$subject,$message,$headers);
    
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>High power lights for your computer</title>
    <link href="Favicon.ico" rel="SHORTCUT ICON">
    <META NAME="description" CONTENT="Flashing Lights for your PC."><META NAME="keywords" CONTENT=
    "Computer lights, PC lights, laser leds, flashing computer lights, computer leds, computer leds kit, multicolor computer LEDs, PC LEDs kit, Case LEDs, Case lights, Flashing 12 LEDs, 12V LEDs, Flashing 12V lights">
    </head>
    <body background="purple-tile.gif" bgcolor="#330066" text="#FFFFFF" alink="#0000FF">
    <img src="Lights4yourPC.gif" id="Image1" alt="" align="top" border="0" width="704" height="150" style="position:absolute;left:0px;top:0px;width:704px;height:150px;z-index:0">
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <div>
    <center><font style="font-size:16px" color="#FFFFFF" face="Verdana">
    <b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b><br>
    <br>Your message has been recieved.<br><br>
    Click the button below to continue to paypal:<br><br>
    <form name="_xclick" action="https://www.paypal.com/us/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="bigjoe4@gmail.com">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="item_name" value="Computer Lights">
    <input type="hidden" name="amount" value="30.00">
    <input type="image" src="http://www.paypal.com/en_US/i/btn/btn_paynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
    </form>
    <p><b>FormToEmail</b> by <a href="http://FormToEmail.com">FormToEmail.com</a></p>
    </font>
    </center>
    </div>
    </body>
    </html>
     
    Last edited: Apr 26, 2008
  4. lszanto

    lszanto New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Okie, thanks for that i'll see what I can do.
     
  5. bigjoe4

    bigjoe4 New Member

    Messages:
    907
    Likes Received:
    0
    Trophy Points:
    0
    OK, thanks.

    Now I know where you live lol: "rgwgg"
     
    Last edited: Apr 26, 2008
  6. marshian

    marshian New Member

    Messages:
    526
    Likes Received:
    9
    Trophy Points:
    0
    1: make a text file, open it and type how many there is in stock.
    2: add this to your page that has to change the number in stock
    PHP:
    <?php
    //Relative path to your chosen file here
    $filename "stock.txt";
    //Url to redirect to when there is no stock left. (full url!)
    $redirurl "http://yoursite.com/invalid.php";

    $file fopen($filename"r");
    $stock fgets($file);
    fclose($file);
    if(
    $stock 0) {
    $stock--;
    $file fopen($filename"w");
    fwrite($file$stock);
    fclose($file);
    ?>
    HTML FOR THE SUCCESSFULL PAGE GOES HERE.
    Alternative:
    $succesurl = "http://www.yoursite.com/itworked.php";
    header("Redirect: ".$succesurl, true, 307);
    exit;
    <?php
    }
    else {
    header("Redirect: ".$redirurltrue307);
    exit;
    }
    ?>
    I think this should do it,
    Marshian
     
    Last edited: Apr 26, 2008
  7. lszanto

    lszanto New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Ah, beat me to it, I don't think this will quite work I may be wrong though, becauseyou open $stock with fgets() but you never turn it into an integer so you can't run $stock--; first you would need a line like:
    PHP:
    $stock = (int) $stock;
    That would make the $stock into an integer and it can be added, subtracted or whatever.
     
  8. woiwky

    woiwky New Member

    Messages:
    390
    Likes Received:
    0
    Trophy Points:
    0
    I think php would take the decrement operator as an implicit cast, but it's probably a good idea and good practice to explicitly cast it anyway. Also, I would modify the code a little bit further to flock() the file.

    PHP:
    <?php
    //Relative path to your chosen file here
    $filename "stock.txt";
    //Url to redirect to when there is no stock left. (full url!)
    $redirurl "http://yoursite.com/invalid.php";

    $file fopen($filename"r");
    flock($fileLOCK_SH);
    $stock = (int) fgets($file);
    flock($fileLOCK_UN);
    fclose($file);
    if(
    $stock 0) {
    $stock--;
    $file fopen($filename"w");
    flock($fileLOCK_EX);
    fwrite($file$stock);
    flock($fileLOCK_UN);
    fclose($file);
    ?>
    HTML FOR THE SUCCESSFULL PAGE GOES HERE.
    Alternative:
    $succesurl = "http://www.yoursite.com/itworked.php";
    header("Redirect: ".$succesurl, true, 307);
    exit;
    <?php
    }
    else {
    header("Redirect: ".$redirurltrue307);
    exit;
    }
    ?> 
     
  9. bigjoe4

    bigjoe4 New Member

    Messages:
    907
    Likes Received:
    0
    Trophy Points:
    0
    Sorry, I did not explain well enough: on this page: http://www.lights4yourpc.com/buy.html where it sais: "ORDER NOW! ONLY 4 LEFT IN STOCK!" I want that to display how many are left in stock. Also, when there are none left in stock, I want the page to redirect to a different page (or display a different page)

    Also can you add the new code to the source code of my site so I can just copy and paste the new code, as I don't know where to put the code.
     
    Last edited: Apr 26, 2008
  10. lszanto

    lszanto New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    To do that you'll have to make the page a .php page or use ajax to make the request to get the value, are you willing to change the file from buy.html to buy.php or would you prefer that it stays .html.
     
  11. bigjoe4

    bigjoe4 New Member

    Messages:
    907
    Likes Received:
    0
    Trophy Points:
    0
    I would prefer it stays .html
    Edit:
    although I wouldn't mind changing it to .php if there is no other way.
     
    Last edited: Apr 26, 2008
  12. lszanto

    lszanto New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Ok I think I finally got this worked out, please tell me if anything goes wrong so I can fix it, your files are below and you will have to create a file called 'num.inc' with the number of stock you have in the file and upload it.

    The file 'num.inc' will also have to be chmodded to 755 so that it can be written to.

    As you can see in buy.html if there is no products left it redirects you to a page called nostock.html, you will have to create this file and may put in it whatever you like :p.

    buy.html -
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>High power lights for your computer</title>
    <link href="Favicon.ico" rel="SHORTCUT ICON">
    <META NAME="description" CONTENT="Flashing Lights for your PC."><META NAME="keywords" CONTENT=
    "Computer lights, PC lights, laser leds, flashing computer lights, computer leds, computer leds kit, multicolor computer LEDs, PC LEDs kit, Case LEDs, Case lights, Flashing 12 LEDs, 12V LEDs, Flashing 12V lights">
    <script type="text/javascript">
    <!--
    function SwapImage()
    {
       var doc=document, args=arguments;
       doc.$imgSwaps = new Array();
       for(var i=2; i<args.length; i+=2)
       {
          var elem=FindObject(args[i]);
          if(elem)
          {
             doc.$imgSwaps[doc.$imgSwaps.length]=elem;
             elem.$src=elem.src;
             elem.src=args[i+1];
          }
       }
    }
    
    function ajaxRequest() { 
        //Make var. 
        var ajaxRequest; 
     
        //Try Firefox, Opera or Safari style. 
        try { 
            //Set ajaxRequest. 
            ajaxRequest = new XMLHttpRequest(); 
        } catch(e) { 
            //Try new IE. 
            try {  
                //Set ajaxRequest. 
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
            } catch(e) { 
                //Try Old IE. 
                try { 
                    //Set ajaxRequest. 
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
                } catch(e) { 
                    //Not supported. 
                    return false; 
                } 
            } 
        } 
         
        //Assume works. 
        return ajaxRequest; 
    }
    
    function getNumber() {
        //Prepare data. 
        var xmlHttp = ajaxRequest(); 
        var url = "getnumber.php"; 
        var data = ""; 
     
        //Check if ajax connection is valid. 
        if(!xmlHttp) { 
            //No ajax. 
            alert("I'm sorry your browser does not support ajax, please upgrade your browser."); 
        } 
     
        //Set up readystatechange. 
        xmlHttp.onreadystatechange = function() { 
            if(xmlHttp.readyState == 4) { 
                //Show new value.
                if(xmlHttp.responseText > 0) { 
                    document.getElementById('stock').innerHTML = xmlHttp.responseText; 
                } else {
                    window.location = "nostock.html";
                }
            } 
        } 
     
        //Send data. 
        xmlHttp.open("POST", url, true); 
        xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
        xmlHttp.send(data); 
    }
    
    // -->
    </script>
    <script type="text/javascript">
    <!--
    function FindObject(id, doc)
    {
       var child, elem;
       if(!doc)
          doc=document;
       if(doc.getElementById)
          elem=doc.getElementById(id);
       else
       if(doc.layers)
          child=doc.layers;
       else
       if(doc.all)
          elem=doc.all[id];
       if(elem)
          return elem;
       if(doc.id==id || doc.name==id)
          return doc;
       if(doc.childNodes)
          child=doc.childNodes;
       if(child)
       {
          for(var i=0; i<child.length; i++)
          {
             elem=FindObject(id,child[i]);
             if(elem)
                return elem;
          }
       }
       var frm=doc.forms;
       if(frm)
       {
          for(var i=0; i<frm.length; i++)
          {
             var elems=frm[i].elements;
             for(var j=0; j<elems.length; j++)
             {
                elem=FindObject(id,elems[i]);
                if(elem) return elem;
             }
          }
       }
       return null;
    }
    // -->
    </script>
    </head>
    <body background="purple-tile.gif" bgcolor="#330066" text="#000000" alink="#0000FF" onload="getNumber();">
    <img src="Lights4yourPC.gif" id="Image1" alt="" align="top" border="0" width="704" height="150" style="position:absolute;left:0px;top:0px;width:704px;height:150px;z-index:0">
    <div id="bv_" style="position:absolute;left:0px;top:150px;width:118px;height:124px;z-index:1" align="center">
    <table border="0" cellpadding="0" cellspacing="0" id="NavigationBar1">
    
    <tr>
    <td align="left" valign="top" width="118" height="31"><a href="/"><img id="home" src="home.gif" alt="home" align="top" border="0" width="118" height="31" onmouseover="SwapImage(1,0,'home','home-over.gif')" onmouseout="SwapImage(0,0,'home','home.gif')"></a></td>
    </tr>
    <tr>
    <td align="left" valign="top" width="118" height="31"><a href="pictures.html"><img id="pictures" src="pictures.gif" alt="pictures" align="top" border="0" width="118" height="31" onmouseover="SwapImage(1,0,'pictures','pictures-over.gif')" onmouseout="SwapImage(0,0,'pictures','pictures.gif')"></a></td>
    </tr>
    <tr>
    <td align="left" valign="top" width="118" height="31"><a href="buy.html"><img id="buy" src="buy-over.gif" alt="buy" align="top" border="0" width="118" height="31" onmouseover="SwapImage(1,0,'buy','buy-over.gif')" onmouseout="SwapImage(0,0,'buy','buy-over.gif')"></a></td>
    </tr>
    <tr>
    <td align="left" valign="top" width="118" height="31"><a href="links.html"><img id="links" src="links.gif" alt="links" align="top" border="0" width="118" height="31" onmouseover="SwapImage(1,0,'links','links-over.gif')" onmouseout="SwapImage(0,0,'links','links.gif')"></a></td>
    </tr>
    </table>
    </div>
    <img src="line.gif" id="Image2" alt="" align="top" border="0" width="1" height="536" style="position:absolute;left:118px;top:150px;width:1px;height:889px;z-index:2">
    <img src="fade.gif" id="Image3" alt="" align="top" border="0" width="118" height="348" style="position:absolute;left:0px;top:274px;width:118px;height:765px;z-index:3">
    <div id="b_" style="position:absolute;left:124px;top:152px;width:574px;height:32px;z-index:4" align="left">
    
    <font style="font-size:27px" color="#FFFF99" face="Verdana"><b><u>BUY!</u></b></font></div>
    <div id="v_" style="position:absolute;left:124px;top:202px;width:560px;height:559px;z-index:5" align="left">
    
    <!-- PayPal Logo -->
    <a href="#" onclick="javascript:window.open('https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/popup/OLCWhatIsPayPal-outside','olcwhatispaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=350');"><img  src="https://www.paypal.com/en_US/i/logo/PayPal_mark_180x113.gif" border="0" alt="Acceptance Mark" style="position:absolute;left:600px;top:0px"></a><!-- PayPal Logo -->
    
    <font style="font-size:16px" color="#FFFFFF" face="Verdana">These amazing LEDs cost only $30USD each! (including delivery to USA or Europe)<br><br>
    To request your LEDs, simply fill out the form below and send it. You will be redirected to a page so you can pay me by paypal.<br>
    <br>
    Make sure you fill out all the fields correctly.<br>
    <br>
    I will send you your LEDs as soon as I recieve your payment.<br><br>
    
    ORDER NOW! ONLY <font style="font-size:24px" color="#FFFF99" face="Arial"><span id="stock" >4</span></font> LEFT IN STOCK!
    </font>
    </div>
    <form action="FormToEmail.php" method="post" style="position:absolute;left:124px;top:430px;z-index:6">
    <table border="0" bgcolor="#ececec" cellspacing="5">
    <tr><td>Name</td><td><input type="text" size="30" name="Name"></td></tr>
    <tr><td>Email address</td><td><input type="text" size="30" name="Email address"></td></tr>
    <tr><td valign="top">Your Full Address and postcode.</td><td><textarea name="Your Full Address" rows="6" cols="30"></textarea></td></tr>
    <tr><td>&nbsp;</td><td><input type="submit" value="Send"><font face="arial" size="1">&nbsp;&nbsp;<a href="http://FormToEmail.com">Form Mail</a> by FormToEmail.com</font></td></tr>
    
    </table>
    <div id="bv2" style="position:absolute;left:0px;top:224px;width:574px;height:32px;z-index:4" align="left">
    <font style="font-size:16px" color="#FFFFFF" face="Verdana">If you want to know the price of delivery to places outside of USA or Europe, or would like to ask me any questions you can email me <script language="JavaScript">
    document.write('<a hre'+'f="m'+'ai'+'lto:'+'%6a%6f%65%40%6c%69%67%68%74%73%34%79%6f%75%72%70%63%2e%63%6f%6d">here<\/a>');
    </script>
    <p><font style="font-size:16px" color="#FFFF99" face="Verdana"><b><u>Disclaimer</u></b></font></p>
    By buying these LEDs you are accepting this disclaimer. Although I believe these LEDs are perfectly safe if used with care and in accordance with the instructions, I accept no liability WHATSOEVER for these LEDs, including but not limited to: if they cause you or anyone else, directly or indirectly: personal injury, mental injury, loss of life, or damage to equipment. Once you buy them, it is your responsibility to use them safely.<br>
    <br><br><br><br>
    <!-- x10 Exchange code begin -->
    <!-- DO NOT ALTER THIS CODE! -->
    <script language="JavaScript"> 
    document.write('<s'+'cript language="JavaScript" src="http://www.x10exchange.com/work.php?n=118&size=1&j=1&c=&code='+new Date().getTime()+'"></s'+'cript>'); 
    </script> 
    <NOSCRIPT>
    <IFRAME SRC="http://www.x10exchange.com/work.php?n=118&size=1&c=" width=468 height=60 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling="no"></IFRAME>
    </NOSCRIPT>
    <!-- x10 Exchange code end -->
    
    </font>
    </div>
    </form>
    </body>
    </html>
    
     
  13. lszanto

    lszanto New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    FormToEmail.php -
    PHP:
    <?php

    //One less stock function.
    function onelessstock() {
        
    //Set file.
        
    $file "num.inc";
        
        
    //Make file handle, read.
        
    $fh fopen($file"r");
        
        
    //Read file.
        
    $num fread($fhfilesize($file));
        
        
    //Close file.
        
    fclose($fh);
        
        
    //Make an int.
        
    $num = (int) $num;
        
        
    //Take one off stock.
        
    $num--;
        
        
    //Make file handle, write.
        
    $fh fopen($file"w");
        
        
    //Write to file.
        
    fwrite($num);
        
        
    //Close file.
        
    fclose($fh);
    }

    /*

    ** PLEASE NOTE **  If you are using the script to process your own forms (or older FormToEmail forms) you must ensure that the email field is named correctly in your form, thus: <input type="text" name="email" etc>.  Note the lower case "email".  If you don't do this, you won't be able to see who the email is from and the script won't be able to check the validity of the email.  If you are using the form code below, you don't need to check for this.

    This is a PHP script.  In order for it to run, you must have PHP (version 4.1.0 or later) on your webhosting account, and have the PHP mail() function enabled and working.  If you are not sure about this, please ask your webhost about it.

    SETUP INSTRUCTIONS

    Step 1: Put the form on your webpage
    Step 2: Enter your email address and (optional) continue link below
    Step 3: Upload the files to your webspace

    Step 1:

    To put the form on your webpage, copy the code below as it is, and paste it into your webpage:

    <form action="FormToEmail.php" method="post">
    <table border="0" bgcolor="#ececec" cellspacing="5">
    <tr><td>Name</td><td><input type="text" size="30" name="name"></td></tr>
    <tr><td>Email address</td><td><input type="text" size="30" name="email"></td></tr>
    <tr><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr>
    <tr><td>&nbsp;</td><td><input type="submit" value="Send"><font face="arial" size="1">&nbsp;&nbsp;<a href="http://FormToEmail.com">Form Mail</a> by FormToEmail.com</font></td></tr>
    </table>
    </form>

    Step 2:

    Enter your email address.

    Enter the email address below to send the contents of the form to.  You can enter more than one email address separated by commas, like so: $my_email = "bob@example.com,sales@example.co.uk,jane@example.com";

    */

    $my_email "joe@lights4yourpc.com";

    /*

    Enter the continue link to offer the user after the form is sent.  If you do not change this, your visitor will be given a continue link to your homepage.

    If you do change it, remove the "/" symbol below and replace with the name of the page to link to, eg: "mypage.htm" or "http://www.elsewhere.com/page.htm"

    */

    $continue "continue.html";

    /*

    Step 3:

    Save this file (FormToEmail.php) and upload it together with your webpage containing the form to your webspace.  IMPORTANT - The file name is case sensitive!  You must save it exactly as it is named above!  Do not put this script in your cgi-bin directory (folder) it may not work from there.

    THAT'S IT, FINISHED!

    You do not need to make any changes below this line.

    */

    $errors = array();

    // Remove $_COOKIE elements from $_REQUEST.

    if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

    // Check all fields for an email header.

    function recursive_array_check_header($element_value)
    {

    global 
    $set;

    if(!
    is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set 1;}}
    else
    {

    foreach(
    $element_value as $value){if($set){break;} recursive_array_check_header($value);}

    }

    }

    recursive_array_check_header($_REQUEST);

    if(
    $set){$errors[] = "You cannot send an email header";}

    unset(
    $set);

    // Validate email field.

    if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
    {

    if(
    preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";}

    $_REQUEST['email'] = trim($_REQUEST['email']);

    if(
    substr_count($_REQUEST['email'],"@") != || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

    }

    // Check referrer is from same site.

    if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}

    // Check for a blank form.

    function recursive_array_check_blank($element_value)
    {

    global 
    $set;

    if(!
    is_array($element_value)){if(!empty($element_value)){$set 1;}}
    else
    {

    foreach(
    $element_value as $value){if($set){break;} recursive_array_check_blank($value);}

    }

    }

    recursive_array_check_blank($_REQUEST);

    if(!
    $set){$errors[] = "You cannot send a blank form";}

    unset(
    $set);

    // Display any errors and exit if errors exist.

    if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

    if(!
    defined("PHP_EOL")){define("PHP_EOL"strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" "\n");}

    // Build message.

    function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

    $message build_message($_REQUEST);

    $message $message PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you for using FormToEmail from http://FormToEmail.com";

    $message stripslashes($message);

    $subject "FormToEmail Comments";

    $headers "From: " $_REQUEST['email'];

    mail($my_email,$subject,$message,$headers);

    onelessstock();

    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>High power lights for your computer</title>
    <link href="Favicon.ico" rel="SHORTCUT ICON">
    <META NAME="description" CONTENT="Flashing Lights for your PC."><META NAME="keywords" CONTENT=
    "Computer lights, PC lights, laser leds, flashing computer lights, computer leds, computer leds kit, multicolor computer LEDs, PC LEDs kit, Case LEDs, Case lights, Flashing 12 LEDs, 12V LEDs, Flashing 12V lights">
    </head>
    <body background="purple-tile.gif" bgcolor="#330066" text="#FFFFFF" alink="#0000FF">
    <img src="Lights4yourPC.gif" id="Image1" alt="" align="top" border="0" width="704" height="150" style="position:absolute;left:0px;top:0px;width:704px;height:150px;z-index:0">
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <div>
    <center><font style="font-size:16px" color="#FFFFFF" face="Verdana">
    <b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b><br>
    <br>Your message has been recieved.<br><br>
    Click the button below to continue to paypal:<br><br>
    <form name="_xclick" action="https://www.paypal.com/us/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="bigjoe4@gmail.com">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="item_name" value="Computer Lights">
    <input type="hidden" name="amount" value="30.00">
    <input type="image" src="http://www.paypal.com/en_US/i/btn/btn_paynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
    </form>
    <p><b>FormToEmail</b> by <a href="http://FormToEmail.com">FormToEmail.com</a></p>
    </font>
    </center>
    </div>
    </body>
    </html>
    getnumber.php -
    PHP:
    <?php

    //File.
    $file "num.inc";

    //Set filehandle.
    $fh fopen($file"r");

    //Read file.
    $number fread($fhfilesize($file));

    //Make an int.
    $number = (int) $number;

    //Return the number.
    echo $number;

    ?>
    Edit:
    This hasn't been tested so please do not hesitate to ask any questions, if something does not work, please tell us what you did and what error occured.
     
    Last edited: Apr 26, 2008
  14. bigjoe4

    bigjoe4 New Member

    Messages:
    907
    Likes Received:
    0
    Trophy Points:
    0
    I get this message in the page which is embeded in FormToEmail.php:
    Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bigjoe4/public_html/lights4yourpc.com/FormToEmail.php on line 12

    Warning: Wrong parameter count for fwrite() in /home/bigjoe4/public_html/lights4yourpc.com/FormToEmail.php on line 27
    Edit:
    also sometimes it redirects to the nostock.html for no reason
     
    Last edited: Apr 26, 2008
  15. marshian

    marshian New Member

    Messages:
    526
    Likes Received:
    9
    Trophy Points:
    0
    If you're using his code, it's because your file is empty

    @lszanto: thanks, i didn't realise you could cast stuff in php, i was just hoping the server would understand xD

    @wiowky: i didn't even know flock() existed o_O thanks

    For the .html problem, add
    Code:
    AddType application/x-httpd-php .php .htm .html
    to your .htaccess file (if it is possible on x10, which i'm not sure of)
     
    Last edited: Apr 26, 2008
  16. bigjoe4

    bigjoe4 New Member

    Messages:
    907
    Likes Received:
    0
    Trophy Points:
    0

    The num.inc file is not empty; it has the number '4' in it. I just typed '4' in notepad and saved it as num.inc. Is that right?
    I can't find a way to add code the the htaccess file.

    If you can help me fix this I will pay 2000 credits
     
    Last edited: Apr 26, 2008
  17. marshian

    marshian New Member

    Messages:
    526
    Likes Received:
    9
    Trophy Points:
    0
    Strange, when the contents of that file are equal to "4", filesize() should return 1...
    try to use
    PHP:
    $number fread($fh1024);
    instead of
    PHP:
    $number fread($fhfilesize($file));
    (in both files)

    EDIT: I can add loads of code to the .htaccess to be honest, but it doesn't seem to work xD
     
    Last edited: Apr 26, 2008
  18. bigjoe4

    bigjoe4 New Member

    Messages:
    907
    Likes Received:
    0
    Trophy Points:
    0
    nope:

    Warning: Wrong parameter count for fwrite() in /home/bigjoe4/public_html/lights4yourpc.com/FormToEmail.php on line 27

    you can see for yourself if you want: just fill out the form and send it but then don't pay: http://www.lights4yourpc.com/buy.html
     
    Last edited: Apr 26, 2008
  19. marshian

    marshian New Member

    Messages:
    526
    Likes Received:
    9
    Trophy Points:
    0
    that's an easy one!
    it's all wrong :p
    change
    PHP:
    fwrite($num);
    to
    PHP:
    fwrite($fh$num);
     
  20. bigjoe4

    bigjoe4 New Member

    Messages:
    907
    Likes Received:
    0
    Trophy Points:
    0

Share This Page