Jump to content

MMDE

Members
  • Posts

    654
  • Joined

  • Last visited

Everything posted by MMDE

  1. foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); What does variables in $_POST that contains the 'qty' in their keyname contain? Just a little confused about it, as I would think it contained how many there is of a product they want to update. foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM Products WHERE id = '.$id; Security hole, because the $id is provided by the client. Another thing I don't get is why you keep writing arrays to string and then back to arrays and then to string and then array etc >_> So hard to read and so unnecessary. Here's your problem: foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } More precisely here: for ($i=1;$i<=$value;$i++) { change it to: for ($i=1;$i<$value;$i++) {
  2. First of all... $cart = $_SESSION['cart']; You must check if the variables you use are set. isset() Don't assume they exist when you haven't just set them yourself. foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { Why do you need to do stristr through all $_POST data? Can't they all the products be put in it's own array when sent as $_POST data, so you can foreach those. The name in the form inputs: "product[id][name]" and "product[id][quantity]" I can't see when you use those two included functions.
  3. PHP is a server side script. It does nothing in your webbrowser, and is parsed by a web service like Apache that has PHP installed before outputing it to the client. Yes, it's not working because the files are being opened in a webbrowser, and not parsed beforehand.
  4. There are some things that doesn't really make too much sense... 1993: 13 1994: 12 1995: 11 1996: 10 1997: 9 1998: 8 1999: 7 2000: 6 2001: 5 2002: 4 2003: 3 2004: 2 2005: 1 2006: 0 So, it is not enough for them to become 6 the year they start going to school? They need to be 6 when they start going to school? If that is the case, you will just have to compare the month first and check if it's above a certain number, and then do the same with the day. If I've understood this correctly, these numbers has moved two spots to the right after when we got to year 2000, so you will have to know the year to find the month and day. It should be pretty easy to implement with this code, just ask if you need more help: $nic = '9306____'; $oldest_year = 93; // write 20xx as 1xx $oldest_class = 13; $year = substr($nic, 0, 4); if($year[0]==2 && $year[1]==0){ $year -= 1900; }else{ $year = substr($nic, 0, 2); } $class = $year-((($year-$oldest_year)*2)+($oldest_year-$oldest_class)); This code is only looking at the age, and 2006 would be 0, while 93 = 13. I haven't put too much thought into the math, probably possible to write it cleaner. Might be easier to use if you edit it so you use youngest year and class instead.
  5. As I said in my earlier post: $backlinkSources[] = $row['website']; Oh and sorry, I didn't see you created the $backlinkSources array before the mysql_query. If it is a function, you may still want to terminate the execution of the rest of the code when there is no results from the mysql_query.
  6. I don't see 45 lines, neither the lines that gives the errors. What the code does is looping through the mysql_query's result. What it loops through is arrays of all the columns you've selected in your mysql_query. You are assigning these to a new array. This new array will therefor be an array of arrays. do this after the loop to see the content of the array $backlinkSources: echo '<pre>'; print_r($backlinkSources); echo '</pre>'; You will probably need to do this: foreach($backlinkSources AS $backlinkSource){ file_get_contents($backlinkSource['website']); } Or just do this while you loop through the results: while($row = mysql_fetch_assoc($result)) { $backlinkSources[] = $row['website']; } The latter is probably the best. Another little thing to note is what would happen if the mysql_query resulted in no rows? You would never create the array $backlinkSources, and later would try to use it. Do this before the loop to make sure it exists: $backlinkSources = array(); Or you could just check if the mysql_query resulted in 0 rows and terminate the execution of the rest of the related code: if(!mysql_num_rows($result)){ return; //should terminate the function if this is a function }
  7. How does 85_____ become 05-08-1985? And why is it not exactly that, just like that? Anyways the later part makes me think you want this: $nic = '85_____'; echo $nic[0].$nic[1];
  8. You should post your final code too if you want to know if you've done more things that might get you into trouble.
  9. I'm not too sure what you got in mind, but if it's something like a ping, then it's completely useless to determine their bandwidth. There are so many different factors that might affect the result. The most important one is that how quickly they respond has absolutely nothing to do with their bandwidth and how fast they are able to load your site even if it's very heavy. Even if ping was enough to determine bandwidth, you would need to keep statistics of the user to determine their bandwidth. I don't think it's a too good idea to keep changing between how the user views the site all the time. It's also very hard to keep track of unless they are members, and if they are members, a better solution is just to allow them to change it themselves instead of you forcing it on them based on a ping.
  10. Please post the error. Please use code tags when posting code. Please explain a bit more what exactly you are trying to do, as I certainly didn't understand (though someone else might understand it). From what I was able to gather, you may want to do something that is run on the client side, but if that is the case, you should know that PHP is serverside scripting.
  11. You could also just completely avoid the problem. Write the login into all pages, if that makes any sense. I think someone else could explain this better than me.
  12. See the link, it's the PHP manual for mysql functions. It says what the functions are and how to use them.
  13. You must use a function to handle the result of the mysql_query. Read the manual: http://www.php.net/manual/en/ref.mysql.php you typically use mysql_fetch_* or mysql_result. You may want to use mysqli_* instead of mysql_*
  14. We need a better example of exactly what you want. Give us some code we can help you with.
  15. http://forums.phpfreaks.com/index.php?topic=200925.0 Yes, you can do this. It's a lot of work because of security reasons. You will probably want to use a database like MySQL to store the posts. There should be plenty of guides out there on this topic. Just make sure you also read some good security guides too. You should come back when you got some coding done and you are stuck with something, or if you want some help with the security (but again, you will need to at least try to do it on your own first and be able to show us that).
  16. Could you show us the HTML and explain exactly what you want it to do? CSS shouldn't be dynamically changed depending on the content in the html page, because it's cached by the browser, but the later versions of CSS allows you to do quite a lot of stuff. You also got JavaScript.
  17. I don't think it would be such a good idea, because CSS is cached and won't be changed every time they visit a page with the same CSS. If you really want to do it anyways: http://php.net/manual/en/function.strlen.php http://php.net/manual/en/function.file-put-contents.php
  18. I actually suggest you break it into more methods/functions. Way too big method/function. Try to keep it at under 10 lines or so. public function index($user_id = NULL, $registration_key = NULL) { $message_box_messages = array(); $css_page_addons = ''; $js_page_addons = ''; $meta_tag_addons = ''; $site_title = 'KOW Manager Account Activation'; var_dump($user_id); var_dump($registration_key); if ((!is_numeric($user_id)) || ($registration_key == NULL)) { $message = 'One or both parameters were not entered!'; } else if (!(($user_id > 0) && (preg_match('/^[A-Za-z0-9]+$/', $registration_key)))) { $message = 'The parameters do not meet the validation criteria!'; } if (!$this->users_model->is_registered($user_id)) { $message = 'The user specified does not exist in the database!'; } $user_status_id = $this->users_model->get_user_status_id($user_id); if ($user_status_id != 1) { $message = 'The user specified is already activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>'; } else if (!$this->users_model->check_user_registration_key($user_id, $registration_key)) { $message = 'The registration key did not match the user specified!'; } $this->db->trans_start(); if ($this->users_model->change_account_type($user_id, 2)) { if ($this->users_model->erase_registration_key($user_id, $registration_key)) { $activation_date = gmdate('Y-m-d H:i:s'); if ($this->users->insert_activation_date($user_id, $activation_date)) { $message = 'The user is now activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>'; } else { $message = 'The activation date was not able to be inserted properly!'; } } else { $message = 'The registration key failed to erase for the user specified!'; } } else { $message = 'The user specified was not able to have his account changed!'; } $this->db->trans_complete(); if ($this->db->trans_status()) { $message = 'The user is now activated! You may now proceed to the login page.<br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>'; } else { $message = 'The user was not able to be activated. The account specified was not able to be changed into a user!'; } $body_content = $this->config->item('themes_path').'/'.$this->config->item('default_theme').'/usermanagement/general_message'; $body_type = 'full'; if (count($message_box_messages) !== 0) { $message_boxes = $this->functions_model->build_message_boxes_output(array('display' => 'show', 'messages' => $message_box_messages)); } else { $message_boxes = array('display' => 'none'); } $meta_tags = $this->functions_model->meta_tags(); if (isset($site_title) && (empty($site_title))) { $site_title = $this->functions_model->site_title(); } $this->data['message_boxes'] = $message_boxes; $this->data['css_page_addons'] = $css_page_addons; $this->data['js_page_addons'] = $js_page_addons; $this->data['site_title'] = $site_title; $this->data['body_content'] = $body_content; $this->data['body_type'] = $body_type; $this->data['meta_tags'] = $meta_tags; $this->data['message'] = $message; $this->load->view($this->config->item('themes_path').'/'.$this->config->item('default_theme').'/usermanagement/index', $this->data ); } } I suspect you didn't really write this entire code. Why do you create $message_box_messages = array(); without using it? I suspect that is where you were supposed to store all the messages, and not like you've done it where they overlap each other. What I tried to say at the end is that you need to use "return" to end the method when for example $user_id is not set. This is because you some few lines later try to use something you've probably already made sure isn't set. Let me put it in other words, you are aware something doesn't exist, but then ignore that fact and attempt to use it anyways. return is used to make a function return a value, but it can be set alone like this: return; if you don't want it to return anything (void), and by that canceling executing the rest of the function.
  19. Well, one problem is it that you keep re-assigning $message all the time. You should do it like this: $message = ''; if ((!is_numeric($user_id)) || ($registration_key == NULL)) { $message .= 'One or both parameters were not entered!<br />'; } else if (!(($user_id > 0) && (preg_match('/^[A-Za-z0-9]+$/', $registration_key)))) { $message .= 'The parameters do not meet the validation criteria!<br />'; } You see the dot? Now it will add each message to $message, instead of just the last message. You may also want to print something to the screen everywhere you want to check if it gets to in the script. Another thing to be noted, even if it fails to find an id, you later just keep using id as if it was valid. if (!$this->users_model->is_registered($user_id)) Use return to exit the method/function early.
  20. When I did this: <?php if ((!is_numeric($user_id)) || ($registration_key == NULL)) { $message = 'One or both parameters were not entered!'; } else if (!(($user_id > 0) && (preg_match('/^[A-Za-z0-9]+$/', $registration_key)))) { $message = 'The parameters do not meet the validation criteria!'; } echo $message; ?> I got this: <br /> <b>Notice</b>: Undefined variable: user_id in <b>x:\pathtofile.php</b> on line <b>2</b><br /> One or both parameters were not entered! With other words, you need to check if $user_id is set, isset(). You may also want to do this before line 2: var_dump($user_id); var_dump($registration_key); so you know what they are for sure.
  21. I'm not entirely sure what you mean, but if $registration_key is set to NULL, it will show the first message, because: $registration_key == NULL part in: if ((!is_numeric($user_id)) || ($registration_key == NULL)) would be true. Since you use ||, which means or and returns true if one or both parts are true. Read more about it in the manual: http://php.net/manual/en/language.operators.logical.php
  22. The revised code will result in error/warning whenever $_POST['status'] is not set. $status = $_POST["status"]; here's what you want to do instead: if(isset($_POST['status']) && $_POST['status'] == 'Active') { //code here }
  23. Why are there two different codes? Use one. You need to check if the $_SESSION['antal'] is set or not before assigning a new value to it. if(!isset($_SESSION['antal'])){ $_SESSION['antal'] = 10; } Only $_SESSION['antal']--; when they have guessed. You also need to make sure if they have guessed. You can't just go ahead and do this: $g?t = $_POST['g?t']; $send = $_POST['send']; Because $_POST['send'] might not be set, and then it will be looking for something that doesn't exist. It's just to use isset() again. Remember that only if they guess you can decrease the amount of guesses left, and you must make sure SESSION then too is already set. $g?t = $_POST['g?t']; Use numbers and English alphabetical characters only in variable names, and they must start with the latter. It also seems like you are setting a new random number each time. Isn't that confusing for the person guessing? There is nothing stopping a person from clearing the session and get 10 new attempts.
×
×
  • 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.