-
October 11th, 2006, 06:56 AM
#1
Senior Member
PHP on HTML pages
Hi all,
I have completed my whole site in HTML.
I have my login page in php.
Some one suggested me that there there can be a small code which can be added in all the pages, and after changing the extn to php, I can use sessions in all of the site.
Can this be possible?
If yes, can someone provide me that code?
I dont want to make many changes in the site now.
thanks
riya
Now is the moment, or NEVER!!!
-
October 11th, 2006, 11:53 PM
#2
Just add...
PHP Code:
<?php
session_start();
?>
to the top of all your pages. When they login you can add their username to the $_SESSION array.
PHP Code:
<?php
$_SESSION['username'] = $_POST['username'];
?>
Then everywhere you want to print their username just do this...
PHP Code:
<?php echo $_SESSION['username']; ?>
and when you want to log them out you can do this...
PHP Code:
<?php
$_SESSION = array();
session_destroy();
?>
Keep in mind this does nothing for input validation. You want to make sure you do not fall victim to XSS or SQL injection if you end up using a database. There is a tutorial around by chsh for input validation and another by catch on shoestring sql stuff I think. Do a search here so you can try and avoid such things. Hope this helps.
-
October 12th, 2006, 06:05 AM
#3
Senior Member
Now is the moment, or NEVER!!!
-
October 15th, 2006, 06:30 AM
#4
Senior Member
Hi,
I am able to start the sessions but unable to destroy them.
I have created a logout.php file in which I have written the following code.
<?php
@session_unset();
$_SESSION = array();
@session_destroy();
?>
and in all other php files i have written the code to start the session.
Please help.
Now is the moment, or NEVER!!!
-
October 15th, 2006, 08:19 AM
#5
Is it giving you an error or are you just still logged in?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|