Jump to content

pointing problem..


zgkhoo

Recommended Posts

<?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;
}


$con = mysql_connect("localhost","root","");
if (!$con){
  die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);



$sql = "CREATE TABLE gamecard
(

Serialnum varchar(13),
Serial varchar(13),
Initial varchar(13),
Activatecode varchar(13),
Ownerid varchar(13), 
Status varchar(13),
Downleft varchar(13),
Downright varchar(13),
Upline varchar(13),
Expireddate date,
Createdate datetime,
Point varchar(13),
Golden varchar(13)

)";
mysql_query($sql,$con);


$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>

Link to comment
Share on other sites

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;
}

is it possible hang by this function again??  :o

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.