Jump to content
Larry Ullman's Book Forums

Pejman Ghasemi

Members
  • Posts

    6
  • Joined

  • Last visited

  • Days Won

    1

Pejman Ghasemi last won the day on August 22 2011

Pejman Ghasemi had the most liked content!

Pejman Ghasemi's Achievements

Newbie

Newbie (1/14)

2

Reputation

  1. Hello Mr.Larry Ullman, I would appreciate of you. I suggested your books to many of my friends. I hope you keep writing new books and release them. I know may this ask is not related to the topic but PHP is not Satisfactory to create a web page. because as you said PHP is a server-side programming language. And We can not decorate our website in client-side. So there is another language beside the is called Java Script. Do you have a good resource that we study javascript. Regards.
  2. Hi, Actually I have some questions in this topics that are still unanswered. First: I have not understood yet, why trim() should be apply for password. As I understand, trim a string is something like: $p=" t!=1 "; trim ($p); echo $p; // This line will print "t!=1" It removes spaces before and after. But as I know we always use spaces to make our password stronger. And my final question what is the problem with my script that has not worked yet. I have not found syntactical problem but maybe I have logical. Thank you very much.
  3. Hello Bahaa, To understand more about some unfamiliar calendars, First of all I introduce them Two different calendars use as formal calendar in middle-east : First : Lunar-Calendar(Hijri) - it uses by Muslims and Arabic countries. (As i write this post the lunar calendar is 1432,09,21) Second: Sun-Calendar(Jalali) - it uses by Persian language countries like Iran, Turkmenistan, Afghanistan and other persian language countries.... (1390,05,31) And other one is from China: Third : Chinese Lunar Calendar - it used by Chinese people however maybe a little hard and I do not understand it but this year of Rabbit. (100,07,23) I found a Gregorian Calender to Lunar Calendar converter is written by Tayeb Habib and source from www.redacacia.wordpress.com, email: tayeb.habib@gmail.com 021 // obtain month, today date etc 022 $month = (isset($month)) ? $month : date("n",time()); 023 $monthnames = array("January","February","March","April","May","June","July","August","September","October","November","December"); 024 $textmonth = $monthnames[$month - 1]; 025 $year = (isset($year)) ? $year : date("Y",time()); 026 $today = (isset($today))? $today : date("j", time()); 027 $today = ($month == date("n",time())) ? $today : 32; 028 029 // The Names of Hijri months 030 $mname = array("Muharram","Safar","Rabi'ul Awal","Rabi'ul Akhir","Jamadil Awal","Jamadil Akhir","Rajab","Sha'ban","Ramadhan","Shawwal","Zul Qida","Zul Hijja"); 031 // End of the names of Hijri months 032 033 // Setting how many days each month has 034 if ( (($month <8 ) && ($month % 2 == 1)) || (($month > 7) && ($month % 2 == 035 0)) ) $days = 31; 036 if ( (($month <8 ) && ($month % 2 == 0)) || (($month > 7) && ($month % 2 == 037 1)) ) 038 $days = 30; 039 040 //checking leap year to adjust february days 041 if ($month == 2) 042 $days = (date("L",time())) ? 29 : 28; 043 044 $dayone = date("w",mktime(1,1,1,$month,1,$year)); 045 $daylast = date("w",mktime(1,1,1,$month,$days,$year)); 046 $middleday = intval(($days-1)/2); 047 048 //checking the hijri month on beginning of gregorian calendar 049 $date_hijri = date("$year-$month-1"); 050 list ($HDays, $HMonths, $HYear) = Hijri($date_hijri); 051 $smon_hijridone = $mname[$HMonths-1]; 052 $syear_hijridone = $HYear; 053 054 //checking the hijri month on end of gregorian calendar 055 $date_hijri = date("$year-$month-$days"); 056 list ($HDays, $HMonths, $HYear) = Hijri($date_hijri); 057 $smon_hijridlast = $mname[$HMonths-1]; 058 $syear_hijridlast = $HYear; 059 //checking the hijri month on middle of gregorian calendar 060 $date_hijri = date("$year-$month-$middleday"); 061 list ($HDays, $HMonths, $HYear) = Hijri($date_hijri); 062 $smon_hijridmiddle = $mname[$HMonths-1]; 063 $syear_hijridmiddle = $HYear; 064 065 // checking if there's a span of a year 066 if ($syear_hijridone == $syear_hijridlast) { 067 $syear_hijridone = ""; 068 } 069 070 //checking if span of month is only one or two or three hijri months 071 if (($smon_hijridone == $smon_hijridmiddle) AND ($smon_hijridmiddle == $smon_hijridlast)) { 072 $smon_hijri = "<font color=red>".$smon_hijridone." ".$syear_hijridlast."</font>"; 073 } 074 075 if (($smon_hijridone == $smon_hijridmiddle) AND ($smon_hijridmiddle != $smon_hijridlast)) { 076 $smon_hijri = "<font color=red>".$smon_hijridone." ".$syear_hijridone."-".$smon_hijridlast." ".$syear_hijridlast."</font>"; 077 } 078 if (($smon_hijridone != $smon_hijridmiddle) AND ($smon_hijridmiddle == $smon_hijridlast)) { 079 $smon_hijri = "<font color=red>".$smon_hijridone." ".$syear_hijridone."-".$smon_hijridlast." ".$syear_hijridlast."</font>"; 080 } 081 082 if (($smon_hijridone != $smon_hijridmiddle) AND ($smon_hijridmiddle != $smon_hijridlast)) { 083 $smon_hijri = "<font color=red>".$smon_hijridone." ".$syear_hijridone."-"."-".$smon_hijridmiddle."-".$smon_hijridlast." ".$syear_hijridlast."</font>"; 084 } 085 ?> I hope it is useful article.
  4. Hello Zanimation, I put the registrar data into database and modifier file included line below: Register.php <div id="content"> <?php $errorys = array(); if (isset($_POST['Submitted'])) { $errors = array(); // put errors into an array // Validate first name if (empty($_POST['first_name'])){ $errors[] = 'Please enter first name'; }else{ $fn = trim($_POST['first_name']); } // Validate Last Name if (empty($_POST['last_name'])){ $errors[] = 'Please enter last name'; }else{ $ln = trim($_POST['last_name']); } // Validate email address if (empty($_POST['email'])){ $errors[] = 'Please fill email address'; }else{ $e = trim($_POST['email']); } // Validate password to enter both verification and main password if (!empty($_POST['password']) && !empty($_POST['verification_password'])){ // Validate that passwords are matched or not if ($_POST['password']==$_POST['verification_password']){ $p = trim($_POST['password']); }else{ $errors[] = 'Passwords are mismatched'; } }else{ $errors[] = 'Passwords has not entered yet'; } if(empty($errors)){ //check for errors //connect to db require_once('includes/db.php'); // make query $q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW())"; $r = @mysqli_query ($dbc,$q); //run mysql query if ($r) { //if it worked properly echo "Thank you, Mr.$ln, your registration done successfully"; //print success message } else{ //if it did not work properly echo "An unknown error occured please contact admin if this error persist"; //error message } }else{ // if errors occured show errors; foreach($errors as $msg){ echo " - $msg <br/>\n"; } echo '<p>please try again.</p>'; } } ?> <form method="Post" action="register.php"> <br/><br/>First Name: <input type="text" name="first_name" value="<?php if(isset($_POST['first_name'])) {echo $_POST['first_name']; }?>" /> <br/><br/> Last Name: <input type="text" name="last_name" value="<?php if(isset($_POST['last_name'])) {echo $_POST['last_name']; }?>" /> <br/><br/> Email: <input type="text" name="email" size="40" value="<?php if(isset($_POST['email'])) {echo $_POST['email']; }?>" /> <br/><br/> Password: <input type="password" name="password" /> <br/><br/> Verify Password: <input type="password" name="verification_password" /> <br/><br/> <input type="hidden" name="submitted" value="1" /> <input type="submit" value="submit" /> <br/> </form> </div> Change password file ,password.php: <?php require_once('includes/db.php'); //Connect to Database $errors = array(); if (isset($_POST['submitted'])){ //Check if form is submitted if (empty($_POST['email'])){ //check if email is empty $errors[] = 'Please enter your email.'; }else{ //else of check if email is empty $e = mysqli_real_escape_string ($dbc,trim($_POST['email'])); }//end of check if email is empty if (empty($_POST['password'])){ //check if password is empty $errors[]= 'Please enter your current password.'; }else{ //else of check if email is empty $cp = mysqli_real_escape_string($dbc,trim($_POST['password'])); }//end of check if email is empty if (empty($_POST['password2'])){ //check if new password is empty $errors[]= 'Please enter your new password.'; }else{ //else of check if new password is empty if ($_POST['password2'] != $_POST['confirm_password2']){ //check if the both confirm password and new passord matched. $errors[] = 'Confirmation password is mismatched.'; }else{ //else of check if the both confirm password and new passord matched. $np = mysqli_real_escape_string($dbc,trim($_POST['password2'])); }//end of check if the both confirm password and new passord matched. }//end of check if new password is empty if(empty($errors)){ //check if proccess run with no error. $q = "SELECT user_id FROM users WHERE (email='$e' AND pass=SHA1('$cp'))"; $r = @mysqli_query($dbc,$q); $num = @mysqli_num_rows($r); if ($num==1){ //check if there is any email and the password matched //Receive user_id data $row = mysqli_fetch_array($r,MYSQLI_NUM); //Make update query $q = "UPDATE users SET pass=SHA1('$np') WHERE user_id=$row[0]"; $r = @mysqli_query($dbc,$q); if (mysqli_affected_rows($dbc)==1){ //if update ran ok... echo '<h1>Thank you</h1>'; echo '<p>Your password changed.</p>'; }else{ //else of if update ran ok... echo "mysqli_error('$dbc')": echo '<h1>Error</h1>'; echo '<p>Sorry we faced an unknown error system Please try again.</p>'; } //end of if update ran ok... }else{ //else of check if there is any email and the password matched echo '<h1>Error</h1>'; echo '<p>Sorry we could not find such entered details.</p>'; }//end of check if there is any email and the password matched }else{ //else of check if proccess run with no error. echo '<p>We encounter below errors:<br/>\n</p>'; foreach ($errors as $msg){ //Print occured errors. echo "<p> -$msg</p>"; } echo '<p>please try again.</p>'; } //end of check if proccess run with no error. }//Check if form is submitted or not ?> And even I describe user table below: Field - Type -Key -Extra information (user_id) - mediumint(8) unsigned - NOT NULL - PRIMARY KEY - AUTO INCREMENT (first_name) - varchar(20) - NOT NULL (last_name) - varchar(40) - NOT NULL (email) - varchar(60) - NOT NULL (pass) - char(40) - NOT NULL (registration_date) - datetime - NOT NULL At the end I want to thank you very much. and sorry for bad writing models because i am a novice in programming language and i do not know where should i put spaces or comments.
  5. Hi and thank you Zanimation and Stuart. Finally I could understand what is the problem. There was a wrong with SHA1. I removed the condition of AND in this line: $q = "SELECT user_id FROM users WHERE (email='$e' AND pass=SHA1('$cp'))"; Changed to: $q = "SELECT user_id FROM users WHERE email='$e'"; I was able to run step 2 successfully. I think I need to trim($cp) and trim($np) to give me the best result. But i do not understand why trim() should be apply for password. As I understand, trim a string like: $p=" t!=1 "; trim ($p); echo $p; // This line will print "t!=1" It removes spaces before and after. But as I know we always use spaces to make our password stronger. I will be happy to answer this question too. Thank you very much Pejman
  6. Hello, My name is Pejman Ghasemi. first of all I want to thanks Mr.Larry Ullman. PHP 6 AND MYSQL5 is the best book I have ever read. I never could understand the example and explanation of other books but this one is easy and useful. Unfortunately Whole Today I worked on script 8.3 to run it but have not run it yet. so i decided to ask you help me. require_once('includes/db.php'); $e= "test"; $cp = 'test'; $np = 'pejman'; $q = "SELECT user_id FROM users WHERE (email='$e' AND pass=SHA1('$cp'))"; $r = mysqli_query($dbc,$q); $num = mysqli_num_rows($r); echo 'step1'; if ($num == 1){ //check if there is any email and the password matched echo 'step2'; //Receive user_id data $row = mysqli_fetch_array($r,MYSQLI_NUM); echo $row[0]; //Make update query $q = "UPDATE users SET pass=SHA1('$np') WHERE user_id=$row[0]"; $r = mysqli_query($dbc,$q); if (mysqli_affected_rows($dbc)==1){ //if update ran ok... echo '<h1>Thank you</h1>'; echo '<p>Your password changed.</p>'; }else{ //else of if update ran ok... echo '<h1>Error</h1>'; echo '<p>Sorry we faced an unknown error system Please try again.</p>'; } //end of if update ran ok... }else{ echo 'step3'; } I put echo 'steps' to know which step is work properly. by changing parameters to wrong data i see step 1 and step 3 but i have never seen step 2.... Please help me . Thank you very much.
×
×
  • Create New...