CodeIgniter Forums
How can I hide content id on URL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: How can I hide content id on URL (/thread-66418.html)

Pages: 1 2


How can I hide content id on URL - olmos - 10-20-2016

Hi Everyone.

Firstly Sorry for my bad engelish. 

Firstly my url : explame.com/olmos/id/content-title/

So I want to hide /id/ from the URL.


So my routes.php like : 

"olmos/([0-9]+)/(.*)"] = "pages/olmos";


Thanks for your help.


RE: How can I hide content id on URL - Compra Venta Cuba - 10-20-2016

Uhmm, how do you detect wich article id is the user requesting.
Maybe you can use the "slug" as the identifier like do Wordpress.


RE: How can I hide content id on URL - Shawn - 10-20-2016

(10-20-2016, 06:42 AM)olmos Wrote: Hi Everyone.

Firstly Sorry for my bad engelish. 

Firstly my url : explame.com/olmos/id/content-title/

So I want to hide /id/ from the URL.


So my routes.php like : 

"olmos/([0-9]+)/(.*)"] = "pages/olmos";


Thanks for your help.

You can use a form in place of a link and pass the id in as a post.


RE: How can I hide content id on URL - tapan.thapa - 10-20-2016

You can try below steps to hide id in your urls.

$id = 123;

$encode = base64_encode($id);

$decode = base64_decode($encode);


RE: How can I hide content id on URL - InsiteFX - 10-21-2016

Or a hidden input form field


RE: How can I hide content id on URL - olmos - 12-04-2016

maybe it will be more better if I can show the codes Smile


pages_model.php

PHP Code:
   public function getMakale($id)
   {
       $record $this->db
                           
->from('makale')
                           ->where('id'$id)
                           ->where('status'1)
                           ->get()
                           ->row();
       
       if 
(empty($record)) {
           return FALSE;
       }
       
       $record
->user $this->getUser($record->user_id1NULLFALSE);
       
       return $record
;
   }
   
   public 
function getMakaleKategori($id)
   {
       $record $this->db
                           
->from('makale_kategori')
                           ->where('id'$id)
                           ->where('status'1)
                           ->get()
                           ->row();
       
       if 
(empty($record)) {
           return FALSE;
       }
       
       $record
->makaleler $this->getMakaleKategoriToMakale($record->id);
       
       return $record
;
   

--------------------------------------------------


controller - pages.php


PHP Code:
 public function makale()
   {
       $id = (int) $this->uri->segment(2);
       $record $this->pages_model->getMakale($id);
       
       if 
(empty($record)) {
           $this->site->set_alert('error'lang('makale-not-exist'));
           redirect('makaleler');
       }
       
       $this
->pages_model->updateHit('makale'$record->id);
       $record->hit $record->hit 1;
       $this->data['record'] = $record;
           
$this
->site->breadcrumb('Makaleler''makaleler''');
$this->site->breadcrumb($record->baslik'''');
       
$this
->site->title($record->baslik);
$this->site->description($record->meta_description);
$this->site->keywords($record->meta_keywords);
       
$this
->load->view('makale'$this->data);
   }
  
 
-------------------------------------------------

and the routes code

PHP Code:
$route["makale/([0-9]+)/(.*)"] = "pages/makale"
thank you veri much.


RE: How can I hide content id on URL - InsiteFX - 12-04-2016

Show the fields in your database table, you would use a slug for accessing it.


RE: How can I hide content id on URL - olmos - 12-04-2016

(12-04-2016, 11:43 AM)InsiteFX Wrote: Show the fields in your database table, you would use a slug for accessing it.


I have field in database : url 

http://prnt.sc/dfaztz


so first item is "id" So I wanna hide id and just I wanna use the "URL" in database. Thanks for your help


RE: How can I hide content id on URL - olmos - 12-05-2016

Can someone help me about it ???


RE: How can I hide content id on URL - PaulD - 12-05-2016

Hi,

This is quite straight forward to do.

1. In a table for products you would have product_id, product_url, plus all your other columns like name, price, description etc.
2. The product_url is a unique column and can be auto generated based on, say, the required product_name, or your user or admin can add a custom one from your 'add product screen'.
3. When you generate a url like your example, you do not send the 'id', you send the 'product_url' and look up your product from that.

PHP Code:
public function view_product($product_url)
{
 
   // do your query on the product_url


To generate the url you would do

Code:
<a href="<?php echo site_url('products/view_product/'.$item['product_url']); ?>">ProductName</a>

The url will then be something like:

Code:
www.mydomain.com/products/view_product/my_wonderful_product

So now, the product ID's are only for internal use, any reference to them in url's or your HTML is by url name, not their id. (By internal use, I mean once you have the product, you would still gather other related tables via the id, such as related products, special offers, related articles, reviews etc).

Hope that helps.

Paul.