-1

In my database I have a table which has an Id column.

I am using this id as a link variable. For example test.php?id=1, deneme.php?id=2.

I want the numbers to be 5 digits so that one can not simply change the id value and go to the page.

How can I do that? Is thare an algoritm that produces 5 digit numbers? For example I will give 1 and it produces 34212 and I will give this number as test.php?id=34212 and get its equivalent that is 1 and will fetch the page.

AgeDeO
  • 3,137
  • 2
  • 25
  • 57
user1223672
  • 21
  • 1
  • 6
  • What happens when your database gets 10,000 rows in it, or 100,000 rows in it. – RiggsFolly Mar 18 '15 at 15:17
  • It can not have because this is lesson table and 5 digit enables me to have 99.999 lessons. – user1223672 Mar 18 '15 at 15:20
  • Hope this answer an guide you to your way. [click here][1] [1]: http://stackoverflow.com/a/24350962/1578908 – Rajnikant Sharma Mar 18 '15 at 15:45
  • 1
    If you want an algorithm it'll have to be something simple like `$id = $_GET['id'] - 34211;`, but someone can increment/decrement that number just as easily. If you want to prevent increment/decrement, you'll need to generate a random number when you create the record and use that to look it up. – ceejayoz Mar 18 '15 at 15:47

1 Answers1

0

One common solution to your problem can be a token sended with the id in the request. So you need to check if token is valid and then do the requested action.

The token its generated server side and you know how check if it is valid, you can use MD5 or SHA1 for this purpose.

Juan de Parras
  • 768
  • 4
  • 18