Bryan Anderson
Bryan Anderson

Reputation: 1

Display URL variables in webpage using PHP

I have data being passed via HTTP post to another page. Essentially passing data from one server to another. On the target page, I cannot get the URL variable to be seen by php. Am I doning something wrong? Is there a better way to do this?

URL string:

form_listener.php?
contactId=101460&inf_custom_ddState=IN&inf_custom_txtZipCode=46268&inf_custom_ddClientDegreeId=729&inf_custom_txtCity=indianapolis&inf_custom_txtLastName=Anderson&inf_form_xid=f28acf3ff321cb273cb4696e996008e0&inf_custom_ddStartSemesterYear=Fall2012&inf_custom_ddMilitaryAffiliation=Yes&infusionsoft_version=1.23.11.30&inf_custom_txtFirstName=someone&inf_custom_txtAddress2=&inf_custom_txtAddress1=4707+East+72nd+Street&inf_custom_ddHSGradYearCustomLiberty=2011&inf_form_name=LibertyOnline&inf_option_Signmeupforthenewsletter=432&inf_custom_txtEmailAddress=killing.fields%40gmail.com&inf_custom_affiliateid=D80576&inf_custom_ddEducationLevel=CLGJ&captcha.typed=jydqb

PHP Code:

$ddState= $_GET['inf_custom_ddState'];

echo $_GET['ddState'];

?>

Upvotes: 0

Views: 1177

Answers (7)

kal
kal

Reputation: 48

you can use either this way

echo $_GET['inf_custom_ddState']; 

Or

$ddstate=$_GET['inf_custom_ddState']; 
echo $ddstate;

Upvotes: 1

Utku Yıldırım
Utku Yıldırım

Reputation: 2277

$ddState= $_GET['inf_custom_ddState'];

echo $ddState;
// or 
echo $_GET['inf_custom_ddState'];

Upvotes: 1

superzoom
superzoom

Reputation: 471

First of all, make sure that your page is getting request parameters. Try $_REQUEST['inf_custom_ddState'] or print all variables using print_r($_REQUEST).

$_REQUEST is an associative array that by default contains the contents of $_GET, $_POST and $_COOKIE. If anyting is passing to page then it should get printed.

Upvotes: -1

admin
admin

Reputation: 41

When you use $_GET you are telling php that the variable is from the URL. By doing this:

$ddState = $_GET['inf_custom_ddState'];

you are "creating" a local variable ($ddState) with the content of $_GET['inf_custom_ddState'], so you don't have to use $_GET variable anymore.

So your echo can be in 2 ways:

  1. echo $_GET['inf_custom_ddState'];
  2. echo $ddState;

Upvotes: 1

Akhil Thayyil
Akhil Thayyil

Reputation: 9413

As the $_GET and $_POST are global array, you can use the following code to see the values:

echo "<pre>Get data</pre>";
print_r($_GET);
echo "<pre>Post data</pre>";
print_r($_POST);

Check whether these variables are set in the request. If not, try to use the post method, as it can hold more data than get method.

Upvotes: 0

Quentin
Quentin

Reputation: 943996

You don't have ddState in the URI. You want: echo $ddState; (because that is the variable where you copied the data to) or rather (to avoid opening up an XSS security hole) you actually want:

echo htmlspecialchars($ddState);

Upvotes: 2

shanethehat
shanethehat

Reputation: 15570

Your echo should just be echo $ddState;

You are assigning the value of the URL variable to a local variable. Once that's done, you are dealing with something that is locally scoped.

Upvotes: 0

Related Questions