Jump to content


  • Content Count

  • Joined

  • Last visited

Everything posted by ajoo

  1. Hi Kicken, Thanks for the reply. The token is being used only to mark the account active. There is no autologin after that. Just a message on a page welcoming the user and a button to redirect to the login page. $mc = md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)); is this method of creating a random token good enough ? I am using the email to check if it's a valid email matching one in the database before I go ahead and actually activate the account but I could do that with the token as well I guess. So maybe I can remove the email in that case as suggested by you. Thanks again.
  2. Hi all, I am using the following code snippet to send a mail on registration for the purpose of account verification by the user. <?php $user = 'Jack'; $pass = 'You may pass'; // a random string to be checked against intself stored in the DB $mc = md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)); function send_mail($from,$to,$subject,$body) { $headers = ''; $headers .= "From: $from\n"; $headers .= "Reply-to: $from\n"; $headers .= "Return-Path: $from\n"; $headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Date: " . date('r', time()) . "\n"; if(mail($to,$subject,$body,$headers)=== true) return true; else return false; } if(send_mail( 'mymail@gmail.com', 'their@gmail.com', 'Register your Account.' "Click on this link http://www.yoursite.com/registeracc.php?email='their@gmail.com'&mc=".$mc." to activate your account" ) === true) echo "Success"; else echo "Failed"; ?> I would like to know if this is Ok or is there a better and more secure way to do it? Are there any security concerns that should be taken into account here? Thanks all !
  3. Hi Requinix, Thanks for your inputs. I was able to manage it. Thanks !
  4. Hi Requinix, Thanks for that reply. Yes that's happening due to Input[type=submit]. The triangular bit of the arrow disappears. It is retained with button[type=submit] but the arrow is distorted. Please check the new update to the link : https://jsfiddle.net/ajoo/hm11o3oh/9/ . Is it not possible to use the Input[type=submit] without distorting the button? To see the initial button with <a = href='' .. > this link : https://jsfiddle.net/ajoo/hm11o3oh/1/ I mean I need this button to send post values to the page. Thanks.
  5. Hi Requinix, Thanks for the reply and sorry for the delay. I have been struggling with this for quite sometime. I actually need to submit php values using the button, just like a regular button. I have been trying out this on a fiddle and here is the link to it : https://jsfiddle.net/ajoo/hm11o3oh/3/ The triangular part of the button breaks and the button loses its shape. Kindly have a look at the fiddle and guide. Thanks !
  6. I have the following piece of code give me a beautiful button that I want to use in a form. <div class='lbk'><a href='' class='btn_lft'>&nbsp Left</a></div> On pressing the button I want to send some post data back to the page which is where I am totally stumped and can't figure how I can do it with this button. It would be very simple to send it using a basically a simple submit button. But then I won't get the arrow button that looks so neat. Please can someone help me figure this out if it is possible. I do not wish to use Ajax etc. Thanks all.
  7. Thanks again Jacques !I request you again to kindly take some time out to answer my query on your mail.
  8. Hi Kicken and Guru Jacques, Thanks for the inputs. My SERVER API shows as Apache 2.0 Handler on my production server. I tried but could not find the file that holds the ProxyErrorOverride directive. Please enlighten. Thanks loads.
  9. Thanks Kicken for the response, I will look it up & revert if I have any further query.
  10. Hi, Just one last thing, 1. What's the mechanics of sending this page on a local server running apache. Should the page be created in the fata_error_handler.php itself or should it be created separately and redirected to it. OR is there a directive in one of the config files on the server that points to some error page by default so that there is no need to make any error page as well. By the way I am using the Amazon aws servers and the server uses Amazon Linux. I am not aware Hmmm I am not aware of this? Where can I find out about it? Kindly take some time out to revert to a query that I had sent on your personal messenger on phpfreaks. Thanks again very much.
  11. Hi Jacques, Thanks you very much. I had sent you a query on your personal messenger too. Kindly revert at your convenience. Thanks loads !!!
  12. Hi Jacques, Thanks for the last reply and I have been trying out that code snippet to understand exceptions. From This : try { $con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = "Select ID, UserLogin from test where SNo = ?"; $stmt = $con->prepare($query); $stmt->bind_param('i',$sno); if($stmt->execute()) { // throw new exception("HAHAH"); $stmt->bind_result($ID,$user); $stmt->store_result(); $stmt->fetch(); echo " WOW "; } }catch(mysqli_sql_exception $e){ echo $e->myMessage." NO GO"; } I observed that only $con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = "Select ID, UserLogin from test where SNo = ?"; $stmt = $con->prepare($query); $stmt->bind_param('i',$sno); if($stmt->execute()) this part of the code produced mysqli_sql_exceptions type exceptions. Even there the bind_param produced the error if I created a mismatch in the number of parameters. The rest of the lines $stmt->bind_result($ID,$user); $stmt->store_result(); $stmt->fetch(); did not produce any mysqli_sql_exceptions type exceptions even though it gave warnings, with display_errors directive turned on, when i deliberately added an extra parameter in bind_result or added a parameter to store_result(). I gather from this that the last 3 lines of code above would not generate an exception of type mysqli_sql_exceptions which are generated only by the other set of initial lines of code ( till and including $STMT->execute() ) and I guess those are the lines that would actually throw the true kind of mysqli_sql_exceptions that are caused by query failure due to whatever reason. Others commands simply manipulate the retrieved data. Is that correct ? Thank you very much.
  13. Hi Guru Jacques, I have another and related question on this & that is that is on extending the Exceptions class. So suppose it is wished to capture only the database related exceptions and we are using mysqli prepared statements in code which is predominantly procedural then if we subclass like class DBExceptions extends Exceptions then how can this (extending of the Exceptions class as DBExceptions) be used to catch the mysqli related exceptions in the following code where a function LC($link) is called in a try catch block and any DBExceptions are caught in the catch block. try { $verify = LC($link); $vu = true; }catch(DBException $e){ // do whatever on catching the DBException } function LC($con) { if(isset($_SESSION['id'],$_SESSION['user_id'],$_SESSION['usr'],$_SESSION['login_string'])) { $id = $_SESSION['id']; $user_id = $_SESSION['user_id']; $username = $_SESSION['usr']; $login_string = $_SESSION['login_string']; $user_browser = $_SERVER['HTTP_USER_AGENT']; $ip = $_SERVER['REMOTE_ADDR']; $query = "SELECT salt FROM loginstatus WHERE id = ? && status = 'ABA' LIMIT 1"; $stmt = $con->prepare($query); $stmt->bind_param('i',$id); $stmt->execute() $stmt->bind_result($salt); $stmt->fetch() $LC = crypt($user_browser.$id.$ip, $salt); if(isset($_SESSION['login_string']) && $_SESSION['login_string'] == $LC) { $stat = "Logged in !!"; return true; } }else return false; } Once again what I am trying to ask is that assuming the function LC() can throw any kind of exception including DBException how will the catch block know which exception is the one that is in the category of DBExceptions and catch that only? If I extend the Exceptions class as I have done above, then would I also be obliged to write some error / exception log function or would php continue to do that by itself? I wish to do the bare minimum, as advised by you and leave all the error / exception handling to php. I just want to make sure that if the exception / error is database related then the program is terminated with an appropriate friendly message on a nice page to the end user. P.S. I know the function is using a few things like HTTP_USER_AGENT & REMOTE_ADDR which you advise against but kindly overlook them since I am using this code as an example in support of my question. Thanks loads.
  14. Hi Jacques, Thanks for being so patient with me. Disabling display_errors and display_startup_errors worked exactly as you suggested. It generates an error 500 message which is caught by the error_handler and displays the custom message. It is also handling exceptions as you suggested by you. Disabling the two error messages and experimenting with errors and exceptions has given me a better insight into them. I don't profess that I know it all but still I feel that quite a few of my doubts have been cleared. WIll revert back with any more questions or queries if I have them. Thanks a lot.
  15. Hi Jacques, Thanks for the reply. Yes I am using Apache and the xampp stack. The php version that I have installed is 5.6.8. I just tried your code example in the article titled "The mystery of errors and exceptions". I deliberately inserted a parse error and got the error on the screen Parse error: syntax error, unexpected ')' in D:\xampp\htdocs\xampp\magics\index.php on line 3 If the production environment was set then it would have suppressed this message as well and would have shown a blank screen. Instead, all I want is to be able to show a simple message on a nice html page saying that an error has occurred and will be resolved soon, without divulging any technical details to the user. Since I also want to display a similar message for any run-time exceptions that may occur,do I also need to set an exceptions handler? I have used try - catch blocks around code that access the database and I want to catch database related exceptions in the catch block and retry a few times as also explained in one of your replies. I have used mysqli for the database. For any other run-time errors I simply want the exception handler to display a user friendly message before terminating the problem. Can errors and exceptions be handled using a common handler or should a simple one be written for exceptions too using a set_exception_handler function? I re-iterate that I do not wish to handle errors or exceptions any more than displaying a user friendly message to user, nor do i wish to generate any logs which the server does for us as you have already explained. I want these to be as simple as possible. Sorry if I am taking a long time understanding these. Just want to be doubly sure. Thanks again very much.
  16. HI, Would you be kind enough to explain the usage of the following two functions functions : 1. exception_handler($e) 2. set_exception_handler('exception_handler') I think they are analogous to the two functions register_shutdown_function('handle_fatal_errors') & handle_fatal_errors() Do we need to use just one set ? In case we use the exceptions_handler then what modifications would be required as has been explained for the errors' functions in your article? ( i.e. to say how would we set the auto_prepend_file directive and the fatal_error_handler.php code) Thanks loads
  17. Hi Guru Jacques, Really good to receive a reply from you. Your link seems to be a treasure on exceptions. I'll go through and revert with any questions. Thank you very much.
  18. Hi All, I have touched upon exceptions earlier. However I am still not sure if I am handling them correctly. try { ... ... ... }catch(Exception $e){ if($prod === true) // In production mode { header("Location: exceptions/errors.php") exit(); } if($dev === true) // In development mode { echo $e->getMessage(); // & if needed log the errors / exceptions into a file. exit(); } } I would like to ask if using the function header() to load the errors.php page is a good and safe practice. Or is there a better way to load the errors.php. If I load the errors page as in the snippet, do I also have to log the errors myself in some files or is php going to do that in any case. Any improvements or suggestions are welcome. Thanks all ! P.S. Googling exceptions gives loads of information but seldom does it touch the issue of loading an errors page when an exception occurs.
  19. Hi Jacques1 and Psycho. Thank you both for the inputs. Jacques1 really good to see you back after a long break !! Psycho thanks for that example. That should solve it for sure. Thanks again to both of you Gurus.
  20. Hi, So I tested a bit and i found that the array is translated into something like this : 4%2C3%2C4%2C3%20%2C4%2C3%2C4%2C3%20%2C2%2C3%2C2%2C3%20%2C3%2C3%2C3%2C3%20%2C3%2C3%2C3%2C3%20 and this is what is received in PHP. I guess this would be a long string that is received by PHP. Now then the question is how to sanitize this and such strings to ensure that they are composed of numbers, spaces and commas and maybe the - sign as well and do not have anything that could pose a security risk. Thank you all.
  21. Hi !! Thanks for that super fast response. Well I will elaborate a bit on the data. Its actually coming from flash and is stored there in an array. trys_per_minute = Array(); . . // trys_per_minute is filled with values lvv.db_trys_per_minute = trys_per_minute; // (1,2,3,4 1,1,1,1 3,2,2,1, 1,2,2,1) etc. lvv.sendAndLoad(path+"trys.php",lvInn,"POST"); // & sent as POST array to PHP Frankly I am not sure how these values will be handled in php whether as an array or as a string. Maybe you can guide me on how I should handle them on the PHP side. What I do know is that I want to add these in the DB so that I may remove them and separate them on the spaces and then use each substring as a a independent string and further explode them at the "," when I need to and extract the digits. So How may I sanitize them before I add them into the DB. I hope I am able to express myself make clearly here. Thanks very much.
  22. Hi all ! I have an array made up of strings of comma separated numbers and these strings are separated from each other by a space like this : "1,2,3,4 1,1,1,1 2,2,2,2 4,4,4,4 1,1,1 2,2,2 3,3,3 " etc. i.e. the array is made up of comma separated strings like 1,2,3,4 separated by a space and then another string 1,1,1,1. I would like to know if I can use the filter_var_array for sanitizing these strings and how? If it is not possible to use the filter_var_array then how can I sanitize the array values before inserting them into a DB. Any help is highly appreciated. Thanks all.
  23. Hi, I liked the interface but did not check it for functionality or any such thing. However I did not see a logout button anywhere when I wanted to logout. Thanks.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.