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?
php // page1. php session_start(); echo 'Welcome to page #1'; $_SESSION['favcolor'] = 'green'; $_SESSION['animal'] = 'cat'; $_SESSION['time'] = time(); // Works if session cookie was accepted echo '<br /><a href="page2. php">page 2</a>'; // Or pass along the session id, if needed echo '<br /><a href="page2.
Open your web browser and type your localhost address followed by '\form1. php'. Output: It will open your form like this, asked information will be passed to the PHP page linked with the form (action=”form2. php”) with the use of the POST method.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With