Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameter to php page without form

Tags:

php

hyperlink

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?

like image 443
Captain Comic Avatar asked Feb 24 '11 16:02

Captain Comic


People also ask

How can I pass variable from one php page to another without form?

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.

How can I pass value from one page to another in php?

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.


2 Answers

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.

like image 115
Quentin Avatar answered Oct 09 '22 07:10

Quentin


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.

like image 3
powtac Avatar answered Oct 09 '22 05:10

powtac