Passing a Variable to Another PHP Page Using URL Appending

What is the J2EE request.getParameter() equivalent in PHP?

Page 1 of 1

5 Replies - 2274 Views - Last Post: 19 July 2009 - 05:21 AM Rate Topic: -----

#1 DecafJava  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 18-May 09

Passing a Variable to Another PHP Page Using URL Appending

Posted 18 July 2009 - 12:19 PM

In PHP, what is the proper way to pass a variable from one page to another using URL appending only (no request or get requests)?

For instance, say I have a page1.php with a link to page2.php as follows:

<a href="page2.php?id='44'">Click</a>


In page2.php, can I just go ahead and do something like:
$id = $_GET['id'];

or
$id = $_POST['id'];

to obtain the value of id?

Intuitively, that makes sense...but no actual POST or GET request was sent, so not sure if it would work.

This post has been edited by DecafJava: 18 July 2009 - 12:21 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Passing a Variable to Another PHP Page Using URL Appending

#2 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 900
  • Joined: 08-August 08

Re: Passing a Variable to Another PHP Page Using URL Appending

Posted 18 July 2009 - 12:20 PM

yes, that should work fine, i cant see why not.


although you shoudl do this

<a href='page2.php?id=44'>Click</a>



instead of

<a href="page2.php?id='44'">Click</a>



This post has been edited by ghqwerty: 18 July 2009 - 12:23 PM

Was This Post Helpful? 0
  • +
  • -

#3 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: Passing a Variable to Another PHP Page Using URL Appending

Posted 18 July 2009 - 12:51 PM

Just wanted to add that you can't use $_POST when using querystrings (?something=value)! :)
Was This Post Helpful? 1
  • +
  • -

#4 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 900
  • Joined: 08-August 08

Re: Passing a Variable to Another PHP Page Using URL Appending

Posted 18 July 2009 - 12:52 PM

i thought that but was unsure if it was just me. thanks for claryfying
Was This Post Helpful? 1
  • +
  • -

#5 DecafJava  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 18-May 09

Re: Passing a Variable to Another PHP Page Using URL Appending

Posted 19 July 2009 - 01:26 AM

Thanks for the advices!
Was This Post Helpful? 0
  • +
  • -

#6 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: Passing a Variable to Another PHP Page Using URL Appending

Posted 19 July 2009 - 05:21 AM

why don't u store the info into a session ? then grab it on page 2 then get rid :) after you done what you need to do
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1