Is it possible to save session values between pages? I did a little script
to let the users login. I use this script to check username and password the
user introduces in a form in the main page, index.php.
If a user is found with username and password, than I create
$_SESSION['Login'] and assign it a value of true, else I assign it a value
of false. If a user is non registered, I send it to the proper page to
register, RegistraUtente. php, if he is registered yet, I send him back to
index.php
But here in index.php $_SESSION['Login'] has no value.
Here is the script I wrote:
<?php
session_start() ;
include("dbconn ect.php");
$tabella="table ";
$dbname="Zucca" ;
if (!isset($_SESSI ON['Login']))
{
$_SESSION['Login']=false;
}
$IdUser=session _id();
$data=date('Y-m-d');
if (!ISSET($HTTP_C OOKIE_VARS["PiOnLine"]))
setcookie("PiOn Line",$IdUser,t ime()+60*60*24* 365);
else
$IdUser=$HTTP_C OOKIE_VARS["PiOnLine"];
mysql_select_db ($dbname,$db);
$username=$_POS T["username"];
$password=$_POS T["password"];
$query="Select Username, UserPassword from $tabella where
('$password'=Us erPassword) and ('$username'=Us ername)";
$result=mysql_q uery("$query") or die(mysql_error ());
// Se esiste l'utente con username e password allora consenti il login
if (mysql_num_rows ($result)==1)
{
$_SESSION['Login']=true;
session_write_c lose();
$url="index.php ";
header ("Location: $url");
}
else // Invia l'utente sulla pagina di registrazione
{
$_SESSION['Login']=false;
session_write_c lose();
$url="RegistraU tente.php";
header ("Location: $url");
}
?>
Franz 5 2254
The whole point of session variables is inter-pageview preservation. You
just aren't using the session vars just right. Where you did:
$_SESSION['Login']=true;
You should have done:
$Login = true;
session_registe r("Login");
Later, pages can access it as $HTTP_SESSION_V ARS["Login"]. I'm not sure if
there are differences between $HTTP_SESSION_V ARS and $_SESSION - check the
PHP docs @ http://www.php.net and remember to provide a logout:
$Login=false;
session_registe r("Login");
You can also log the user out by using session_destroy ().
~Eric
My PGP public key: http://www.parabolagames.com/chem/pgppubkey.txt
"Lamp" <la**@dina.it > wrote in message
news:HQ******** **************@ news4.tin.it... Is it possible to save session values between pages? I did a little script to let the users login. I use this script to check username and password
the user introduces in a form in the main page, index.php. If a user is found with username and password, than I create $_SESSION['Login'] and assign it a value of true, else I assign it a value of false. If a user is non registered, I send it to the proper page to register, RegistraUtente. php, if he is registered yet, I send him back to index.php But here in index.php $_SESSION['Login'] has no value.
Here is the script I wrote:
<?php
session_start() ;
include("dbconn ect.php");
$tabella="table ";
$dbname="Zucca" ;
if (!isset($_SESSI ON['Login']))
{
$_SESSION['Login']=false;
}
$IdUser=session _id();
$data=date('Y-m-d');
if (!ISSET($HTTP_C OOKIE_VARS["PiOnLine"]))
setcookie("PiOn Line",$IdUser,t ime()+60*60*24* 365);
else
$IdUser=$HTTP_C OOKIE_VARS["PiOnLine"];
mysql_select_db ($dbname,$db);
$username=$_POS T["username"];
$password=$_POS T["password"];
$query="Select Username, UserPassword from $tabella where ('$password'=Us erPassword) and ('$username'=Us ername)";
$result=mysql_q uery("$query") or die(mysql_error ());
// Se esiste l'utente con username e password allora consenti il login
if (mysql_num_rows ($result)==1)
{
$_SESSION['Login']=true;
session_write_c lose();
$url="index.php ";
header ("Location: $url");
}
else // Invia l'utente sulla pagina di registrazione
{
$_SESSION['Login']=false;
session_write_c lose();
$url="RegistraU tente.php";
header ("Location: $url");
}
?>
Franz
"Eric Stein" <no@spam.com> wrote in message
news:c6******** ***@news.wplus. net... The whole point of session variables is inter-pageview preservation. You just aren't using the session vars just right. Where you did:
$_SESSION['Login']=true;
You should have done:
$Login = true; session_registe r("Login");
No, $_SESSION['Login'] = true should work perfectly fine. I'm not entirely
sure what the problem is. I suspect it has something to do with setting the
cookie. In general when you're using session variables, you should keep your
hand off the cookie. Stay away from session_registe r() too.
Chung,
Sorry, I didn't know - but I've been using session_registe r() for a long
time and it's always worked. Why shouldn't I use it?
~Eric
My PGP public key: http://www.parabolagames.com/chem/pgppubkey.txt
"Chung Leong" <ch***********@ hotmail.com> wrote in message
news:sc******** ************@co mcast.com... No, $_SESSION['Login'] = true should work perfectly fine. I'm not entirely sure what the problem is. I suspect it has something to do with setting
the cookie. In general when you're using session variables, you should keep
your hand off the cookie. Stay away from session_registe r() too.
Eric Stein <no@spam.com> wrote: Chung, Sorry, I didn't know - but I've been using session_registe r() for a long time and it's always worked. Why shouldn't I use it?
Because the manual says so :)
<q src='http://nl2.php.net/session_registe r'>
Caution
If you want your script to work regardless of register_global s, you need
to instead use the $_SESSION array as $_SESSION entries are
automatically registered. If your script uses session_registe r(), it
will not work in environments where the PHP directive register_global s
is disabled.
</q>
Also look at the other warnings.
--
Daniel Tryba
Eric Stein wrote: The whole point of session variables is inter-pageview preservation. You just aren't using the session vars just right. Where you did:
$_SESSION['Login']=true;
You should have done:
$Login = true; session_registe r("Login");
Later, pages can access it as $HTTP_SESSION_V ARS["Login"]. I'm not sure if there are differences between $HTTP_SESSION_V ARS and $_SESSION - check the PHP docs @ http://www.php.net and remember to provide a logout:
$Login=false; session_registe r("Login");
You can also log the user out by using session_destroy (). ~Eric
My PGP public key: http://www.parabolagames.com/chem/pgppubkey.txt
"Lamp" <la**@dina.it > wrote in message news:HQ******** **************@ news4.tin.it... Is it possible to save session values between pages? I did a little script to let the users login. I use this script to check username and password the user introduces in a form in the main page, index.php. If a user is found with username and password, than I create $_SESSION['Login'] and assign it a value of true, else I assign it a value of false. If a user is non registered, I send it to the proper page to register, RegistraUtente. php, if he is registered yet, I send him back to index.php But here in index.php $_SESSION['Login'] has no value.
From the posted script the problem isn't immediately obvious. Other than
maybe the following. Are you testing the script on your local box running a
web server? Make sure that you access your script through http://127.0.0.1/scriptname.php and not http://localhost/scriptname.php
because: If you session_start() on a "localhost" page, that session is not
available to a "127.0.0.1" page. On Apache, I can access http://localhost/login.php no problem, but when I send the variable to a
relative path from login.php, Apache changes the hostname to the loopback
interface, 127.0.0.1, which of course the session won't work for.
Just a thought :)
..:Albe
-- http://www.ninja.up.ac.za This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Kandell |
last post by:
Hi,
I posted this in the asp.net group, but didn't get a response. Maybe someone
here can help me with this...
---
Would someone be able to shed some light on what is the cost of saving a
DataTable to session vs saving a custom object of the same data.
|
by: Ray |
last post by:
Hi
I have designed a database app using a windows form and a tab control with
comboboxes and edit controls on each tab control. The problem that I am
having is with the edit form that I have created.
On the forms onload event handler I databind the controls on the various tab
controls to the dataset for the selected record.
The problem comes when I save the record. If I haven't clicked on each tab
|
by: RA |
last post by:
Hi
I use ASP.net with c#. The web application is hosted by a web host provider.
The application gets user information for order processing. The information
should be moved from one aspx page to the other until the user choose to
submit the order. The order process has about 4 aspx pages. What will be the
best way to keep the user data between the pages considering the following:
1) User might not have cookies enabled
2) I have no...
|
by: Denis Georgievski |
last post by:
I am optimizing my web application written in ASP/VB.NET 1.1. I have number
of pages that have dropdown list server controls that contain large number
of items. Before redesigning the data access I would like to try by saving
the view state to the server if this can speed up the access to these heavy
pages. Could somebody give me a working example on saving the viewstate to
the server written in VB.
Thanks
|
by: RCS |
last post by:
I have an app that I have different "sections" that I want to switch back
and forth from, all while having the server maintain viewstate for each
page. In other words, when I am on Page1.aspx and set textboxes, radio
buttons, etc - that viewstate is fine. Then I have a linkbutton that does a
Server.Transfer over to Page2.aspx. When I Server.Transfer back to
Page1.aspx, the viewstate info is lost.
I ran across another example of this last...
| |
by: DKode |
last post by:
Hello,
I am trying to call a UserControl after postback to save data filled
out on that usercontrol to sql server.
The problem I am having is this, I have 2 LinkButtons that I have setup
as tabs on my app, the user fills out information on UserControl_1,
when they click a different tab, I want to load UserControl_2 and save
the data that was entered into UserControl_1.
|
by: VMI |
last post by:
I'm working on a web application that's basically a questionaire that
consists of 8 pages. Each page has different data that needs to be saved. I
have to either save all the data from all 8 pages OR save nothing.
What's the best way to temporarily save this data and then insert (or
update) all this data in bulk at the end of the questionnaire?
Any help is appreciated.
Thanks.
|
by: Annie |
last post by:
hello guys,
I have a scenario that I am confused about ...
I have a number of pages which are using a Master page ...
Then I have seperate Footer user control that can reside in master page or
could be kept
in the content pages (still not confirmed and looking for any suggestion)
|
by: Annie |
last post by:
Hi guys,
I am having a weired situation that don't know how to handle it ...
I have master pages, the master page contains a dynaic menu which is set up
in the database
and has page url, name, title etc.
The menu is loaded dynamically at run time. The problem that I have is that
once the users are selecting
any menu option (eg a link) i should manage to save current page content and
|
by: Bam |
last post by:
Hey gang.
Is there a way, to automatically save a page that is db driven, as a page
that contains html?
i would like a page like
http://tournamentsbyeck.com/past_standings3.asp
to be converted to the html values. i want to do this, so the db doesn't
grow too large.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |