0

i have this errors in error log

mod_fcgid: stderr: PHP Notice: Undefined index: url in /var/www/vhosts/mysite.it/httpdocs/wp-content/themes/colormag-pro/js/sharrre/sharrre.php on line

4 lines affected.

Are they dangerous for my site? How can i fix them exactly?

UPDATE: First 4 lines of this code in sharre.php get errors

 $json['url'] = $_GET['url'];
  $url = urlencode($_GET['url']);
  $type = urlencode($_GET['type']);

  if(filter_var($_GET['url'], FILTER_VALIDATE_URL)){
    if($type == 'googlePlus'){  //source http://www.helmutgranda.com/2011/11/01/get-a-url-google-count-via-php/
      $contents = parse('https://plusone.google.com/u/0/_/+1/fastbutton?url=' . $url . '&count=true');
willsmith7
  • 21
  • 6
  • This generally means the PHP failed to access item in an array index, that is actually not defined yet at all. Try to look at line numbers in the sharrre.php files to see what $variables are accessed there. – igraczech Jan 03 '17 at 11:10
  • Sorry. Just added the code lines that are giving errors. Do you know what edit should i do to fix those errors? – willsmith7 Jan 03 '17 at 11:34
  • Please get your tags and title right! –  Jan 03 '17 at 11:40
  • Sorry Andreas, i don't know what you mean, first time i post here. I edited the post and made it more comprehensible, matching with title and tag, hoping anyone can help – willsmith7 Jan 03 '17 at 11:53
  • 2
    Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – j08691 Jan 03 '17 at 16:45
  • 1
    you're assuming `$_GET['url']` is set without checking it first. Check if its set using `empty()`. Same for `$_GET['type']` – chiliNUT Jan 03 '17 at 16:47
  • Thank you the answer, but, i'm very ignorant @PHP. May you tell me the exact code i should edit to fix? – willsmith7 Jan 03 '17 at 17:41
  • The bug is really what it says. There's no index called 'url' in the $_GET array, maybe this has been called using command-line or without an &url= parameter set. @chiliNUT probably means something like ```if ( empty($_GET['url']) ) { die ("'url' not set in HTTP GET request"); }``` – igraczech Jan 05 '17 at 12:57

2 Answers2

1

Not too bad, annoying. A 'Notice' is something that PHP can carry on with but may cause something else to break, but on the same hand might not cause anything to break at all. A lot of the time 'Notices' can be ignored and are generally turned off in production environments.

Personally I hate to see 'Notices' in my code but that's just me.

Either $json['url'], $_GET['url'], or both are not set so check both and see which one is not being set, from there you will be able to trace back to what is supposed to be setting the variable and fix it.

Use an isset() to check if each one is set before the first line of the code you pasted to check if either one is not actually set.

Chris
  • 435
  • 4
  • 11
  • Thanks very much but i'm not an expert of PHP, so, may you tell me the exact code i should edit to fix the error? – willsmith7 Jan 03 '17 at 17:42
  • Without seeing your entire code base I could not tell you where the error is occurring, However you could stopp the message by surrounding the code containing $json['url'] and $_GET['url'] with an if statement `if (isset($json['url']) && isset($_GET['url']))...` but that might end up breaking more so do at your own risk. – Chris Jan 04 '17 at 10:31
0

This is not dangerous for your site per se. The variable(s) in the GET are not set (variables $_GET['url'] is not set). If you plan to use it later in your PHP script, you should set them before, on the previous page. So, there are two pages, first one and your PHP page - the second one.

Vladimir Despotovic
  • 3,200
  • 2
  • 30
  • 58
  • 1
    Thanks for the answer, but, i'm very ignorant @PHP. May you tell me the exact code i should edit to fix? – willsmith7 Jan 03 '17 at 17:41
  • Replace $json['url']=$_GET['url'] with if (isset($_GET['url']))$json['url'] = $_GET['url']; – Vladimir Despotovic Jan 03 '17 at 17:43
  • 1
    Thanks a lot!! So i just need to edit the first line of that code? Should i keep the other lines as they are even if the error is reported for 4 lines? – willsmith7 Jan 03 '17 at 19:04
  • What are the other 3 errors? I only told you the solution for the 1 error that you wrote. If you tell me other errors, I can help you again. – Vladimir Despotovic Jan 03 '17 at 20:16
  • 1
    It's the same error, but it also appears for 2nd, 3rd and 4th line of the code i pasted above. You suggested me the solution for the 1st line and the error is fixed, but for the other 3 lines it still appears – willsmith7 Jan 03 '17 at 20:28
  • Then, do the same for 2nd, 3rd and 4th. So put if(isset($_GET['url']))$url = urlencode($_GET['url']); instead of $url = urlencode($_GET['url']); Put if(isset($_GET['type']))$type = urlencode($_GET['type']); instead of $type = urlencode($_GET['type']); – Vladimir Despotovic Jan 03 '17 at 20:29
  • Also, please upvote my answer and comments if it is helpful to you. Upvote the comments too if they helped you too. – Vladimir Despotovic Jan 03 '17 at 20:31
  • 1
    And what to put instead of the 4th line? This one: if(filter_var($_GET['url'], FILTER_VALIDATE_URL)){ Btw, I upvoted the answer, can you explain how to upvote the comments? – willsmith7 Jan 03 '17 at 20:37
  • Maybe you can't upvote comments yet, because you have a small reputation. Thanks anyway. For the fourth line, do the same: instead of if(filter_var($_GET['url'], FILTER_VALIDATE_URL)){ put if(isset($_GET['url'])) if(filter_var($_GET['url'], FILTER_VALIDATE_URL)){ – Vladimir Despotovic Jan 03 '17 at 20:41
  • 1
    You are great, thanks a lot. I don't know if there is a contacts system in this site, but if there is, add me or give me your mail if you want other upvotes for helping me in other questions that i'll ask in this site. – willsmith7 Jan 03 '17 at 20:48
  • Thanks. And no, there is no contacts system. The whole point is that people voluntarily and on their own upvote/downvote. I am tired of telling people to upvote my comments and questions, to be honest :) but I have to, because people don't do that, and over time, the number of idiots who downvote overwhelms those who upvote me and I lose some privileges (like for example privilege to upvote comments). The point is, evil rises by itself, and good has to be worked (or begged) for, because people are to lazy or stupid to do the right thing :) – Vladimir Despotovic Jan 03 '17 at 21:03
  • 1
    Agree. Anyways, you deserved my upvote not because you told me, but for how excellently you helped me, and i didn't upvote before just because i didn't even know about the existence of upvotes. And if i did, i would not have known that they're useful for users. So you did the best thing by telling me, now i can also upvote others who help. For this you deserve it even more ;) – willsmith7 Jan 03 '17 at 21:34