Jump to content

craigj1303

Members
  • Posts

    12
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

craigj1303's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi Requinix, thanks for your reply. Yes, you are correct, perhaps I phrased it incorrectly. Your comment: That is exactly what I want to do for SEO purposes. What line(s) of code would I need to add to my existing code to make requests for the old URL redirect to the new URL using 301 redirect? I am aware of the Redirect 301 rule but need to understand if that is the correct way to go about it with maybe adding some form of regex?
  2. Hi There I've been working on creating search engine friendly URLS from query strings. I have written some rules using mod_rewrite and the rules are working well and re-directing query string URL's to my new friendly URL's. However, I seem to have a problem when introducing the [R=301] flag. This code gives me my Search Engine friendly URL in the address bar: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteCond %{REQUEST_URI} ^/ranges/ RewriteRule ^([-a-zA-Z_0-9]+)/([a-zA-Z_0-9]+)$ /index.php?page=show_range&range_id=$2 [QSA,L] But after I enter the R=301 flag this code gives displays the full index string URL: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteCond %{REQUEST_URI} ^/ranges/ RewriteRule ^([-a-zA-Z_0-9]+)/([a-zA-Z_0-9]+)$ /index.php?page=show_range&range_id=$2 [R=301,QSA,L] I am told that R=301 should be implemented to let Google know that the page has moved. What is going wrong?
  3. Hi, thanks for the advice. Before I go and experiment with that, I have been informed I need to do 301 redirects so not only do the URL's look more frindly, but Google will be aware that they have moved permanently. How do I build that in to the equation?
  4. Hi There I designed a database driven site some years ago using PHP and HTML. All the site pages are routed through index.php and the content of those pages is determined by the query string in the URL which then triggers PHP includes. I am now at a stage where we have a SEO company who has advised us to make our URL's "SEO friendly". They advise that the best way to do this is using 301 redirects and using the mod_rewrite feature on the Apache Server. I have no experience whatsover with this. What is the best way to go about this? I have googled mod_rewrite etc. but there is so much information I don't know what the best way to proceed is. Below is an example of what I want to achieve across the site: Existing URL: http://www.mycompany.co.uk/index.php?page=show_range&range_id=39 Proposed URL: http://www.mycompany.co.uk/ranges/balmoral If anyone can offer any advice for best practice I would most appreciate, or even a link to a good tutorial that would be great! Thanks in advance, Craig
  5. Hi All I developed a site using PHP & a MYSQL database. From the off I structured the site by routing everything through index.php. This way the page shell (banner, navigation etc) is always consistent and I use includes for the various page contents. This has been fine up until now. But now I am designing in a new aspect to the site which requires a user to login to view some content. Now, the problem is that I want to check if the user has logged in before certain content is displayed, and I have a confirm_login() function that checks if a $_session variable has been set for login. If the login $_Session variable hasn't been set the user is diverted to the login page. But this confirm_login() function requires me to check for a user login on every page and I only need the user to be logged in for a few secure pages. But as everything is routed through index.php how can I best handle this? Regards Craig
  6. Well David & Wildteen, It seems you were both on the right track with the charset thing. I always thought I just opened a text editor, typed my code, saved it and that was that. I didn't know there were different charsets to save under etc, but your comments got me looking in to it and I opened all my php files relating to this project in my text editor. At the foot of each page the text editor revealed different types for each file. Some said UNIX, some MAC and some DOS. The 2 includes that were failing were MAC ones. I cut the text and pasted in to a UNIX file, saved that and hey presto, it works now! During this project I have been working on my apple imac, my windows XP laptop and my Windows XP laptop at work. I have been saving my work and transferring to flash drive and carrying between computers over time. I guess that is why some files have these different "charsets"? I don't know, but i've never seen any options available to save as a certain type of text. I thought it was just....well......text! Anyway, thanks for putting me on the right track, I was up 'til 3am last night banging my head against the wall!] Regards Craig
  7. Hi David, Nope, all my pages begin with "<?php" as the opening tag. I tried deleting "output_fns.php" as a test out of curiousity and PHP then failed to parse the next included file "general_fns.php".
  8. Hi All I have been working on a project in PHP for about three months. I have been happily working away with a WAMP server locally all that time. The problem arose today when I uploaded the project to a web server. I uploaded all the files by FTP and imported a mysql database on the new web server. When I went to view my home page I got the following error: Parse error: syntax error, unexpected T_STRING in /home/priestbr/public_html/output_fns.php on line 1 My index page references an include to a page which stores my functions: <?php error_reporting(E_ALL ^ E_NOTICE); session_start(); include('priest_br_fns.php'); The priest_br_fns.php then includes a further 3 includes as below: <?php include_once('db_fns.php'); include_once('output_fns.php'); include_once('general_fns.php'); ?> PHP seems to parse the db_fns.php page OK and fails at output_fns.php (as per the parse error msg). But here's the thing....during some investigation I deleted the contents of db_fns.php and pasted in the contents of output_fns.php and then the page got parsed OK! Anyone have any idea why it's failing? Is it something to do with how I have the includes set up? I really need all the includes working obviously for the site to run. For info my local server where the site works perfectly is set up as below: PHP 5.2.6, MySQL 5.0.51a, Apache 2.2.8 The web server is set up like this: PHP 5.2.1.14, MySQL 5.0.91, Apache 2.2.16. Thanks in advance, Craig
  9. Hi Guys Ever had the feeling your being a spoon and can't see the wood for the trees? Well, that's how I feel today. All I am trying to to is implement a variable in a "foreach" loop that increments by one through each iteration of the loop. I know how to do it in a "for" loop but can't for the life of me get it to work here. Here is the code: foreach ($cart as $prodcode => $qty) { $item = get_product_details($prodcode); echo '<input type="hidden" name="item_name_'.[b]$needavariablehere[/b].'" value="'.$item['description'].$_SESSION['finish'][$prodcode].$_SESSION['handles'][$prodcode].'" />' . "\n"; } Where I have highlighted $needavariablehere is where I want a number to appear i.e. if there is one item available and the foreach loop iterates once I want the number 1 here. If there are two items and the foreach loop iterates twice I want the output to have number 1 in the first line and number 2 the second time around and so on. How many times the foreach loop iterates is based on the $cart array which contains items in a shopping cart. Thanks for any help you can give guys.
  10. Hi MrAdam! As you said in your reply to kumarkiranm I can't store all the products available with different finishes in the products table because they would have to have a different product_id and I would be upkeeping hundreds of extra products in the database. The products are stored in a database table called "products" and the finishes are stored in a seperate table called "finishes". The "products" table contains all the information about the product e.g. part number, weight, width, associated images etc. It also contains a field called 'finish_id' which is integer. I use this field to identify what finishes are available for each product. The finishes available seem to be in groups. If the field is null I know that that item is available in only one finish. If finish_id is "1" the item page displays a drop down menu with 5 options. If finish_id is "2" the item page displays a menu with a different set of options still. The "finishes table" contains an ID for each finish available, the name of the finish, the finish_id field (as in the products table)
  11. Hi All I am in desperate need of help with a shopping cart script i've been working on. Here is the background. Basically, I have been working on a site for a furniture company. I have added some products to a database and am now at the stage where I want to add the product to a shopping basket. Here is the script which is called when I add a product to the basket or view the cart: <?php include ('functions.php'); session_start(); @ $new = $_GET['new']; if($new) { //new item selected if(!isset($_SESSION['cart'])) { $_SESSION['cart'] = array(); $_SESSION['items'] = 0; $_SESSION['total_price'] ='0.00'; } if(isset($_SESSION['cart'][$new])) $_SESSION['cart'][$new]++; else $_SESSION['cart'][$new] = 1; $_SESSION['total_price'] = calculate_price($_SESSION['cart']); $_SESSION['items'] = calculate_items($_SESSION['cart']); } if(isset($_POST['save'])) { foreach ($_SESSION['cart'] as $prodcode => $qty) { if($_POST[$prodcode]=='0') unset($_SESSION['cart'][$prodcode]); else $_SESSION['cart'][$prodcode] = $_POST[$prodcode]; } $_SESSION['total_price'] = calculate_price($_SESSION['cart']); $_SESSION['items'] = calculate_items($_SESSION['cart']); } if($_SESSION['cart']&&array_count_values($_SESSION['cart'])) display_cart($_SESSION['cart']); else { echo '<p>There are no items in your cart</p>'; } $target = 'index.php'; // if we have just added an item to the cart, continue shopping in that category if($new) { $details = get_product_details($new); if($details['category_id']) $target = 'index.php?page=show_category&category_id='.$details['category_id'].'&sort='.$_GET['sort']; } ?> This script is working great with standard products. The variable $_GET['new'] is carried over to the script from the product page and the function "display_cart" displays each product with a little thumbnail of the item and some details in a nice table row where you can alter the qty, delete the item etc. Great.....no problem. Now this is the curve ball! Certain items have "optional finishes". i.e. product number 1234 is available in white, black and red. So I thought, OK, before the user adds that item to the cart they select a finish from a drop down menu and this information can be carried across to the cart script by way of $_POST['finish']. But for the life of me I cannot work out how to display this information in my cart table row alongside the product information. Obviously I can echo the $_POST['finish'] variable which is great for the first item but if I add another product to the cart in a different finish it changes the finish for the first item and every other item as well! Here is the code for the function display_cart: <?php function display_cart($cart, $change = true, $images = 1) { // display items in shopping cart // optionally allow changes (true or false) // optionally include images (1 - yes, 0 - no) echo '<table style="margin-top: 20px;" border = "0" width = "95%" cellspacing = 0> <form action = "index.php?page=show_cart" method = "post"> <tr><th colspan = '. (1+$images) .' bgcolor="#905f36">Item</th> <th bgcolor="#905f36">Finish</th><th bgcolor="#905f36">Price</th><th bgcolor="#905f36">Quantity</th> <th bgcolor="#905f36">Total</th></tr>'; //display each item as a table row foreach ($cart as $prodcode => $qty) { $item = get_product_details($prodcode); echo '<tr>'; if($images ==true) { echo '<td align = left>'; if (file_exists('images/products/small/'.$item['sm_image'])) { $size = GetImageSize('images/products/small/'.$item['sm_image']); if($size[0]>0 && $size[1]>0) { echo '<img src="images/products/small/'.$item['sm_image'].'" '; echo 'width ="'. $size[0]/3 .'" height = "' .$size[1]/3 . '" />'; } } else echo ' '; echo '</td>'; } echo '<td align = "left">'; echo '<a href = "index.php?page=show_product&product='.$prodcode.'">'.$item['description'].'</a>'; echo '</td>'; [u][i][b]echo '<td></td>';[/b][/i][/u] echo '<td align = "center">$'.number_format($item['price'], 2); echo '</td><td align = "center">'; // if we allow changes, quantities are in text boxes if ($change == true) echo "<input type = 'text' name = \"$prodcode\" value = \"$qty\" size = 3>"; else echo $qty; echo '</td><td align = "center">$'.number_format($item['price']*$qty,2)."</td></tr>\n"; } // display total row echo "<tr> <th colspan = ". (3+$images) ." bgcolor=\"#905f36\"> </td> <th align = \"center\" bgcolor=\"#905f36\"> ".$_SESSION['items']." </th> <th align = \"center\" bgcolor=\"#905f36\"> \$".number_format($_SESSION['total_price'], 2). '</th> </tr>'; // display save change button if($change == true) { echo '<tr> <td colspan = '. (2+$images) .'> </td> <td align = "center"> <input type = "hidden" name = "save" value = true> <input type = "image" src = "images/save.png" border = 0 alt = "Save Changes"> </td> <td> </td> </tr>'; } echo '</form></table>'; } ?> It is between the <td></td> cells I have underlined in the above function that I need to contain the optional finish if one has been selected by the client. Would really appreciate your help with this one guys. I've been trying to program a solution for a week now but after much deliberation with associative arrays, loops and $_SESSION variables i'm at the stage where it has taken over my life and I can think of nothing else until I get it resolved and I can't do it by myself! I think the answer lies with $_SESSION variables but i'm at that "staring at the computer screen with a blank expression on my face" stage and I can no longer see the wood for the trees! HELP!! Many thanks Craig
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.