You are here:

PHP5/How to pass data while redirecting page

Advertisement


Question
QUESTION: Sir,

I want to pass the values (username) while redirecting the page.

I have 3 pages.

1 Login form
2 Login check page (using MYSQL database)
3 home page for registered user.

The Procedure : user fills the form (using post method), check login page checks the user is registered or not, if registered, redirect to the registered user's home page.

Aim : I want to print user name on each page.

Problem :  When check login page checks, user is registered or not, if user is registered the page starts new session and page redirect to registered user's home page but it lost the user name while redirecting the page (using header: location.....),

How can I pass the user name to registered user's home page.


Please help me to sought out my problem.

Thanks.

Ashish"
ANSWER: My advise would be to set a cookie with the user name and then recall it in the script you want by $_COOKIE['name'];  This seems to work for my scripts.

Regards,
Travis Pessetto

---------- FOLLOW-UP ----------

QUESTION: Sir,

There is any other options.

I saw a website (www.shaadi.com)which works fine if user disable cookie.

Regards,

Ashish

ANSWER: You could hold that information in a text file that has the computers IP.  Then get the Text file depending on the users IP return the user name.

Regards,
Travis Pessetto

---------- FOLLOW-UP ----------

QUESTION: Sir,

I don't know about this mathod. Can you provide me some more details (any example if possible).

Thanks in advance.

Regards,

Ashish

Answer
You know what I thought of an easier way to send the values.  You can use the GET command by sending it in the redirection header.  you use it by pointing to your script and putting a ?name=value  for example I want to send name in a script called getname it would look like this http://adomain.com/getname.php?name=Travis this would send Travis to the variable $_GET['name'] so you could do it that way too.

Regards,
Travis Pessetto

PHP5

All Answers


Answers by Expert:


Ask Experts

Volunteer


Travis Pessetto

Expertise

Variables, MySQL database,POST, GET, COOKIE

Experience

Self taught

©2012 About.com, a part of The New York Times Company. All rights reserved.