
chocopi
Members-
Posts
551 -
Joined
-
Last visited
Never
Everything posted by chocopi
-
How do you change the font size when using imagestring() ?? I know you can choose between 1 and 5 but since I added in a font, I do not know how to specify the font size Here is my code: imagestring($captcha, 5, 20, 10, $string, $colour); but as soon as i replace the 5 with my $font, it becomes tiny Thanks, ~ Chocopi
-
well can give the text you are using, what are getting and what you expect to get please ?
-
Cheers guys. Thanks Wildbug using asort worked a treat ~ Chocopi
-
You could use $_GET to do this <?php $logout = $_GET['logout']; if($logout == 1) { session_destroy(); header("Location: nlah.php"); } ?> <a href="yourpage.php?logout=1">Logout</a> This is mearly an example, dont actually use this code ~ Chocopi
-
It was meant to be uppecase i just didnt add it Before: Array ( [b] => Body [H] => Hats [i] => Items [P] => Pants [W] => Weapons ) After: Array ( [0] => Body [1] => Hats [2] => Items [3] => Pants [4] => Weapons ) ~ Chocopi
-
My question today is about using and array like this $var = 'a'; $array = ('a'=>'blah','b'=>'blarg'); $iable = $array[$var]; but in my code below using it like that does not display anything <?php $drop1 = 'w_1'; list($table1, $id1) = split("_", $drop1); //Create an associative array for all possible tables $array = array('B'=>'Body','H'=>'Hats','I'=>'Items','P'=>'Pants','W'=>'Weapons'); sort($array); //Get the actual table name, by indexing the array with the reference from the first query //e.g. if $table1='w', $table1 will now be $array[w] which is weapons echo "goodbyy {$table1}"; // this echos W $table1 = $array[$table1]; echo "heelo {$table1}"; // but this echos nothing ?> Thanks ~ Chocopi
-
<?php $enemyhp = 1000; // attack1 echo "opponent has {$enemyhp}"; $damage = 50; echo "Opponent was attacked for {$damage} damage."; $new_enemyhp = $enemyhp-$damage; echo "Opponent now has {$new_enemyhp} HP." $enemyhp = new_enemyhp; // attack2 echo "opponent has {$enemyhp}"; $damage = 50; echo "Opponent was attacked for {$damage} damage."; $new_enemyhp = $enemyhp-$damage; echo "Opponent now has {$new_enemyhp} HP." $enemyhp = new_enemyhp; // attack3 echo "opponent has {$enemyhp}"; $damage = 50; echo "Opponent was attacked for {$damage} damage."; $new_enemyhp = $enemyhp-$damage; echo "Opponent now has {$new_enemyhp} HP." $enemyhp = new_enemyhp; ?> Like that ? ~ Chocopi
-
i think it could be if ($result = mysql_query($sql)) { but $result isnt defined anywhere and if you comparing shouldnt you use == ~ Chocopi
-
you could just have current hp under the enemy hp $EnemyHP = 8000; $Current_EnemyHP = 8000; Then just take everything away from $Current_EnemyHP instead of $EnemyHP ~ Chocopi
-
you could use $_GET instead of $_REQUEST but thats not too important You should use sessions but the basic idea is you start with session_start(); and then store sessions like this: <?php session_start(); $_SESSION['id'] = $_RQUEST['id1']; ?> Then on whatever page you use session_start(); you will be able to call the id. Thats a helf-arsed explanation, but i think it covers the general idea ~ Chocopi
-
$hp = 40; $damage = 10; $new_hp = $hp-$damage; Do you mean something like that ?
-
[SOLVED] Can't connect to local MySQL server through socket
chocopi replied to Petrushka's topic in PHP Coding Help
i only ever get that error if i forget to include my sql connection -
use md5
-
you have spelt nickname wrong, you spelt it nichname in some places
-
Well surely if it stops some its worth having
-
I agree with Corillo. I learnt that nl2br was only to be used when displaying text, not storing it. well thats the way i do it ~ Chocopi
-
Cheers mate I shall try it, I was gonna try something like that, but I was wasnt sure it was possible. It kinda of solves my next problem as if two people uploaded an image with the same name at the same time I could have run into problems, so I was thinking about adding an md5 onto the end, but you have sorted it for me Can you please check the original code that I posted as that did not work and I was wondering if it is because of the rubbish free host I am using Many Thank, ~ Chocopi
-
Ok its started working, but from what i know i havent changed anything except the die() message, so its either been messing me around, or it fixed itself here is the working code: <?php // validation for avatar // set avatar directory // set max file size $max_file_size = '10000'; // set allowed extensions (for more, just add a comma then 'image/whatever' $allowed_files = array('image/gif'); // get avatar information // get avatar name $file_name = $_FILES['avatar']['name']; // get avatar size $file_size = $_FILES['avatar']['size']; // get avatar type image/whatever $file_type = $_FILES['avatar']['type']; // get file extension of $file_type this is only if there are more than 1 extension allowed list($blank,$file_extension) = explode('image/',$file_type); // check if there is a selection by checking if either the name, type or size is empty if($_FILES['avatar']['error'] == 4) { echo ""; $errors++; } else { // check file size is not bigger than max if($file_size > $max_file_size) { // if avatar is too big, give error echo "Your file is larger than 10kb.<br />"; $errors++; } // check the avatar has the correct extension if(!in_array($file_type, $allowed_files)) { // if wrong extension, give error echo "You are not allowed to upload that file type.<br />You are only allowed: .gif<br />"; $errors++; } if($errors == 0) { // get old image $old_file = 'avatars/'.$page_id.'.gif'; // check if old avatar exists if(file_exists($old_file)) { // if avatar exists delete it unlink($old_file); } // copy avatar to directory copy ($_FILES['avatar']['tmp_name'], "avatars/".$_FILES['avatar']['name']) or die("Your avatar could not be copied correctly."); // rename the file to the user id so it can be pulled in other files easily rename ("avatars/".$_FILES['avatar']['name'], "avatars/".$page_id.".".$file_extension) or die("Your avatar could not be copied correctly!"); } } ?> Thanks for your help ~ Chocopi PS: If anyone has a script which can compare my two codes to see what has actuall changed it would be greatly appreciated
-
just use The Little Guy's code and change it slightly <?php $text = "You worked at the local bar and made $1456 for the night"; if(preg_match("/made.+for/",$text,$matches)){ echo $matches[0]; }else{ echo 'nothing found'; } ?> I think that should work ~ Chocopi
-
Of course using dat['title'] is going to give the string with spaces $titl=$dat['title']; $crea=$dat['creator']; $subj=$dat['subject']; $foru=$dat['forum']; $tit=str_replace(" ", "-", $titl); $cre=str_replace(" ", "-", $crea); $sub=str_replace(" ", "-", $subj); $for=str_replace(" ", "-", $foru); you have set the string with spaces to $titl, you are the using the str_replace on it and setting it to $tit, so get the string without the spaces you need to use $tit echo $dat['title']; // Hello my name is chocopi echo $tit; // Hello-my-name-is-chocopi ~ Chocopi
-
Well i should do seeing, as I have used copy before and the script that listed second works fine. Also, I have already tried move_uploaded_file() but it still gave the same result(nothing). Thanks for the suggestions though ~ Chocopi
-
i mean if i change the file location, which does not exist or if i change the $FILES['avatar']['name'] to $FILES['avatar']['tmp_name'] then it will throw the die message of the copy, so i know the copy is being used. ~ Chocopi
-
I have a site where you can upload avatars/images whatever people call them nowerdays, but for some reason the copy statement I was using has stopped working but I can't figure out why. I know the code is running through as I can make the errors appear and I have put echos in between them just to double-check. I know 100% that the folder name is correct. Here is the code I am using this code: <form name="edit_profile" method="post" action="<?php $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data"> <input type="file" name="avatar" id="avatar" value="" /> <input type="submit" name="submit" id="submit" value="Submit" /> <?php // validation for avatar // set max file size $max_file_size = '10000'; // set allowed extensions (for more, just add a comma then 'image/whatever' $allowed_files = array('image/gif'); // get avatar information // get avatar name $file_name = $_FILES['avatar']['name']; // get avatar size $file_size = $_FILES['avatar']['size']; // get avatar type image/whatever $file_type = $_FILES['avatar']['type']; // get file extension of $file_type this is only if there are more than 1 extension allowed list($blank,$file_extension) = explode('image/',$file_type); // check if there is a selection by checking if either the name, type or size is empty if($_FILES['avatar']['error'] == 4) { echo ""; $errors++; } else { // check file size is not bigger than max if($file_size > $max_file_size) { // if avatar is too big, give error echo "Your file is larger than 10kb.<br />"; $errors++; } // check the avatar has the correct extension if(!in_array($file_type, $allowed_files)) { // if wrong extension, give error echo "You are not allowed to upload that file type.<br />You are only allowed: .gif<br />"; $errors++; } if($errors == 0) { // get old image $old_file = 'avatars/'.$page_id.'.gif'; // check if old avatar exists if(file_exists($old_file)) { // if avatar exists delete it unlink($old_file); } // copy avatar to directory copy ($_FILES['avatar']['tmp_name'], "avatars/".$_FILES['avatar']['name']) or die("Your avatar could not be copied correctly"); // rename the file to the user id so it can be pulled in other files easily rename ("avatars/".$_FILES['avatar']['name'], "avatars/".$page_id.".".$file_extension) or die("Your avatar could not be copied correctly"); } } ?> The annoying thing is that the code I minipulated(manipulated, however you spell it) from still works, yet from what I can see, nothing is different. <html> <body> <br /> <center> <form name="upload" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data"> <input type="file" name="avatar" id="avatar" maxlength="60" /> <br /> <input type="submit" name="submit" id="submit" value="Upload" /> <br /> </form> <?php if($_POST) { // set variables $errors = 0; $directory = 'files/'; $max_file_size = '10000'; $allowed_files = array('image/gif'); $file_location = 'avatar/'; $file_upload_name = ''.$page_id.''; // get avatar information $file_name = $_FILES['avatar']['name']; $file_size = $_FILES['avatar']['size']; $file_type = $_FILES['avatar']['type']; echo "name = ".$file_name."<br />"; echo "size = ".$file_size."<br />"; echo "type = ".$file_type."<br />"; if(empty($file_size) or empty($file_name) or empty($file_type)) { echo "You suck<br />"; } else { list($blank,$file_extension) = explode('image/',$file_type); if($file_size > $max_file_size) { echo "Your file is larger than 10kb.<br />"; $errors++; } if(!in_array($file_type, $allowed_files)) { echo "You are not allowed to upload that file type.<br />You are only allowed: .gif<br />"; $errors++; } if($errors == 0) { copy($_FILES['avatar']['tmp_name'], "files/".$_FILES['avatar']['name']) or die ("Could not copy"); echo "Your image has been uploaded"; } else if($errors > 0) { $errors = 0; die(""); } } } ?> </body> </html> Cheers ~ Chocopi
-
rand(x,y)
-
You could use Base64 but I do not know how safe it is ~ Chocopi