PHP - Uniqid(); Wtf?
Hi guru's,
I was just playing around with formtokens by using the function uniqid(); (is this btw unique enough for a form token?) pretty soon i noticed something weird: I have this small script (for testing) <?php $token = uniqid; echo $token; //resulting in something like: 4cbba625bd06d ?> Now for some reason if i run this code no matter how often the first few characters are always 4cbba Anyone has an idea on why/ how et cetera? So 2 questions: - is this function good enough for creating a secure form token? - how/ why does it keep starting with 4cbba? Would love to here it, thank you Similar TutorialsI would like to secure my files from being downloaded using this code. Code: [Select] <?php $unique = md5( uniqid() ); // 32 hex characters ?> but i dont know how to apply it to my files. I have a form on page 1 that submits to page 2, then on to page 3, 4 and 5. On each page more data is collected, then page 5 puts it all into its respective place in the database. I'm trying to prevent a duplicate entry from someone hitting the back button, and I've seen suggestions to do it with sessions and a uniqid. I'm not versed in sessions, so my first question is, because I'm not submitting to the same page, where do I put the session? on page 2 or page one? Right now, on page one, all I have is: Code: [Select] <?php session_start(); include("dbconnection.php"); ?> <!-- a bunch of javascript form validation, html code and the form --> <?php $unique_id = uniqid (rand (),true); $_SESSION['unique_id']=$unique_id; ?> <form name="register1" class="registration_form" method="post" action="register2test.php" target="_self" onsubmit="return myForm()"> <input type="hidden" name="unique_id" id="unique_id_form" value="<?php echo $unique_id; ?>" > <input type="submit" value="Submit" class="buttontype"/> </form> on page two, I'm assuming, it's something similar to... Code: [Select] <?php session_start(); if (isset($_POST["submit"])) { if ($_POST["unique_id_form"] == $_SESSION["unique_id"]) { $_SESSION["unique_id"] = ''; /*set variables here ? */ } else echo 'error'; } else { $_SESSION["unique_id"] = uniqid (rand (),true); ?> |