Forum Moderators: coopster

Message Too Old, No Replies

i want to know if it's possible to post data form page to page

Post data form page to page

         

MrGecko

7:00 pm on May 4, 2006 (gmt 0)

10+ Year Member



i'm making a user login form and i
want to post the username form page to page
so i can display welcome $username
on each page

can any one help me?

Mr. Gecko

henry0

7:48 pm on May 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are using a form of authentication
and if your user did log in you probably
use a session; as such on the top of each page where you want to make the username available add:
<?php
session_start();
$username=$_SESSION['username'];

Now to display the username simply use:
Echo "Hello $username";

If you are not using session (which I doubt)
You may get the username via the original form
And create a session out of the username POST

$username=$_POST[‘username’];
$_SESSION[‘username’]=$username;
$username=$_SESSION['username'

That will do for the first page (The page receiving input from the form)
Then for any other pages again use
<?php
session_start();
$username=$_SESSION['username'];

MrGecko

9:25 pm on May 4, 2006 (gmt 0)

10+ Year Member



my problem is not that i don't know how to read the posted data
my problem is that when i change to the second page the posted data is lost and i want to make it so the first page will post the data to the second page with a link

eelixduppy

9:53 pm on May 4, 2006 (gmt 0)



What Henry0 is telling you is that you can use sessions to your advantage. When the information from the form is submitted to the first page, then you can do something like this:


session_start();
$_SESSION['info'] = $_POST['info'];

Doing this will enable you to access the information from the post on any page of your site as long as the session is started and the user doesn't exit out of their browser.

The second page will therefore look something like this:


session_start();
$info = $_SESSION['info'];
echo "<a href=$info>$info</a>"; //here depends on what you want to do, obviously

Hope this explains how you can achieve this.

eelix

MrGecko

9:47 pm on May 5, 2006 (gmt 0)

10+ Year Member



Thanks I know what you mean now
I'll try it on monday
And post if it works or not

Mr. Gecko