Help about Php

Started on the old forum in December 2012 · view the original in the archive · old links redirect here

3 replies · 1,035 views · started 13 years ago · 1 min read

3 participants
Dr_BIoLoGY Junior · 35 posts #1

I'm making a website script for the Garment. So I already added login page and it is working perfectly. But the problem is anyone can just type any .php page name and can access those pages. I need to avoid that problem. So i need to know how to add session expiration for those pages. It will avoid my problem. If anyone need to access my website, they have to login through login page. Because session will blocking for the unauthorized access. Pleases anyone can give some advice to avoid my problem.

http://wap.asialk.com/images/logo.gif If u want any help.Plz contact me.ill help u http://asialk.com

kevk3v Senior · 332 posts #2

Add to the top of exery page

session_start();

put this where login is successful

$_SESSION["user"] = "username"; ///<-can be any values 

Add this to the pages that you want to protect

if(isset($_SESSION["user"]))
{
///logged in
}
else
{
////not logged in
}

to log out users

session_destroy();

Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

Dr_BIoLoGY Junior · 35 posts #3

kevk3v wrote: Add to the top of exery page

session_start();

put this where login is successful

$_SESSION["user"] = "username"; ///<-can be any values 

Add this to the pages that you want to protect

if(isset($_SESSION["user"]))
{
///logged in
}
else
{
////not logged in
}

to log out users

session_destroy();

Thank You Friend. But i already added cookies for my website.

http://wap.asialk.com/images/logo.gif If u want any help.Plz contact me.ill help u http://asialk.com

arnage Lead · 811 posts #4

If its sql based use something like this:

function users() { 
 $username = !empty($_SESSION['username']) ? safe_query_function($_SESSION['username']) : null; 
 $password = !empty($_SESSION['password']) ? safe_query_function($_SESSION['password']) : null; 
 if (isset($username, $password)) { 
  $query = mysql_query('SELECT * FROM `users` WHERE `username` = "'.$username.'" AND `password` = "'.$password.'" LIMIT 1'); 
  return (bool) (mysql_num_rows($query) > 0); 
 } else { 
  return false; 
 } 
} 
if (users()) { 
// in the bussines 
} 

See also: http://coding-talk.com/f60/protecting-your-users-session-url-session-vars-%24_session-%24_cookie-17514/#post98932

And post the codes in the matter, its so much easier to help ppl. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close