Jump to content
Larry Ullman's Book Forums

Craig-UK

Members
  • Posts

    35
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by Craig-UK

  1. RewriteRule ^bf/([A_Za-z0-9]+)/([0-9-]+)$ /bf/index.php?content=$1&event_id=$2
    RewriteRule ^bf/([A_Za-z0-9]+)/([0-9-]+)$ /bf/index.php?content=$1&article_id=$2
    

    Basically as you have said... Rewrite rule matches the first instance... in this example...

    www.yourdomain.com/bf/events/26 and www.yourdomain.com/bf/news/26 would both match "RewriteRule ^bf/([A_Za-z0-9]+)/([0-9-]+)$ /bf/index.php?content=$1&event_id=$2"

    Instead of trying to set 2 ReWriteRule's on this I would think the best way would be in the index.php itself, as there isn't really a way without changing the structure of the rules to get this to work.

    Make the event_id and article_id as just id.

    Take the last rule off and simply in the index.php make a if clause, for example:

    $event_id = "";
    $article_id = "";
    if ($_GET['content'] == "events") {
    $event_id = $_GET['id'];
    } elseif ($_GET['content'] == "news") {
    $article_id = $_GET['id'];
    } else {
    $error = "Some sort of error here";
    }
    

     

    Do the obvious checks of whether content and a id exist and whether they are valid etc. Also don't forget to set $event_id and $article_id above so then no error's appear.

     

    Hope that helps

    • Upvote 1
  2. Assuming "$row['field5']" has no value if there's no URL then you could just simple to a "if" clause

     

    if (($row['field5'] == "") || ($row['field5'] == "http://")) { // obviously change it to what suits you
     echo '<td align="left"></td>';
    } else {
     echo '<td align="left"><a href="' . $row['field5'] . '">' . "Link2" . '</a></td>';
    }
    

    or something similar.

     

    I haven't tested the code but you might need {} around {$row['field5']}

    • Upvote 1
  3. The only idea I have for this is a time limit for completing a purchase, so from when they 'add to basket' or 'purchase' they have 10 mins to finish the order, but for as long as they are still adding the 10 mins gets refreshed with each new item added.

    I have never tried it but I can't see it being too hard, timestamp the basket, each additional purchase updates the time as they are still active on your site. You could give them 5-10 minutes on your site and 10-20mins with the payment processor, so once they have clicked to pay.. you could cancel out the site time-limit and start the payment time-limit. Most payment processors allow you to send additional hidden information, this could be the timestamp once the payment is completed you can cancel the time-limit.

     

    If either time-limit is exceeded then the item becomes available again. Or you could simply set a overall 30min time limit to any basket to be completed from first addition. This is only 1 idea and I am sure others will come up with maybe a better solution.

    • Upvote 1
  4. To make this work you don't actually have to create folders. You can trick the URL for it to look like it's accessing a folder using .htaccess

     

    RewriteEngine on
    RewriteBase /
    RewriteRule ^([A-Za-z0-9]+)/?$ page.php?folder=$1
    

    I think that is all you need, but someone might need to correct it.

     

    Simply get that page.php script to read from the database and show the required info.

    If you do need to create folders then to get the value, save the folder name when creating it by either giving it a value and passing it through the script or giving a session it's value. Although these aren't the best of ways.

     

    Hopefully I understood your question correctly as it's quite vague.

    • Upvote 1
  5. May I ask as to why you're querying the password field anyway? Surely if you're doing a login script you should compare their password using the same hash code that you chose in the registration form.

     

    Also I think the reason why the last character was taken off when you queried the database is because it added a extra backslash 4th character in maybe theres a size limit exceeded.

  6. SELECT * FROM `users` WHERE `pass`='bb4c572b60661fe7dff6cca2fffc8c2155cb2cf85c5ce9f367f1c8df1228029d'
    

     

    I feel very confused and somewhat embarrassed asking this question :(

    Is it the fact that you are quoting the table of which you are trying to get information from?

     

    Edit: Hmm scrap that, should work even when quoted.

    Is there any chance you could screenshot the phpmyadmin of the password row, just to see if any of us can spot something that you possibly missed? Don't include any unrequired but secure information

  7. Hi,

     

    Your first error is

    if (empty($errors()) {
    

    should be

    if (empty($errors)) {
    

     

    You have also forgot to close the quotations on...

    $q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() );
    

     

    And finally you have also forgot the semi-colon on this line...

    echo '<h1>System Error</h1> <p>You could not be registered because of a system error. We are doing everything we can to resolve it<br />Please try again later</p>'
    

     

    Once I corrected those mistakes the script seems to work on my server. If you have any other problems then feel free to let us know :)

  8. Hi,

    I keep trying to upload a profile picture but keep getting the same "Failed to set a new photo" error.

    I have tried a couples of pictures.

     

    1. 2448 x 3264 jpg file 1,149 KB. This failed so assumed it was too big, so I made it smaller...

    2. 612 x 816 jpg file, 111KB. This also fails.

     

    I have tried it by clicking on my profile picture and using it that way, also by clicking edit my profile and using the upload profile picture that way. Both seem to fail.

     

    Am I the only person havin the problem lately, as I assume those with profile pictures had them up before this new forum update?

     

    Thanks

  9. Hi Larry,

    Your book is incredibly useful. I created a website for my staff to access pdfs of the different forms we use for an animal hospital. Occasionally, we change the forms content and will need to re-upload the pdf of it. I didn't see a way in your book to delete the pdf if it has already been uploaded. Any recommendations?

    Thanks,

    Sam

    Depending on if you name them the same, you could run a function to see if the file exists. If it does exists then to delete (unlink()) then rename the new uploaded file as the same filename.

    If the file is named differently then there really is no other way, unless you create a "replace" button next to each pdf or a tick option, then it replaces that using the same unlink() and file upload system.

    If I was you I'd let the file upload, check existance (if using first option), unlink the old, then rename the new file. That way if the file fails to upload then you don't lose the old one.

    If you need any further assistance with what I mentioned, feel free to contact me.

  10. It is possible, not that I have tested it.

    // Send the content information:
    header('Content-type:application/pdf');
    header('Content-Disposition:inline;filename="' . $filename . '"');
    $fs = filesize($file);
    header ("Content-Length:$fs\n");
    // Send the file:
    readfile ($file);
    exit();
    

    Replace $filename with your filename and $file with the path and filename to the requested file.

    Please look at Larry's E-Commerce book/files for more information

  11. It may not be the best way but one way is forwarding yourself to the same page with a success tag if the file uploaded successfully. Like...

     

    header ("Location: {$_SERVER['PHP_SELF']}?success=y");
    exit();

     

    and in the code have something along the lines of

     

    if (isset ($_GET['success']) && ($_GET['success'] == "y")) {
    
    echo '<h4>The file has been uploaded!</h4>';
    }

     

    That way if you click refresh it will just reload the page rather than uploading the file again.

    • Upvote 1
  12. From what I gather, you are still wanting people to access the PDF files but ONLY if they are logged in? If so I think I have changed the code correctly below

    <?php

    if(isset($_GET['id'])&&(strlen($_GET['id']) == 40)&&(substr($_GET['id'],0,1) !='.')){

    $file =PDFS_DIR.$_GET['id'];

    // if all 3 conditons are true then the path is defined

    if(file_exists($file)&&(is_file($file))) {

    //SQL for the path to the pdf

    $q = 'SELECT title, description, file_name FROM pdfs WHERE tmp_name = "'.mysqli_real_escape_string($dbc, $_GET['id']) .'"';

    $r = mysqli_query($dbc, $q);

    if(mysqli_num_rows($r) == 1) { // if everything is ok

    $row = mysqli_fetch_array($r, MYSQLI_ASSOC);

    $valid = true;

    if(isset($_SESSION['user_id'])) { // instead of getting rid of this, check whether they are logged in instead

    header('Content-type:application/pdf');

    header('Content-Disposition:inline; filename="' .$row['file_name'] . '"');

    $fs = filesize($file);

    header("Content-Length:$fs\n");

    readfile($file);

    exit();

     

     

    }else{ // if not logged in

    $page_title = $row['title'];

    include('./includes/header.html');

    echo "<h3>$page_title</h3>";

    if(isset($_SESSION['user_id'])) {

    echo '<p class="error">Thank you for your interest in this content. Unfortunately your account has expired. Please <a href="renew.php">renew your account</a> in order to access this file</p>';

    }else{

    echo'<p class="error">Thank you for your interest in this content. You must be logged in as a registered user to view this file</p>';

    } // You'd also need to get rid of this

    echo"<div>{$row['description']}</div>";

    include('./includes/footer.html');

    }//End of user IF-ELSE - You need this, its the end of checking whether they are logged in

    }// End of Mysqli_num_rows() IF - You'd also need this

    }// End of file_exists() IF

    }// End of $_GET['id'] IF

    if(!$valid){

    // if not VALID

    //Set $page_title to error and display an error message

    $page_title = "Error";

    include('./includes/header.html');

    echo '<p class="error">This page has been accessed in error.</p>';

    include('./includes/footer.html');

     

    }

     

    ?>

    • Upvote 1
×
×
  • Create New...