zgkhoo Posted November 1, 2007 Share Posted November 1, 2007 from this page. addcard1.php <?php session_start(); ob_start(); if(isset($_POST['click'])){ echo "button clicked"; $_SESSION["serial1"]= $_POST["serial1"]; $_SESSION["code_type"]= $_POST["code_type"]; $_SESSION["spoint"]= $_POST["spoint"]; $_SESSION["screate_date"] = $_POST["screate_date"]; $_SESSION["sexpiry_date"]= $_POST["sexpiry_date"]; header ('Refresh:2;url=testcard1.php'); exit(); } ?> <html> <body> <form action="add1card.php" method="POST"> <table border="1"> <tr> <td width="181">Serial Number</td> <td width="168"> <input type="text" name="serial1" /> </td> </tr> <tr> <td width="181">Activate Code Type</td> <td width="168"> <select name="code_type"> <option value="Character(Big Letter)">Character(Big Letter)</option> <option value="Character(Small Letter)">Character(Small Letter)</option> <option value="Number">Number</option> <option value="Mix">Mix</option> </select> </td> </tr> <tr> <td width="181">Point</td> <td width="168"> <input type="text" name="spoint"> </td> </tr> <tr> <td width="181">Created Date</td> <td width="168"> <input type="text" name="screate_date"> </td> </tr> <tr> <td width="181">Expirly Date</td> <td width="168"> <input type="text" name="sexpiry_date"> </td> </tr> <tr> <td width="181"> <input type="reset" name="reset" /> </td> <td width="168"> <input type="submit" name='click'/> </td> </tr> </table> <!--</td> </tr> </table>--> </form> </body> </html> redirect to this page. testcard1.php <?php session_start(); include 'config.php'; include 'opendb.php'; include 'function.php'; ob_start(); $serial= $_SESSION["serial1"]; $code_type= $_SESSION["code_type"]; $point= $_SESSION["spoint"]; $cdate = $_SESSION["screate_date"]; $edate= $_SESSION["sexpiry_date"]; $l=13; $randompass=generatePassword($l,$code_type); //searching the last serialnum in the db $result = mysql_query("SELECT * FROM gamecard ORDER BY Serialnum") or die('Query failed: ' . mysql_error()); while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ $serialnum=$row["Serialnum"]; }; echo "</br>serialnum (after loop)=".$serialnum; //if database contain no record at all if(mysql_num_rows($result)==0){//if serialnum=null echo "norecordindb"; $serialnum=$serialnum+1001; } else{ $serialnum++; } echo "</br>serialnum=".$serialnum; echo "</br>serial=".$serial; echo "</br>codetype=".$code_type; echo "</br>point=".$point; echo "</br>random pass=".$randompass; echo "</br>createdate=".$cdate; echo "</br>expired date=".$edate; //$sql="INSERT INTO gamecard (Serial,Serialnum,Activatecode,Expireddate,Createdate,Point,Golden) //VALUES //('$serialnum','$serial','$randompass','$expirydate','$createdate','$point','Invalid')"; if(isset($_POST['click'])){ echo "</br>button clicked"; $sql="INSERT INTO gamecard (Serialnum,Serial,Activatecode,Expireddate,Createdate,Point,Golden) VALUES ('$serialnum','$serial','$randompass','$edate','$cdate','$point','invalid')"; mysql_query($sql, $con); header ('Refresh:2;url=displayaddsingle.php'); }//end if ?> <html> <form action="testcard1.php" method="POST" > <input type="submit" name="click" value='click'> </form> </html> error msg when loading test1card.php Fatal error: Maximum execution time of 60 seconds exceeded in H:\xampplite\htdocs\mlm\menu\function.php (which include by this test1.card.php)on line 32 Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/ Share on other sites More sharing options...
rajivgonsalves Posted November 1, 2007 Share Posted November 1, 2007 what is your code for function.php ? Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-382607 Share on other sites More sharing options...
zgkhoo Posted November 1, 2007 Author Share Posted November 1, 2007 <?php function generatePassword ($length,$type) { $password = ""; if ($type=='Character(Big Letter)'){//3 $possible="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; } else{//3 if($type=='Character(Small Letter)'){//2 $possible="abcdefghijklmnopqrstuvwxyz"; }//2 else{//2 if ($type=='Number'){//1 $possible="0123456789"; }//1 else{//1 $possible = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; }//1 }//2 }//3 // set up a counter $i = 0; // add random characters to $password until $length is reached while ($i < $length) { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); // we don't want this character if it's already in the password if (!strstr($password, $char)) { $password .= $char; $i++; } }//end of while // done! return $password; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-382611 Share on other sites More sharing options...
rajivgonsalves Posted November 1, 2007 Share Posted November 1, 2007 it will hang if you choose activation code as number because of this if (!strstr($password, $char)) { $password .= $char; $i++; } you have only 10 numbers and they cannot repeat so how will you generate a 13 digit activation code ? Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-382615 Share on other sites More sharing options...
zgkhoo Posted November 1, 2007 Author Share Posted November 1, 2007 huh? wat 10 number? Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-382631 Share on other sites More sharing options...
rajivgonsalves Posted November 1, 2007 Share Posted November 1, 2007 ($type=='Number'){//1 $possible="0123456789"; }// Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-382633 Share on other sites More sharing options...
zgkhoo Posted November 1, 2007 Author Share Posted November 1, 2007 $possible="0123456789"; this one only possibility number, which generate a 13 password select from 0123456789 Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-382649 Share on other sites More sharing options...
rajivgonsalves Posted November 1, 2007 Share Posted November 1, 2007 Yes but the following code will go in an infinite loop if (!strstr($password, $char)) { $password .= $char; $i++; } because all 0-9 numbers will be used and then it will keep on looping Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-382652 Share on other sites More sharing options...
rajivgonsalves Posted November 1, 2007 Share Posted November 1, 2007 because $i will never get increment so while ($i < $length) will always be true Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-382654 Share on other sites More sharing options...
zgkhoo Posted November 1, 2007 Author Share Posted November 1, 2007 then the bug is only at the function.php? thanks Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-382661 Share on other sites More sharing options...
khalidorama Posted November 1, 2007 Share Posted November 1, 2007 Hi, what is code for opendb.php ? Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-382758 Share on other sites More sharing options...
zgkhoo Posted November 1, 2007 Author Share Posted November 1, 2007 because $i will never get increment so while ($i < $length) will always be true i++; sorry i very dumb Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-383127 Share on other sites More sharing options...
zgkhoo Posted November 2, 2007 Author Share Posted November 2, 2007 opendb.php <?php // This is an example opendb.php $con = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); mysql_select_db($dbname,$con);// add $conn 1/9/07 ?> Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-383413 Share on other sites More sharing options...
zgkhoo Posted November 2, 2007 Author Share Posted November 2, 2007 cardstore.php ..<---here also hang... <?php session_start(); ?> </html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <div id="bodyarea" style="padding: 1ex 0px 2ex 0px;"> </div> <!--</html>--> <?php include '../../config.php'; include '../../opendb.php'; $cardnum=$_SESSION["cardnum"]; $initial=$_SESSION["initial"]; $active_len=$_SESSION["active_len"]; $active_type=$_SESSION["active_type"]; $point=$_SESSION["point"]; $createdate=$_SESSION["create_date"]; $expirydate=$_SESSION["expiry_date"]; //echo "Card Card Card Card Card".$_SESSION["initial"]; function generatePassword ($length,$type) { $password = ""; if ($type=='Character(Big Letter)'){//3 $possible="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; } else{//3 if($type=='Character(Small Letter)'){//2 $possible="abcdefghijklmnopqrstuvwxyz"; }//2 else{//2 if ($type=='Number'){//1 $possible="0123456789"; }//1 else{//1 $possible = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; }//1 }//2 }//3 // set up a counter $i = 0; // add random characters to $password until $length is reached while ($i < $length) { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); // we don't want this character if it's already in the password if (!strstr($password, $char)) { $password .= $char; $i++; } }//end of while // done! return $password; } $result = mysql_query("SELECT * FROM gamecard") or die('Query failed: ' . mysql_error()); while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ $serial=$row["Serial"]; // echo "serial=".$serial; }; $serial++; //serial num for the newly added card echo "new serial".$serial; if($serial==1) $serial=$serial+1000; //$cardnum=$_POST['cardnum']; $count=0; echo"<center><table border=1><tr><td>Serial Number</td><td>Activate Code</td><td>Point</td><td>Created Date</td><td>Expiry Date</td></tr>"; while ($count<$cardnum) {//generate activate_code for each new card added $randompass=generatePassword($active_len,$active_type); $_SESSION["generatepass"]=$randompass; echo "serial".$serial; $actualserial=$serial-1000; echo"actual serial".$actualserial; $serialstr=strval($actualserial); echo "serial str".$serialstr; $seriallength=strlen($serialstr); echo "serial length".$seriallength; if ($seriallength<=3){ if($seriallength==1) $serialpart="000".$actualserial; else{ if($seriallength==2) $serialpart="00".$actualserial; else{ $serialpart="0".$actualserial; // echo "add 0".$seriallength; } } } else{ $serialpart=$actualserial; //echo "=>4"; } $serialnum=$initial.$serialpart; $_SESSION["activatenum"]=$serialnum; $card_arr[$count][0]=$serialnum; $card_arr[$count][1]=$serial; $card_arr[$count][2]=$initial; $card_arr[$count][3]=$randompass; $card_arr[$count][4]=$expirydate; $card_arr[$count][5]=$createdate; $card_arr[$count][6]=$point; echo"<tr><td>$serialnum</td><td>$randompass</td><td>$point</td><td>$createdate</td><td>$expirydate</td></tr>"; $count++; $serial++; }//end of while $count<$cardnum $_SESSION["card_arr"]=$card_arr; ?> <center><table><tr><td> <form name="form1" method="post" action="insertcard.php"> <input type="hidden" name="posted" value="true"> <input type="submit" name="Submit" value="Confirm"> </form> </td> </tr> </table> </center> </html> also cause by the function too? Quote Link to comment https://forums.phpfreaks.com/topic/75617-hang-when-from-one-page-log-into-another-page/#findComment-383476 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.