php_guest Posted January 21, 2009 Share Posted January 21, 2009 I have a list of 300 products inside one page: T-shirts Trousers Socks ... Every product is a link to the next page. I would like to assign the value of variable for each product so I can pull in next page right information from table Products. Due SEO I would like to keep URL in following format: www.sitename.com/productname So my question is how to send a value of variable of a product to which user click to the next page? Will code read from www.sitename.com/productname once beeing on next page which productID to pull from database? Quote Link to comment https://forums.phpfreaks.com/topic/141849-how-to-move-value-to-next-page/ Share on other sites More sharing options...
MatthewJ Posted January 21, 2009 Share Posted January 21, 2009 Google for mod_rewrite Quote Link to comment https://forums.phpfreaks.com/topic/141849-how-to-move-value-to-next-page/#findComment-742699 Share on other sites More sharing options...
Lodius2000 Posted January 21, 2009 Share Posted January 21, 2009 ditto, google mod_rewrite, when you enable mod_rewrite your $_GET variables now look like directories sitename.com/index?product=productname becomes sitename.com/productname Quote Link to comment https://forums.phpfreaks.com/topic/141849-how-to-move-value-to-next-page/#findComment-742710 Share on other sites More sharing options...
DeanWhitehouse Posted January 21, 2009 Share Posted January 21, 2009 Just a little warning, first off not all hosts will allow mod rewrite, second off i believe it can cause problems with some search engines as it looks for a directory then and not a file, and third if the user or you try and use site.com/productname/ it won't work it has to be site.com/productname Quote Link to comment https://forums.phpfreaks.com/topic/141849-how-to-move-value-to-next-page/#findComment-742713 Share on other sites More sharing options...
php_guest Posted January 22, 2009 Author Share Posted January 22, 2009 Just a little warning, first off not all hosts will allow mod rewrite, second off i believe it can cause problems with some search engines as it looks for a directory then and not a file, and third if the user or you try and use site.com/productname/ it won't work it has to be site.com/productname depend of that, is there any better solution how to move value to next page in this case? Quote Link to comment https://forums.phpfreaks.com/topic/141849-how-to-move-value-to-next-page/#findComment-742788 Share on other sites More sharing options...
haku Posted January 22, 2009 Share Posted January 22, 2009 Just a little warning, first off not all hosts will allow mod rewrite Pretty much all of them do these days. If they don't, it's time to get a new host, as that host is living in the dark ages. second off i believe it can cause problems with some search engines as it looks for a directory then and not a file Search engines have no clue whether the directory exists or not. They don't see the server, they only see the data that the server feeds to them. Mod rewrite is set up on the server, and any rewriting is done internally before being sent to the search engines (or user). So whether a directory exists, or whether mod rewrite just makes it look like a directory exists, it doesn't really matter. third if the user or you try and use site.com/productname/ it won't work it has to be site.com/productname If the mod rewrite is written properly, both can work. Quote Link to comment https://forums.phpfreaks.com/topic/141849-how-to-move-value-to-next-page/#findComment-742954 Share on other sites More sharing options...
DeanWhitehouse Posted January 22, 2009 Share Posted January 22, 2009 Search engines have no clue whether the directory exists or not. They don't see the server, they only see the data that the server feeds to them. Mod rewrite is set up on the server, and any rewriting is done internally before being sent to the search engines (or user). So whether a directory exists, or whether mod rewrite just makes it look like a directory exists, it doesn't really matter. No, that is not what i meant when you use it in links and/or submit them as pages in your site map it can make the search engine believe it is a directory and in effect come up with a 404 Quote Link to comment https://forums.phpfreaks.com/topic/141849-how-to-move-value-to-next-page/#findComment-743329 Share on other sites More sharing options...
php_guest Posted January 22, 2009 Author Share Posted January 22, 2009 I found also one another solution with $_SERVER['REQUEST_URI'] function. Which one do you think is better. I just don't know now how to change www.mysite.com/product.php/productname into www.mysite.com/productname. Please tell me how to change following code to get this format of url. Showing product page is inside product.php. //Insert product into DB <?php $productName="laptop"; $urlID="/product.php"."/".$productName; $con = mysql_connect("localhost", "root", "") or die(mysql_error()); $db = mysql_select_db("DBname", $con); mysql_query("INSERT INTO products (urlID, productName) VALUES ('$urlID', '$productName')") or die(mysql_error()); ?> //productsList.php <?php $con = mysql_connect("localhost", "root", "") or die(mysql_error()); $db = mysql_select_db("DBname", $con); $query="SELECT * FROM products"; $result=mysql_query($query); while ( $row = mysql_fetch_assoc($result)) { extract ($row); echo "<a href='/product.php/$productName'>$productName</a>"; echo "<br />"; } ?> //product.php <?php $urlID=$_SERVER['REQUEST_URI']; $con = mysql_connect("localhost", "root", "") or die(mysql_error()); $db = mysql_select_db("DBname", $con); $result=mysql_query("SELECT * FROM products WHERE urlID='$urlID'"); $row = mysql_fetch_assoc($result); $product=$row[productName]; echo $product; ?> Quote Link to comment https://forums.phpfreaks.com/topic/141849-how-to-move-value-to-next-page/#findComment-743613 Share on other sites More sharing options...
DeanWhitehouse Posted January 22, 2009 Share Posted January 22, 2009 Use .htaccess so that when someone requests mysite.com/productname it actually loads mysite.com/product.php?product=productname_or_id Quote Link to comment https://forums.phpfreaks.com/topic/141849-how-to-move-value-to-next-page/#findComment-743617 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.