This topic is locked
[SOLVED]

 How to pass variable through URL to external page securely

3/12/2014 10:28:10 AM
PHPRunner General questions
A
Abul author

I had an issue to create pdf from my order list page on the fly by using FPDF lib. I posted the issue to get help here. Fortunately I had solved by myself by passing variable through URL. However it created a security issue. Because the variable is visible on the external URL page which can be editable and easy to access to another unauthorized record by different user. I have solved this issue and now I am intending to post here if anyone gets help if they have the same issue as well as to find any hole in my code if anyone sees into it for further improvement. What this will do for you, it will pass your recordID from list page to external page through URL. Visitor can see the recordID on their URL address bar but they cannot edit the recordID to unauthorized access to another record.
Step 1:

I created an extra blank filed in my order table I called it “Print” and field type is varchar.
Step 2:

Uncheck this filed for add, edit and nay other pages except list page. Keep this field at the end of the list page.
Step 3:

Go to the visual editor and change the field into “Custom View as”. Add this code

$var = $data["id"]; (id is for order table)

$salt='something';

$hash=md5($salt.$var);

$value = "<a href='ord.php?ord_id=$var&anyword=$hash'>pdf</a>";


Step 4:

Open your ord_pdf.php file which will pull data from the database query and create pdf file. Enter this code right after MySQL connection block.

$var=$_GET['ord_id'];

$salt='something';

$hash=md5($salt.$var);
if ($hash==$_GET['anyword']){
$ord_id=$_GET["ord_id"];

}


Step 5:

You are done. Your new URL will be similar to http://localhost/test1/ord.php?ord_id=42&anyword=1d18ef5dfaea4681062809ea679c1582


Now if you change the id from 42 to any other it will popup error msg.
Hope it will helpful. But please let me know if you have any good solution better than this. I will appreciate your help.

Off topic: “FAIL” doesn’t mean you are fail rather it’s mean First Attempt In Learning.
P
phenicie 3/13/2014

Thanks for sharing. That is a valuable add! i am not qualified to point out any holes though.