Results 1 to 10 of 10
  1. #1
    Resident Genius and Staunch Capitalist Leader's Avatar
    Join Date
    January 18th, 2005
    Location
    Florida
    Posts
    12,817
    How do I make PHP generate a 404 page when products no longer exist?
    I've recently dynamic-ized some sites of mine, and have come across this problem:

    Whenever a merchant stops putting an item in a feed, the data disappears upon update, of course.

    Problem is, if the affected page has been indexed, and someone comes to it, my site shows a blank page (just the header and footer) instead of sending them to 404sville. Also, these blank pages generate whenever a spider checks one of these dataless results, so the engine never really gets the clue that the page doesn't really exist anymore.

    Does anyone know, how do I make it so these obsolete listings go to 404sville like they would on a static site?
    There is no knowledge that is not power. ~Hemingway

  2. #2
    The Great Egress NewcastleB's Avatar
    Join Date
    January 19th, 2005
    Posts
    65
    Without actually looking up the code right now. Id think that you could test the number of rows returned mysql_num_rows() I think. And if that equals 0 you could provide alternate content or use header() to give them a 404. Should work.
    But are you still master of your domain?

  3. #3
    Affiliate Marketer Rogi's Avatar
    Join Date
    January 18th, 2005
    Location
    Melbourne
    Posts
    415
    What you could do is have a 'disabled' field in your database.
    When you parse the data feed, any products that are in your database from that merchant and were not modified or found in the feed, means they are no longer active.

    If you have this disabled field in your database, then on your product page, you have an if statement such as:

    if (!$disabled)
    { // display item information here
    }
    else
    {
    // display product does not exist page here
    // perhaps some adsense too ?
    }


    * see Step 3 of my thread at:
    http://forum.abestweb.com/showthread.php?t=57774

    it has this there too. (i got no replies on the thread so disappointed in myself)

  4. #4
    ABW Ambassador
    Join Date
    January 18th, 2005
    Posts
    4,423
    Why throw up a 404? Why not feature a list of other products from that category and say - while we are out of stock on that item, check one of these! 404's scare people away, you want to invite people in.

    Chet

  5. #5
    Affiliate Manager
    Join Date
    January 18th, 2005
    Posts
    1,056
    This is what I do... this is assuming that the product is completely deleted from the database when it is out of stock or no longer available.

    PHP Code:
    // Get number of rows for the product ID
    $sql "SELECT * FROM products_table WHERE product_id='$product_id'";
    $num mysql_num_rows(mysql_query($sql));
    if(
    $num 1){
    die(
    "Sorry, that product is no longer available please browse our store for other products... blah, blah, blah....
    <a href=http://www.store.com>Click Here</A>"
    );


  6. #6
    Resident Genius and Staunch Capitalist Leader's Avatar
    Join Date
    January 18th, 2005
    Location
    Florida
    Posts
    12,817
    NewcastleB and Chet_B:

    Thanks for the ideas, and ChetB thanks for the code snippet! Nothing like looking right at it...

    I was hoping to be able to have it so the server would tell the spiders "404" when a page's data ceased to exist, to keep the empties from diluting the rankability of the active stuff--but your ideas give me a way to show humans something other than an empty table, which is an improvement over what I've got!

    Rogi--I see what you're saying, but I'd have to redo how I do the updates to implement that, so I'd rather go with a PHP-side method if I can. Currently I just wipe out last week's stuff and load in the new, so there's no way to compare like that. If something's in stock the data exists. If the merchant dumps something, it utterly ceases to exist...


    Quote Originally Posted by chetf
    Why throw up a 404? Why not feature a list of other products from that category and say - while we are out of stock on that item, check one of these! 404's scare people away, you want to invite people in.

    Chet
    I was mainly worried that, as these blanks accumulated, Google et al would see the majority of the sites' pages as being empty and penalize for that. G's already thinking that one of the sites has twice as many pages as I have products to show (according to a site:www.mysite.com query)! Eventually it may be hard for the engines to find the pages that actually have stuff on them! So I was hoping to get rid of the inactives to make sure the active pages keep and/or improve their ranks.

    As for the 404 itself, I have a pretty good custom 404 that I did when the site went over to dyamic, so it should work as well as anything could (considering the site doesn't have what the person was looking for anymore)...so my main concern is that the active pages continue to be found and ranked, and not diluted or drowned in the old stuff.
    There is no knowledge that is not power. ~Hemingway

  7. #7
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    What I do is keep all the product information as it was originally except I change the "Buy It Now" button to "Out of Stock" and I simply stop linking to it from my categories and search engine. That way the search engines will deem the page dead since it no longer has any incoming links. It also gives the user an idea of what they're looking for if they happen to find it by the search engines' out of date information. My users can view my related products and decide if they want something else from there.

    I just can't delete data.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  8. #8
    Animal Lover
    Join Date
    January 18th, 2005
    Location
    oz
    Posts
    1,210
    I think if you want it to go to a 404, then borrowing from Chet's code it would be :

    // Get number of rows for the product ID
    $sql = "SELECT * FROM products_table WHERE product_id='$product_id'";
    $num = mysql_num_rows(mysql_query($sql));
    if($num < 1){
    header ("Location: http://www.yoursite.com/custom404.html");
    }

  9. #9
    Newbie
    Join Date
    January 18th, 2005
    Location
    Singapore
    Posts
    10
    header("HTTP/1.0 404 Not Found");

  10. #10
    Resident Genius and Staunch Capitalist Leader's Avatar
    Join Date
    January 18th, 2005
    Location
    Florida
    Posts
    12,817
    Thanks all,

    I'll be updating my code this week to incorporate this, so hopefully that'll be the end of the blank pages!
    There is no knowledge that is not power. ~Hemingway

  11. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. htaccess - passing referer page to 404.php
    By vivekar in forum Programming / Datafeeds / Tools
    Replies: 7
    Last Post: June 11th, 2010, 09:14 AM
  2. When Products Don't Exist Anymore - what do you do?
    By MoneyBusiness in forum Search Engine Optimization
    Replies: 3
    Last Post: November 21st, 2008, 08:50 PM
  3. Google has decided my sites no longer exist
    By Robert484848 in forum Midnight Cafe'
    Replies: 17
    Last Post: February 17th, 2004, 05:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •