Jump to content
Larry Ullman's Book Forums

rob

Members
  • Posts

    143
  • Joined

  • Last visited

  • Days Won

    16

Posts posted by rob

  1. The cost of registration is calculated in advance, before the registrant gets to the page with the paypal 'Pay Now' button, and is stored in a 'fee' session variable. I'm then passing the value of $_SESSION['fee'] to the paypal button... or at least that is my intention.

     

     

    Have you looked at the source code for that page to confirm it's being set correctly?

     

    You should dump the contents of the information sent by paypal to your ipn script into a text file. This will enable you to see which conditions are met and whether your ipn script gets to the part where the sql query should be executed.

     

    If it does then you'll have to go through the standard sql debugging to see where the error is.

  2. In your script you're testing a mysqli object ($connection) to NULL; from the manual:

     

    OO syntax only: If a connection fails an object is still returned. To check if the connection failed then use either the mysqli_connect_error() function or the mysqli->connect_error property as in the preceding examples.

     

    http://www.php.net/manual/en/mysqli.construct.php

  3. I've been testing code against the RCs of PHP 5.4 for about a month and realised that the official stable version was released in the last 24 hours.

     

    Liking it a lot: especially the short array syntax, built in server and traits. Nice to see register globals and magic quotes gone too.

     

    Can't believe how tedious writing array in 5.3 has already become.

     

    Anyway, I thought I'd just post this up just in case anyone had missed it:

     

    http://php.net/releases/5_4_0.php

  4. Ok, it's been a while since I used mysqli, unless I have to work with legacy code, I pretty much stick to PDO these days.

     

    Re-reading the php manual, if you use prepared statements for SELECT queries you need to bind the results, so my question was nonsensical; apologies for misleading.

     

    If I had to achieve what you're doing and I had the option, I would probably avoid a prepared statement and go with:

     

    $query = "SELECT… ";
    
    if ($result = mysqli_query($mysqli, $query)) {
    
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    	$myarray[] = $row;
    }
    
    mysqli_free_result($result);
    }
    

     

    Just remember to filter and sanitize your search terms if you go down that route.

     

    Might be worth reading through the user comments on the php manual for a possible solution using prepared statements other than the one you already have.

    • Upvote 1
  5. Non persistant database connections are closed automatically at the end of script execution.

     

    If you're pre-populating a form with data from a database, and a user submits that form, these are 2 script executions and therefore 2 separate connections to the database.

     

    You could close the connection manually after both your SELECT and UPDATE queries - I've assumed the form posts data back to the same script and the UPDATE query won't be called unless the script tests true for form submission.

     

    mysqli_free_result frees up memory used by the result of your query.

     

    General rule is use mysqli_free_result after executing queries and mysqli_close when you know you no longer require a database connection for the rest of the current script execution.

     

    I think it's good practice to use both, can also make code easier to review for you and others.

  6. while(mysqli_stmt_fetch($stmt)) {
    	$myarray[] = array($col1, $col2));
    }
    

     

    $myarray will automatically assign the index numbers, you don't need to.

     

    However, if I have more variables seems a little inconvenient to repeat over and over again... I wonder if there is any way faster or better.

     

    Is there a reason you're using bound results? If not, simply assign returned $rows to $myarray.

     

    while($row = mysqli_fetch_row($result)) {
    	$myarray[] = $row;
    }
    

    • Upvote 1
  7. No worries,

     

    Wanted to test this for myself, for anyone who was interested in a working example for locally stored video above the root directory for protection:

     

    Downloaded latest JW player from http://www.longtailv.../jw-flv-player/

     

    Created a page with the following code:

    (include player.swf in same directory your viewer page)

     

    <script type='text/javascript' src='jwplayer.js'></script>
    
    <div id='mediaspace'>This text will be replaced</div>
    
    <script type='text/javascript'>
    jwplayer('mediaspace').setup({
     'flashplayer': 'player.swf',
     'file': 'proxy.php',
     'controlbar': 'bottom',
     'provider': 'video',
     'width': '470',
     'height': '320'
    });
    </script>
    

     

    Created a directory above the document root called video (I know original); remember to check directory perms.

     

    Found the absolute path to video directory

     

    Created a proxy script called proxy.php (place in same directory as viewer page), with the following:

     

    <?php
    
    $file = "[ABSOLUTE_PATH_TO_VIDEO_DIR]" . 'video.mp4';
    
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Cache-Control: no-store, must-revalidate");
    header("Content-Type: video/mp4");
    header('Content-Length: ' . filesize($file));
    
    readfile($file);
    

     

    Obviously change ABSOLUTE_PATH_TO_VIDEO_DIR to whatever that is on your development/production server.

     

    To play different video files pass the page with the player embedded a $_GET variable and then just send this to the proxy.php script:

     

    proxy.php?video=your_get_var
    

     

    Append to the end of $file instead of video.mp4 in the above example.

     

    JW player also offers a setup wizard at http://www.longtailv...er-setup-wizard which shows an option for a playlist, which may be a better way of doing it, but I've run out of time to check.

     

    NB:

     

    JW player does offer HTML5 video with fallback to flash, but this was about protecting content so I haven't bothered with it.

     

    This is just a quick proof of concept, I haven't included any validation in the proxy script; however, should be a good starting point for anyone who's interested.

    • Upvote 2
  8. Yeah this is the big stumbling block for html5 video.

     

    You could store the files outside the document root and access them through a proxy script and run them through a flash player (JW player is pretty easy to use). I think some sites do this with javascript, but it's not an area I'm familiar with.

     

    Alternatively, store the assets on Amazon S3 and set up bucket permissions to only allow linking from the server ip address the sports club website is hosted on. Then run it through a flash player on the website. You might also want to take a look at Amazon CDN which offers streaming. JW player has Amazon CloudFront support built in, but I've never used it.

     

    Truth is though, if someone wants to copy your content, there's no way to prevent it; there are freely available tools for download that will rip flash/music/anything.

     

    There are probably more options available which may suit your requirements better, I'll be interested to see what others have used/suggest.

    • Upvote 2
  9. In addition to Jonathon's comments, I don't think it's great to hide any product unless you're discontinuing it. Amazon allow you to purchase even if the item is not in stock - I'm sure I've done this with two of Larry's new books in the past, they had order early discounted prices.

     

    On a recent ecommerce project, I had item pages without stock state "Stock on order" with both a form to enter a contact email address(to be notified when stock was in) and the addition of thumbnail images/links for similar products in stock.

    • Upvote 1
×
×
  • Create New...