0

I'm working with drupal. I have this page something.com/node/13. Inside I have this script

 <?php
 $door = $_GET["variable"];
 echo $door;
 ?>

When I open the URL like this something.com/node/13?variable=1231 I get the following error:

  Error message
  Notice: Undefined index: variable in eval() (line 2 of /var/www/html/modules/php/php.module(74) : eval()'d code).

and no output. Any ideas what I might be doing wrong?

15
  • That error is not from the code posted here. Why are you using eval? What is the whole code? Commented May 16, 2012 at 21:12
  • Try $door = isset($_GET["variable"]) ? $_GET["variable"] : ''; Did you call the URL like something.com/node/13?variable=x? If you did, then Drupal is unsetting values in the $_GET array and presumably moving them somewhere else. Commented May 16, 2012 at 21:12
  • 2
    Possibly an absent [QSA] flag in the RewriteRules, so the ?variable=xx isn't carried on to the target script. Commented May 16, 2012 at 21:13
  • @Rocket I think Drupal is calling eval() in order to run the PHP code that the user has added to that particular page in the CMS. Commented May 16, 2012 at 21:13
  • 1
    To the OP - what is contained in the $_GET['q'] variable? (drupal.org/node/180589) Commented May 16, 2012 at 21:22

2 Answers 2

2

The error, partcilarly in drupal 7 simply means that you aren't getting any value for $_GET['variable']. This would be because the url doesn't have a value (someurl?variable=foo). You can avoid the notice by prefixing an @ like this:

$door = @$_GET['variable'];

but that won't make the variable return any data. It's pretty unclear from the code you've posted what you're trying to accomplish. You might consider starting there. There is no reason why you can't use $_GET variables in drupal. I do so all the time.

Sign up to request clarification or add additional context in comments.

Comments

0

Use drupal_get_query_parameters

Because the rewrite rules with Drupal, you don't grab the $_GET values cleanly directly like that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.