Jump to content

Ninjakreborn

Members
  • Posts

    3,922
  • Joined

  • Last visited

Everything posted by Ninjakreborn

  1. I figured out finally it was working it was just Google Chrome/Canary issues. I am unsure why, but they sometimes have Cache issues. I guess they are finally starting to get in the way.
  2. <?php session_start(); setcookie("user_id", "", time()-3600, "/", "www.mystagingsite1.net"); setcookie("territory", "", time()-3600, "/", "www.mystagingsite1.net"); setcookie("membership_level", "", time()-3600, "/", "www.mystagingsite1.net"); session_destroy(); header("Location: gateway.php"); ?> I am setting them using set cookie like: <?php setcookie("user_id", $row['user_id'], time()+3600, "/", "www.mystagingsite1.net"); setcookie("territory", $row['territory'], time()+3600, "/", "www.mystagingsite1.net"); setcookie("membership_level", $row['membership_level'], time()+3600, "/", "www.mystagingsite1.net"); ?> This is not deleting cookies. It should be. If I do this and it redirects me then I revisit the homepage, I am still logged in even after doing this. I have tried doing this in about 20 different ways and these stupid sessions won't die. I even tried unsetting them manually as well, nothing is working. Advice?
  3. Hehe, yes I think I will start doing that. I don't use cookies that often, but because of certain client requirements I am having to use them a lot more, so I will probably start doing it a little differently from now on.
  4. hehe, I understand what you mean now. It would help a lot if I set the .com to .net instead, I am guessing that was an issue there. OK, so that got the basic cookie working. So now at least I have verified that the cookies are working on my server. However, there is still something strange when I try to set them in a live environment (meaning in the actual working code. However, I just went back and retested and it seems there working now. So it must have been that issue. There might have been some other issues with how I was doing the time. It seems to all be working now, thanks again.
  5. I am not sure what you mean? The only thing I gather from what your saying is I would need to replace the ".mystagingsite1.net to "www.mystagingsite1.net" but I tried that and it doesn't work either. Also, according to the documentations the . acts like a wildcard when setting the cookie. So it's the base domain. So using ".mystagingsite1.net" should work whether the website domain is www.mystagingsite1.net or mystagingsite1.net. It's even recommended to show it without the www at the start. Is that what you meant? Either way it doesn't work, as that was one of the first things I tried.
  6. I am testing this entire thing on a production server. I am confused as to why it's not working though, because I have done this before many times with no issues. If I do the basic test I can access it using $_REQUEST even after browser close, but not in $_COOKIE. Also when I have it in the actual login script and set 2-3 cookies none of them are saving for some reason. I have never had this kind of issue before.
  7. Another question. I just found out it is available under $_REQUEST but not $_COOKIE that is strange. Is there a reason it's working like that? Am I doing something wrong in setting it? However, request even only works in a test environment. When I try to put this into a script as just basic it's not saving the session data. Is there something I am doing wrong?
  8. test.php <?php setcookie("test", 'tester', time()+3600*24*30 , "/", ".mystagingsite1.com"); header('Location: test2.php'); ?> test2.php <?php echo '<pre>'; print_r($_COOKIE); echo '</pre>'; ?> This does not work. It's not setting the cookie at all. Is there something I am doing wrong here?
  9. I also tried: <?php error_reporting(E_ALL & ~E_NOTICE | E_STRICT); ?> This seems to work. The logic for this should be "Show E_ALL. Don't show E_NOTICE. Also show E_STRICT" Is this correct?
  10. I have been working on this awhile (the perfect PHP error handling for my coding style). I have tried to set it up as: <?php error_reporting(E_ALL & E_STRICT & ~(E_NOTICE)); ?> I want this to show me E_ALL errors, E_STRICT errors, and NOT show me E_NOTICE. Is this the right way to set that up, or am I doing something wrong. I haven't used E_STRICT before but I am anxious to see what kind of errors that have it showing since I haven't messed with it before. Thanks again.
  11. Which one is better for standards practices in PHP. 1. Using the same form for everything. (Add and edit). Meaning setting up one form to handle adding new records, as well as editing existing records. Or 2. Using two different forms for both actions. Use one form/area to handle Adding, and one form/area to handle editing. Which one of these are better from a standards/practice point of a view. Which one better fits into the MVC platform (a framework like Codeignitor, or Cake). Should their be separate controller functions/views for add and edit or should they all be in the same controller function/form. Thanks for the feedback.
  12. I am not sure why but it wasn't able to step out of the folder (../assets) I had to do (./assets) instead and it started working. Thanks.
  13. I can't seem to get this file system to upload. It's returning an error about directory not writable. I have also verified it's 777 on the server, so I know permissions are right. File Class <?php /** * Uploader is a file transfer class. it can upload files and images. * It also can resize and crop images. * Works on PHP 5 * @author Alaa Al-Hussein * @link http://www.freelancer-id.com/projects * @version 1.0 * */ class uploader{ /** * Array, The file object as $_FILES['element']. * String, file location. */ public $source; /** * Destination file location as folder. */ public $destDir; /** * Directory for Resized images. */ public $resizeDir; /** * Directory for Cropped images. */ public $cropDir; /** * stores information for uploading file */ private $info = ''; /** * Enabling autoName will generate an auto file name for the uploaded file. */ public $generateAutoName = true; /** * Handles the error when it occurs. */ private $errorMsg = ''; /** * new width for resizing and cropping. */ public $newWidth; /** * new height for resizing and cropping. */ public $newHeight; /** * TOP postion to cropping image. */ public $top = 0; /** * LEFT position for cropping image. */ public $left = 0; /** * JPG quality (0 - 100). used for image resizing or cropping. */ public $quality = 60; public function __construct(){ //nothing } /** * Uploads the file to the server. * @param Array $_FILES[] */ public function upload($source){ if($source != ""){ $this->source = $source; } if(is_array($this->source)){ if($this->fileExists()){ return false; } // Check for auto-name generation. If it's set then generate the name automatically. if ($this->generateAutoName == true) { $this->autoName(); } return $this->copyFile(); } else { return $this->source; } } /** * return the error messages. * @return String messages. */ public function getError(){ return $this->errorMsg; } /** * Get uploading information. */ public function getInfo(){ return $this->info; } /** * Auto Name */ private function autoName() { $num = rand(0, 2000000); $num2 = rand(0, 2000000); $this->source['name'] = $num . $num2 . $this->source['name']; return $this->source; } /** * Get Image Sizes * Returns an array of variables pertaining to properties of the image. * USE THIS ON IMAGES ONLY */ public function getImageSize() { // Get the size information of the provided image. $image_size = getimagesize($this->getTemp()); // Setup the height/width so they can be returned in a readable format $return_array['width'] = $image_size[0]; $return_array['height'] = $image_size[1]; // Return the array of new data. return $return_array; } /** * Copy the uploaded file to destination. */ private function copyFile(){ if(!$this->isWritable()){ $this->errorMsg .= '<div>Error, the directory: ('.$this->destDir.') is not writable. Please fix the permission to be able to upload.</div>'; return false; } if(copy($this->source['tmp_name'],$this->destDir . $this->source['name'])){ // Done. $this->info .= '<div>file was uploaded successfully.</div>'; } else { $this->errorMsg .= '<div>Error, the file was not uploaded correctly because of an internal error. Please try again, if you see this message again, please contact web admin.</div>'; } } /** * Checks if the file was uploaded. * @return boolean */ private function uploaded(){ if($this->source['tmp_name']=="" || $this->source['error'] !=0){ $this->errorMsg .= '<div>Error, file was not uploaded to the server. Please try again.</div>'; return false; } else return true; } /** * Prepares the directory. */ private function preDir(){ if($this->destDir!="" && substr($this->destDir, -1,1) != "/"){ $this->destDir = $this->destDir . '/'; } if($this->resizeDir!="" && substr($this->resizeDir, -1,1) != "/"){ $this->destDir = $this->resizeDir . '/'; } if($this->cropDir!="" && substr($this->cropDir, -1,1) != "/"){ $this->destDir = $this->cropDir . '/'; } } /** * Check if the folder is writable or not. * @return boolean */ private function isWritable(){ $err = false; if(!is_writeable($this->destDir) && $this->destDir!=""){ $this->errorMsg .= '<div>Error, the directory ('.$this->destDir.') is not writeable. File could not be uploaded.</div>'; $err = true; } if(!is_writeable($this->resizeDir) && $this->resizeDir!=""){ $this->errorMsg .= '<div>Error, the directory ('.$this->resizeDir.') is not writeable. File could not be resized.</div>'; $err = true; } if(!is_writeable($this->cropDir) && $this->cropDir!=""){ $this->errorMsg .= '<div>Error, the directory ('.$this->cropDir.') is not writeable. File could not be cropped.</div>'; $err = true; } if($err == true){ return false; } else { return true; } } /** * Checks if the file exists on the server * @return boolean */ private function fileExists(){ $this->preDir(); if(file_exists($this->destDir.$this->source)){ $this->errorMsg .= '<div>Upload error because file already exists.</div>'; return true; } else { return false; } } /** /586742130./8532 Crops image. * @return String fileName or False on error */ public function crop($file='',$width='',$height='',$top='',$left=''){ if($file!=""){ $this->source = $file;} if ($width != '') $this->newWidth = $width; if ($height != '') $this->newHeight = $height; if ($top != '') $this->top = $top; if ($left != '') $this->left = $left; return $this->_resize_crop(true); } /** * Resizes an image. * @return String fileName or False on error */ public function resize($file='',$width='',$height=''){ if($file!=""){ $this->source = $file; } if($width != '') $this->newWidth = $width; if($height != '') $this->newHeight = $height; return $this->_resize_crop(false); } /** * Get the Temp file location for the file. * If the Source was a file location, it returns the same file location. * @return String Temp File Location */ private function getTemp(){ if(is_array($this->source)){ return $this->source['tmp_name']; } else { return $this->source; } } /** * Get the File location. * If the source was a file location, it returns the same file location. * @return String File Location */ private function getFile(){ if(is_array($this->source)){ return $this->source['name']; } else { return $this->source; } } /** * Resize or crop- the image. * @param boolean $crop * @return String fileName False on error */ private function _resize_crop ($crop) { $ext = explode(".",$this->getFile()); $ext = strtolower(end($ext)); list($width, $height) = getimagesize($this->getTemp()); if(!$crop){ $ratio = $width/$height; if ($this->newWidth/$this->newHeight > $ratio) { $this->newWidth = $this->newHeight*$ratio; } else { $this->newHeight = $this->newWidth/$ratio; } } $normal = imagecreatetruecolor($this->newWidth, $this->newHeight); if($ext == "jpg") { $src = imagecreatefromjpeg($this->getTemp()); } else if($ext == "gif") { $src = imagecreatefromgif ($this->getTemp()); } else if($ext == "png") { $src = imagecreatefrompng ($this->getTemp()); } if($crop){ //$pre = 'part_'; //We want to overwrite file, so comment this out. if(imagecopy($normal, $src, 0, 0, $this->top, $this->left, $this->newWidth, $this->newHeight)){ $this->info .= '<div>image was cropped and saved.</div>'; } $dir = $this->cropDir; } else { //$pre = 'thumb_'; //We want to overwrite file, so comment this out. if(imagecopyresampled($normal, $src, 0, 0, 0, 0, $this->newWidth, $this->newHeight, $width, $height)){ $this->info .= '<div>image was resized and saved.</div>'; } $dir = $this->resizeDir; } if($ext == "jpg" || $ext == "jpeg") { imagejpeg($normal, $dir . $pre . $this->getFile(), $this->quality); } else if($ext == "gif") { imagegif ($normal, $dir . $pre . $this->getFile()); } else if($ext == "png") { imagepng ($normal, $dir . $pre . $this->getFile(),0); } imagedestroy($src); return $src; } } /* Examples Section */ /* Let me explain first how to manage an image to be uploaded and then to be cropped or resized. <?php $uploader = new uploader(); // Setting properties then Uploading the image $uploader->source = $_FILES['field_image']; $uploader->destDir = "images/"; $uploader->upload(); // ===================== // Or you may use this too $uploader->destDir = "images/"; $uploader->upload($_FILES['field_image']); ?> Note: upload() returns the file name uploaded. To get error messages, use this code: <?php echo $uploader->getError(); // This function will return all errors occured while uploading the image. But it's not printing it to print it where ever you want. ?> And to get Information messages use this code: <?php echo $uploader->getInfo(); // This function will return all information to let the user print it where ever he wants. ?> After uploading this image, we may resize it. To do that use the following code: <?php $uploader->newWidth = 75; // in Pexels. $uploader->newHeight = 75; $uploader->resizeDir = "images/resized/"; $uploader->resize(); ?> You may also use this syntax: <?php // $uploader->resize($file,$width,$height); // $file could has a value of "" (nothing), in this case we use the last uploader file. // if the $file has a String value (file url) it will resize this new file. $uploader->resizeDir = "images/resized/"; $uploader->resize('',75,75); // Or you may upload and resize in the same line: $uploader->resizeDir = "images/resized/"; $uploader->resize($uploader->upload(),75,75); ?> Crop this image after uploading it: <?php $uploader->cropDir = "images/cropped/"; $uploader->newWidth = 75; $uploader->newHeight = 75; $uploader->top = 20; // Default is ZERO.. This used to set the cropping top location from the original image. $uploader->left = 40; // Default is ZERO.. This used to set the cropping left location from the original image. $uploader->crop(); // You may also use this: // $uploader->crop($file,$width,$height,$top,$left); $uploader->cropDir = "images/cropped/"; $uploader->crop('',75,75,20,40); ?> */ ?> Upload Function <?php /* END STANDARD FUNCTIONS */ /* General function to deal with image uploads site_wide. */ function upload_image($file, $dir, $table, $fieldname, $id, $exists, &$data) { // Get image information if ($file['tmp_name'] != '' && $file['name'] != '') { if ($exists == 1) { // Delete Associated Image $imageSQL = "SELECT " . $fieldname . " FROM " . $table . " WHERE product_id = '" . $id . "'"; $imageQuery = mysql_query($imageSQL); while($row = mysql_fetch_array($imageQuery, MYSQL_ASSOC)) { if ($row[$fieldname] != '') { $tmpdirectory = '../assets/' . $dir . '/'.$row[$fieldname]; if (file_exists($tmpdirectory)) { unlink($tmpdirectory); } } } } $directory = '../assets/' . $dir . '/'; // Default DIR // Upload $uploader = new uploader; $uploader->destDir = $directory; $uploader->generateAutoName = true; $file_name = $uploader->upload($file); $image_sizes = $uploader->getImageSize(); echo $uploader->getInfo(); } // Check if image was uploaded and if so database name. if ($uploader->source['name'] != '') { $data[$fieldname] = $uploader->source['name']; }else { if ($exists == 1) { $tmpSelect = "SELECT " . $fieldname . " FROM " . $table . " WHERE product_id = '".$id."'"; $tmpQuery = mysql_query($tmpSelect); if ($row = mysql_fetch_array($tmpQuery, MYSQL_ASSOC)) { $data[$fieldname] = $row[$fieldname]; }else { $data[$fieldname] = NULL; } }else { $data[$fieldname] = NULL; } } } ?> Code to call function <?php // Upload all images $picture_1 = $_FILES['picture_one']; if ($picture_1['tmp_name'] != '' && $picture_1['name'] != '') { $functions->upload_image($picture_1, 'product_pictures', 'products', 'picture_1', $product_id, $exists, &$data); } ?> At this point I have done all of the debugging I can and it's not working out. Any advice is appreciated.
  14. Just run str_replace for '/n', '/r', '<br />' and ' '. So take your string and run it through str_replace 3 times to clear out all of the things that would add whitespace.
  15. Get the ID # in a variable. Get the value in another variable (via the database) and then run an str_replace on the string. It's the fastest method for simple find/replace logic. So basically take the ID and hit the database to get the value. Have the id as $find_id $replace_value (holding the DB value you wanted to replace the ID with). Then run an str_replace. Only use regex if you have an advanced pattern you have to match with.
  16. I have a file called email_cron.php. I have verified that when I load this page in a browser it works fine. I have it doing some email sending, then sending a master email to a specific email address saying what emails were sent. This is an update script for a website to give them notices every day. Regardless, I tested the script itself out and it works perfectly when ran normally. I had setup a cron for this. I thought the cron was working but it's been 3-4-5 days and they have had no emails. If I go in and test the script manually it works but the cron isn't doing something. I am using 1and1.com for the hosting by the way. So I went back into the SSH and typed "crontab -l" and mine is listed. It is marked as 50 * * * * /kunden/usr/local/bin/php /kunden/homepages/##/#######/htdocs/email_cron.php Replace the # with the id's of my site. Which are the path structure. For some reason this isn't working. It shows this when I listed out so I know it's setup as a cron but for some reason it's not running. Did the code I use to set this up not structured right (the 50 * * * * ) part of it or something? I wanted it to run 1 time per day. Thanks again.
  17. "/^[0-9]{1,2}\-\[0-9]{1,2}\-\[0-9]{4}$/" How can I make this check for mm/dd/yy instead of mm-dd-yy like it is now? I just need it to check for / instead of the - symbols. Thanks.
  18. All I have been able to verify is that when the registered headline is checked then the other is always defaulting to "no" and if it isn't it works fine. Any advice here?
  19. The no_enddate. When it's checked it should hide the end date field and disable it. When it's not checked it shouldn't. This was working fine. Now all of a sudden I added "registered_headline". If that checkbox is checked then the stuff for no_enddate doesn't work. If it isn't checked, then it continues to work fine. Any advice? <label for="registered_headline">Only show to registered users:</label><input name="registered_headline" <?php if ($registered_headline == 1) { echo 'checked="checked"'; } ?> type="checkbox" class="checkbx" /> </fieldset> <fieldset class="choosedates"><legend>Run Dates</legend> <label for="start_date"><span style="color:red;">*</span>Start Date:</label><br/><input name="start_date" id="start_date" class="date_pick" type="text" value="<?php echo $start_date; ?>" /><br /> <br/><label for="no_enddate"><strong>Run Promotion continuously with no end date?</strong></label> <script type="text/javascript"> $(document).ready(function() { if ($("input[@name='no_enddate']:checked").val() == 'yes') { $('#end_date').attr('disabled', 'disabled'); $('.end_date').hide(); }else { $('#end_date').attr('disabled', ''); $('.end_date').show(); } $('.enddatecheck').click(function() { if ($("input[@name='no_enddate']:checked").val() == 'yes') { $('#end_date').attr('disabled', 'disabled'); $('.end_date').hide(); }else { $('#end_date').attr('disabled', ''); $('.end_date').show(); } }); }); </script> <?php if ($no_enddate == 1) { echo '<div class="inputgroup">Yes<input id="enddate_yes" class="radio enddatecheck" type="radio" name="no_enddate" value="yes" checked="checked" />No<input type="radio" name="no_enddate" id="enddate_no" value="no" class="radio enddatecheck" /></div>'; }else { echo '<div class="inputgroup">Yes<input class="radio enddatecheck" type="radio" id="enddate_yes" name="no_enddate" value="yes" />No<input class="radio enddatecheck" type="radio" name="no_enddate" value="no" id="enddate_no" checked="checked" /></div>'; } ?><br/><br/> <span class="end_date"> <label for="end_date">End Date:</label><br/><input name="end_date" id="end_date" class="date_pick" type="text" value="<?php echo $end_date; ?>" /><br /> </span>
  20. I have been using arrays and classes for awhile. However, I am having an issue I have never had before. I am using Codeignitor. I am getting a set of results. These results are returned as a class. Then I am looking through them and displaying them in a complex set. I am having to get some additional data and add it to it. Is there a way to add an array into a class as a class? For example. I have a class: Class->0->allthedata Class->1->allthedata Class->2->allthedata Class->3->allthedata Then I get my array Array[0][allthedata] Array[1][allthedata] Array[2][allthedata] I want to add that to the class Class->4->allthedata Class->5->allthedata Class->6->allthedata I am not sure if that makes sense. Is this possible? To just add some records at te end of the class with autonumbering.
  21. Believe it or not for the first time in 7 years, I had to use a Cron job. So I created a PHP script that did exactly what I wanted and put it in the root directory. After I had that in the root directory it was time to start setting up the cron. The client is using 1and1.com and you can only do the crons for them via SSH. So I got SSH Putty downloaded/installed and connected to the server. Ran the crontab -e command and then went into edit mode and put in all the data needed to save the file into the cron. '14 * * * * /kunden/usr/local/bin/php /kunden/homepages/**/****/htdocs/email_c ron.php' Apparently it worked and saved it correctly. I go back and do a list on the crons and it shows me that one as active. So with all of that done, I guess it's finished. I have a few questions. 1. Is there a way to test out a cron to make sure it's working, or can you pretty much guess that it's working if it's in there. Also, what happens if I change that email_cron.php...do I need to do anything to the crontab or will it always grab that file and use it regardless..meaning I can change the file as much as I want? Thanks again.
  22. I have a datetime field. Is there a Mysql function or PHP side something I can do to pull out only the results that are 4 days from today?
×
×
  • 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.