Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since your main motive here to keep people form guessing the id in url and since as pointed out by <strong>lucas william</strong> that the way you want it is not possible in .htaccess instead you can store the id of each product in the database as guid format(this format of id storage into database is used by <strong>sugarCRM</strong>) which is also a proper substitute to satisfy you required and you can use that id to uniquely identify you product table each records:</p> <p>The functions to create guid is as follows:</p> <pre><code>function create_guid() { $microTime = microtime(); list($a_dec, $a_sec) = explode(" ", $microTime); $dec_hex = dechex($a_dec* 1000000); $sec_hex = dechex($a_sec); ensure_length($dec_hex, 5); ensure_length($sec_hex, 6); $guid = ""; $guid .= $dec_hex; $guid .= create_guid_section(3); $guid .= '-'; $guid .= create_guid_section(4); $guid .= '-'; $guid .= create_guid_section(4); $guid .= '-'; $guid .= create_guid_section(4); $guid .= '-'; $guid .= $sec_hex; $guid .= create_guid_section(6); return $guid; } function create_guid_section($characters) { $return = ""; for($i=0; $i&lt;$characters; $i++) { $return .= dechex(mt_rand(0,15)); } return $return; } function ensure_length(&amp;$string, $length) { $strlen = strlen($string); if($strlen &lt; $length) { $string = str_pad($string,$length,"0"); } else if($strlen &gt; $length) { $string = substr($string, 0, $length); } } </code></pre> <p>Now using the above function you can generate the id as:</p> <pre><code>$guid = create_guid(); //guid is of the format 79cb3604-e634-a142-d9cb-5113745b31e2 which you can see is quite impossible to guess. </code></pre> <p>Also I would sugest that you keep the auto increment field in your product table. Because it always a good idea to maintain a auto incremented field in a table to uniquely identity the records.</p> <p>I hope this can be of some help</p> <p>Edit :</p> <p>what you need to do is add a field in you database product table named "guid" so say your current database product table structure has the following fields:</p> <pre><code>id, name, price //where id is the auto incremented </code></pre> <p>after adding the field guid it becomes</p> <pre><code>id, guid, name, price //where id is auto incremented field and guid uniquely identifies each row in the product table </code></pre> <p>and when you do the insert of the product data in the database product table you generate the guid using the above code and insert it. ie</p> <p>for example </p> <pre><code>$sql = "Insert into product_table('guid','product_name',product_price) values('".$guid."','product1','59.00'); </code></pre> <p>so an example data in your product table will look like this:</p> <pre><code>1, 79cb3604-e634-a142-d9cb-5113745b31e2, product1, 59.00 </code></pre> <p>Now in the product.php page with url say</p> <pre><code>yoursite.com/product.php?guid=79cb3604-e634-a142-d9cb-5113745b31e2 </code></pre> <p>instead of using the url</p> <pre><code>yoursite.com/product.php?id=1 </code></pre> <p>you can easily query the data from the database product table in relation to "guid" which of course also uniquely identifies each row in your product table in the database there by elimiting the risk of user guessing your id in url of the webpage.</p> <p>I hope this gives you an idea of what i am trying to explain.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload