473,473 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

sessions

5 New Member
hi everyone,

I have just started learning php. I have this problem with sessions.

There is a page called sesstest1.php where i can write my name and click the "click me" button. Now it goes to sesstest2.php where i want to display my name and a hyper link which takes me to the same page(sesstest2.php). The problem is if i am using $_SESSION=$_POST, then, only for the first time my name is getting displayed. How do be able to retrieve my name how many ever times i click on the hyper link.

Here is my code for sesstest1.php
[php] <?php
session_start();
?>
<html>
<head>
<title>
test page 1
</title>
</head>
<body>
<form name="test1" action="sesstest2.php" method="post">
<input type="text" name="username">
<input type="submit" name="submit" value="click me">
</form>
</body>
</html>[/php] this is my sesstest2.php
[php] <?php
session_start();
?>
<html>
<head>
<title>
test page 2
</title>
<head>
<body>
<?php
$_SESSION=$_POST;
echo $_SESSION['username'];
echo "<br/>";
$self=$SERVER['PHP_SELF'];
echo '<a href="'.$self.'">NEXT</a>';
?>
</body>
</html>[/php]Could you help? Thank you
Mar 30 '08 #1
5 982
ronverdonk
4,258 Recognized Expert Specialist
Welcome to The Scripts!

We are only prepared to help you when you adhere to the Posting Guidelines, in this particular case about enclosing all code within tags.

So please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Mar 30 '08 #2
learnphp25
5 New Member
Welcome to The Scripts!

We are only prepared to help you when you adhere to the Posting Guidelines, in this particular case about enclosing all code within tags.

So please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
sure, I will adhere to the rules in the future,
Thank you.
Mar 30 '08 #3
ronverdonk
4,258 Recognized Expert Specialist
The $_SESSION array is overwritten each time the 2nd routine is invoked, even when there is nothing in the $_POST array, and that is when you issue the GET in the hotlink.

You must first test if there is anything submitted using POST and when so, save that in the $_POST array, like this starting at line 11 in the 2nd script[php]<?php
if (isset($_POST['username'])
$_SESSION['username']=$_POST['username'];
echo $_SESSION['username'];
echo "<br/>";
$self=$SERVER['PHP_SELF'];
echo '<a href="'.$self.'">NEXT</a>';
?>[/php]Ronald
Mar 30 '08 #4
learnphp25
5 New Member
The $_SESSION array is overwritten each time the 2nd routine is invoked, even when there is nothing in the $_POST array, and that is when you issue the GET in the hotlink.

You must first test if there is anything submitted using POST and when so, save that in the $_POST array, like this starting at line 11 in the 2nd script[php]<?php
if (isset($_POST['username'])
$_SESSION['username']=$_POST['username'];
echo $_SESSION['username'];
echo "<br/>";
$self=$SERVER['PHP_SELF'];
echo '<a href="'.$self.'">NEXT</a>';
?>[/php]Ronald
Thank you very much, this solves my problem
Mar 30 '08 #5
ronverdonk
4,258 Recognized Expert Specialist
You are welcome. See you around some time.

Ronald
Mar 30 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: The Plankmeister | last post by:
Hi... I'm trying my hardest to understand fully how sessions work and how best to use them. However, all I can find is information that doesn't tell me anything other than that sessions store...
13
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location...
3
by: Maxime Ducharme | last post by:
Hi group We have a problem with sessions in one of our sites. Sessions are used to store login info & some other infos (no objects are stored in sessions). We are using Windows 2000 Server...
3
by: Will Woodhull | last post by:
Hi, I'm new here-- I've been reading the group for a couple of days. Nice group; I like the way n00b33 questions are handled. I've been using a Javascript routine in index.html to determine a...
2
by: Steve Franks | last post by:
According to the docs you tell ASP.NET to use cookieless sessions by setting a value in the config.web file. However, what if I wanted to determine at run time whether or not I wanted to use...
12
by: D. Shane Fowlkes | last post by:
This is a repost (pasted below). Since my original post, I've double checked the system clock and set all IIS Session Timeout values to 10 minutes. Still ...the problem occurs. I've also...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
22
by: magic_hat60622 | last post by:
Hi all. I've got an app that dumps a user id into a session after successful login. the login page is http://www.mydomain.com/login.php. If the user visits pages on my site without the www (i.e.,...
13
Frinavale
by: Frinavale | last post by:
One of the most fundamental topics in web design is understanding how to pass information collected on one web page to another web page. There are many different ways you could do this: Cookies,...
3
Atli
by: Atli | last post by:
Introduction: Sessions are one of the simplest and more powerful tools in a web developers arsenal. This tool is invaluable in dynamic web page development and it is one of those things every...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.