Enter details before downloading

3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 27, 2013   (RSS)

Hi Tim, 

What about using something like this:

<?php
  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
  
  //Set page variables
  $errorsAndAlerts = "";

  //If the form has been submitted.
  if(@$_REQUEST['formSubmitted']){
    
    //Validate form 
    if(!@$_REQUEST['name']){ $errorsAndAlerts .= "You must enter you name.<br>"; }

    //If there are no errors
    if(!$errorsAndAlerts){
       //Set a session variable for the user
       $_SESSION['accessFiles'] = 'true';
    }
  }

  ?>
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php if($errorsAndAlerts): ?>
  <div class="errors">
    <?php echo $errorsAndAlerts; ?>
  </div>
<?php endif; ?>

<form action="scratch.php" method="get">
<!-- hidden input to check form has been submitted -->
<input type="hidden" name="formSubmitted" value="yes" />

  <input type="text" name="name" value="<?php echo @$_REQUEST['name']; ?>" />

  <input type="submit" name="submit" value="submit" />
</form> 
<!-- If the user has the accessFiles session variable set, display the list of files. -->
<?php if(@$_SESSION['accessFiles']): ?>
  <div class="fileList" >
    <ul>
      <li>List</li>
      <li>Files</li>
      <li>Here</li>
    </ul>
  </div>
<?php endif; ?>

So if the user has entered their information correctly into the form, you set a session variable for the user. Then you can use that session variable to trigger if the list of files is displayed or not.

The only issue with doing it this way is that the session data will be lost after a few days or if the user deletes their history. So they would have to fill in the form again to access the files.

Let me know if you have any questions.

Thanks

Greg 

Greg Thomas







PHP Programmer - interactivetools.com

By Toledoh - March 27, 2013

Hey Greg - that works a treat - thanks!

Cheers,

Tim (toledoh.com.au)