I want a Drupal page to display this information:

Hello Peter. You live in New York.

I can call the page like this:

www.mysite.com/showinfo.htm?Peter?New York

What code do I use in the Drupal page so that it shows the person's information?

Kindly show me how one can do this.

Comments

antoniotorres’s picture

I'm not entirely sure of what you're asking here.

Are you trying to pass variables to GET on the URL? drupal is a bit different.

what do you mean "the persons information" their profile information?

what are we working with here, be as explicit as you can please? :D

ahotel’s picture

In another program (outside of Drupal) I store a person's first name and city. They click a button in this program to go to my Drupal website.

I would like to take them to a page in my website that shows them their name and city.
So I made the button click do this:

www.mysite.com/showinfo.htm?Peter?New York

I can change this if required.

I don't know how to show these parameters on a Drupal page. How do I use the information and display it on a page?

I am a novice at html and php, but if you could show me how to do my simple example, that will be great.

So how do I make a Drupal page say:
Hello Peter. You live in New York.

Thanks

vikramy’s picture

Do like this..
Imagine you are sending that to node/1 of your drupal site..

www.mysite.com/node/1?name=Peter&place=New York

So in body of node/1 write a small php code..

//Check for isset($_GET[""]) if you want.. 

echo "Hello ".$_GET["name"].". You live in ".$_GET["place"]; 
ahotel’s picture

Thanks, that was helpful. I got it working OK.

I couldn't work out how to use isset(). Can you show how to use it for the example above?

anilo’s picture

if(isset($_GET['name']) && isset($_GET['place']))

Try double quotes if needed.

john morahan’s picture

To prevent this being a security hole you could use check_plain():

echo 'Hello '. check_plain($_GET['name']) .'. You live in '. check_plain($_GET['place']);

Or you could use t() and take advantage of Drupal's translation facility as well as the security benefits:

echo t('Hello @name. You live in @place.', array('@name' => $_GET['name'], '@place' => $_GET['place']));
ahotel’s picture

Thanks all for the helpful suggestions.

This is what I have so far.

www.mysite.com/node/1?name=Peter&place=New York

<?php

$name = check_plain($_GET['name']);
$place = check_plain($_GET['place']);

echo "Hello: ".$name;
print "<br/>";
echo "You live in: ".$place;
print "<br/>";
print "<br/>";

echo "Thanks for confirming your information.";

?>

NOTE: I don't know how to implement isset(). How would I use isset() in the code above?
Also any suggested changes to the above code are welcome.

Anonymous’s picture


if(isset($_GET['name']))
  $name = check_plain($_GET['name']);
else
  $name = 'anonymus';

if(isset($_GET['place']))
  $place = check_plain($_GET['place']);
else
  $name = 'nowere';


echo "Hello: ".$name;
print "<br/>";
echo "You live in: ".$place;
print "<br/>";
print "<br/>";

echo "Thanks for confirming your information.";

ahotel’s picture

Thanks Tomark - that works fine.