Hey all
How can i capture the username, which is being input in a textbox, and pass it to another page?

Login.php
Example,
username: admin

Welcome.php
it should display,
Welcome, admin

How can i achieve this?

Using dtreamweaver with PHP language

Thanks

Dani AI

Generated

Short answer: submit the form to a PHP script that validates the input, store the username in a session, then read and escape that session value on the welcome page. That keeps the username out of the URL and lets you show "Welcome, admin" reliably.

As already noted, GET and POST are both ways to send form data, but prefer POST for login-like inputs so values do not appear in the URL. As suggested, sessions are the right place to keep the remembered username — but watch the common mistakes: always call session_start() at the very top of every PHP file that uses $_SESSION, use the $_SESSION superglobal (not a bare SESSION), and check isset before reading. When you output the username, escape it to prevent XSS, for example with htmlspecialchars($_SESSION['username'], ENT_QUOTES, 'UTF-8') (see htmlspecialchars). The official note on starting sessions is at session_start.

Security tips and production practice: regenerate the session id after login to reduce fixation risk (session_regenerate_id(true) — see session_regenerate_id), set the session cookie with Secure and HttpOnly flags, never store passwords in plain text in sessions, and authenticate usernames against a database using password hashing APIs (see password_hash). Sanitize and validate input server-side rather than relying on client-side checks.

Quick debugging checklist: run PHP through a local server (not file://), check for "headers already sent" errors (output before session_start()), verify form method matches how you read input, and inspect PHP error logs. This covers the reliable, secure flow needed to capture a username and display it on another page.

Recommended Answers

All 3 Replies

you pass it via the $_GET method or the $_POST method.

you pass it via the $_GET method or the $_POST method.

Could you guide me on how to do that?
Im a beginner in php

Ok, you need to look at a few tutorials (there's millions on the net) about user logins and sessions. In a nutshell: form.html This contains the textbox.

<form action="submit.php" method="GET"> <!--or "POST"-->
  <input type="text" name="username" />
</form>

submit.php Set the session variable

<?php
session_start(); //so you can use the session variable
&username = $_GET['username']; //or $_POST depending on form method
echo "Hello $username. I have learnt your name!";
SESSION['username']=$username;
?>
<a href="/page.php">Return</a>

page.php //Content page

<?php
start_session();
if isset($_SESSION['username']){
  echo "Hey $_SESSION['username'], I remembered your name!";
}
?>
...rest of page content

Now please do some research so you understand that code and how your using it.

[code untested]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.