Jump to content

WatsonN

Members
  • Posts

    227
  • Joined

  • Last visited

Everything posted by WatsonN

  1. AlexWD that was exactly what it was Thanks yall
  2. I did try it and it sent me to /?p=$url instead of what the variable equals.
  3. I'm trying to put a variable in a header("Location: /?p=$url"); Is this even possible?
  4. Just change the HTML form to GET and in the PHP make sure its set to check for GET and not POST
  5. Ok, then lets help you understand. . . Do you want the image to be uploaded into the same table or a separate one?
  6. Can you post the script?
  7. Sure would
  8. to make each one expire at the end of the session setcookie(name, value, 0) or setcookie(name, value)
  9. Yes or just omit that all together
  10. If your form is posting as "image" and not "image_name" then yes use "image" And are you using GET or POST because, well he said it:
  11. <?php if(isset($_POST['playsix'])){ $dice = rand(1,6); echo "You rolled a<br /><b>{$dice}</b>\n"; $winnings = "500"; if($dice == 6){ include("haha.php"); $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase); $username = $cxn->real_escape_string($_SESSION['username']); $sql = "UPDATE `Member` SET `rp` = rp+$winnings WHERE `username` = '$username'"; mysqli_query($cxn,$sql); } } ?>
  12. Yeah, I would change that to the same as on the insert
  13. What you could do is when you set the cookie set it to expire when the session is closed
  14. <?php error_reporting(E_ALL); define('ROOT_DIR', './'); define('PROPER', TRUE); mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("eurico_edy") or die(mysql_error()); /** * include common files */ // No album id has been selected if (isset($_POST['drivers'])) { // get the image file name so we // can delete it from the server $sql = "SELECT id, image FROM driversnew WHERE id = {$_POST['drivers']}"; $result = mysql_query($sql) or die('Delete photo failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); define("GALLERY_IMG_DIR", "./images/"); // remove the image and the thumbnail from the server unlink(GALLERY_IMG_DIR . $row['image']); unlink(GALLERY_IMG_DIR . 'thumbs/' . $row['image']); // and then remove the database entry print_r($_POST); } } /////////// this where the upload script starts/////////// this where the upload script starts//////// this where the upload script starts /////////// this where the upload script starts/////////// this where the upload script starts//////// this where the upload script starts //define a maxim size for the uploaded images define ("MAX_SIZE","100"); // define the width and height for the thumbnail // note that theese dimmensions are considered the maximum dimmension and are not fixed, // because we have to keep the image ratio intact or it will be deformed define ("WIDTH","150"); define ("HEIGHT","100"); // this is the function that will create the thumbnail image from the uploaded image // the resize will be done considering the width and height defined, but without deforming the image function make_thumb($img_name,$filename,$new_w,$new_h) { //get image extension. $ext=getExtension($img_name); //creates the new image using the appropriate function from gd library if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) $src_img=imagecreatefromjpeg($img_name); if(!strcmp("png",$ext)) $src_img=imagecreatefrompng($img_name); //gets the dimmensions of the image $old_x=imageSX($src_img); $old_y=imageSY($src_img); // next we will calculate the new dimmensions for the thumbnail image // the next steps will be taken: // 1. calculate the ratio by dividing the old dimmensions with the new ones // 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable // and the height will be calculated so the image ratio will not change // 3. otherwise we will use the height ratio for the image // as a result, only one of the dimmensions will be from the fixed ones $ratio1=$old_x/$new_w; $ratio2=$old_y/$new_h; if($ratio1>$ratio2) { $thumb_w=$new_w; $thumb_h=$old_y/$ratio1; } else { $thumb_h=$new_h; $thumb_w=$old_x/$ratio2; } // we create a new image with the new dimmensions $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); // resize the big image to the new created one imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // output the created image to the file. Now we will have the thumbnail into the file named by $filename if(!strcmp("png",$ext)) imagepng($dst_img,$filename); else imagejpeg($dst_img,$filename); //destroys source and destination images. imagedestroy($dst_img); imagedestroy($src_img); } // This function reads the extension of the file. // It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } // This variable is used as a flag. The value is initialized with 0 (meaning no error found) //and it will be changed to 1 if an errro occures. If the error occures the file will not be uploaded. $errors=0; // checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; // if it is not empty if ($image) { // get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); // get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); // if it is not a known extension, we will suppose it is an error, print an error message //and will not upload the file, otherwise we continue if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { // get the size of the image in bytes // $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which the uploaded file was stored on the server $size=getimagesize($_FILES['image']['tmp_name']); $sizekb=filesize($_FILES['image']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($sizekb > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=time().'.'.$extension; //the new name will be containing the full path where will be stored (images folder) $newname="images/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); //we verify if the image has been uploaded, and print error instead if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; } else { // the new thumbnail image will be placed in images/thumbs/ folder $thumb_name='images/thumbs/'.$image_name; // call the function that will create the thumbnail. The function will get as parameters //the image name, the thumbnail name and the width and height desired for the thumbnail $thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT); }} }} //If no errors registred, print the success message and show the thumbnail image created $id = $_POST['id'] ; $name = $_POST['name']; $location = $_POST['location']; $date_of_birth = $_POST['date_of_birth']; $car_number = $_POST['car_number']; $favourite_track = $_POST['favourite_track']; $least_favourite_track = $_POST['least_favourite_track']; $achievements = $_POST['achievements']; $sponsors = $_POST['sponsors']; $email = $_POST['email']; $image = $_FILES['image']; $query = "UPDATE driversnew SET name = '$name', location = '$location', date_of_birth='$date_of_birth', car_number='$car_number', favourite_track='$favourite_track', least_favourite_track='$least_favourite_track', achievements='$achievements', sponsors='$sponsors', email='$email', image='$image' WHERE id = '$id'"; mysql_query($query); echo "<h1>Thumbnail created Successfully!</h1>"; echo '<img src="'.$thumb_name.'">'; echo ''.$name.''; echo ''.$location.''; ?> try submitting the form then check the errors
  15. Try putting error_reporting(E_ALL); and see if that gives you any information you didn't have already
  16. Are you sure the image is being uploaded?
  17. mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("name") or die(mysql_error()); $id = $_GET['id'] ; $name = $_POST['name']; $location = $_POST['location']; $date_of_birth = $_POST['date_of_birth']; $car_number = $_POST['car_number']; $favourite_track = $_POST['favourite_track']; $least_favourite_track = $_POST['least_favourite_track']; $achievements = $_POST['achievements']; $sponsors = $_POST['sponsors']; $email = $_POST['email']; $image = $_FILES['image']; $query = "UPDATE driversnew SET name = '$name', location = '$location', date_of_birth='$date_of_birth', car_number='$car_number', favourite_track='$favourite_track', least_favourite_track='$least_favourite_track', achievements='$achievements', sponsors='$sponsors', email='$email', image='$image' WHERE id = '$id'"; mysql_query($query);
  18. You have to connect to the database first: // Connects to your Database mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error());
  19. Sure thing Sorry if i confused you All you need to do is add your cookies that you need removed and change the timeout if you want too
  20. Oops, try this one. I keep it in a file called timer.php and just include to keep it simple, just an Idea <?php $error = 'Your session timed out.'; session_start(); if($_SESSION['session_count'] == 0) { $_SESSION['session_count'] = 1; $_SESSION['session_start_time']=time(); } else { $_SESSION['session_count'] = $_SESSION['session_count'] + 1; } $session_timeout = 1800; $session_duration = time() - $_SESSION['session_start_time']; if ($session_duration > $session_timeout) { session_unset(); session_destroy(); session_start(); session_regenerate_id(true); setcookie("Key_WatsonN", 0, time()-3600); setcookie("Errors", 0, time()-3600); setcookie("UID", 0, time()-3600); setcookie("PWD", 0, time()-3600); setcookie(Errors, $error, time()+120000); $_SESSION["expired"] = "yes"; header("Location: /"); // Redirect to Login Page } else { $_SESSION['session_start_time']=time(); } ?>
  21. $_SESSION['timeout'] is a var that will be stored throughout your session on the site. $_SESSION['timeout']=time() sets this to the current time. time() - $_SESSION['timeout'] is subtracting timeout from current time.
  22. Insert http://www.w3schools.com/PHP/php_mysql_insert.asp Delete http://www.w3schools.com/PHP/php_mysql_delete.asp
  23. Updated code: <?php session_start(); // 10 mins in seconds $inactive = 600; $session_life = time() - $_SESSION['timeout']; if($session_life > $inactive) { session_destroy(); header("Location: logoutpage.php"); } $_SESSION['timeout']=time(); ?>
  24. Variables that start with an underscore _ are server variables that the server sets.
  25. Sure This starts the session: session_start(); This is just telling the script how long to let them be inactive(Must be in seconds): $inactive = 600; Setting the session_life variable: $session_life = Current Unix time: time() Subtracting the current inactive time(not completely sure): - $_session['timeout'] Saying if the session life time is greater than the $inactive time: if($session_life > $inactive) Do This: Destroy the session: { session_destroy() Redirect to the logout page: header("Location: logoutpage.php"); } If not greater than $inactive: Setting session timeout to the current Unix time: S_session['timeout']=time(); -edit- fixed minor mistype -edit-
×
×
  • 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.