6

I am new to PHP.

I have a page that displays user profile. I need to pass user id to this page so that correct profile was displayed.

I just dont use the <form> element. I want to have a link

<a href="/users/24378234298734"> or <a href="/users/?id=24378234298734"> or whatever

Since I am not using form I cannot use _GET or _POST on the handler page What is the best way to handle the parameters on handler page?

3
  • You CAN pass a parameter via url and retrieve it with $_GET Commented Feb 24, 2011 at 16:57
  • 2
    ?id=24378234298734 is a _GET. Commented Feb 24, 2011 at 16:58
  • 3
    Why downvoting? I have C++ background and I am not PHP developer. Commented Feb 24, 2011 at 17:03

4 Answers 4

14

A form with method="GET" is just a way to build a query string automatically based on user input. Nothing prevents you using $_GET to read data from a manually constructed query string (and the server can't tell the difference anyway).

<a href="/users/?id=24378234298734"> will cause $_GET['id'] to be populated.

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

Comments

3

If you have a link somewhere like

<a href="/users.php?id=24378234298734">User XY</a>

and you put this code on users.php:

echo 'Hello '.$_REQUEST['id']; // $_REQUEST catches $_GET and $_POST

you will be able to set up a user page for user number 24378234298734.

Comments

2

Use this..

HTML

<a href="/users/?id=24378234298734">Link</a>

PHP

$id = $_REQUEST['id'];

1 Comment

Generally speaking, it is better to know if you are getting data from GET, POST or a cookie. $_REQUEST is best avoided.
2

You can use $_GET['id'] to retrieve the value in the url /users/?id=324332. No forms are required to receive _GET variables.

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.