fffanatics
Jun 3 2005, 06:08 PM
Hey everyone. I am having some trouble accessing the same php class instance in more that one page. This is for my login script and what i need to do is be able to call the classes logout function from a separate page. What i have tried to do is create a new .php page and include the class file and then make a new class and call logout. This does not work because it does not log out the current user which is my problem. Can anyone help me fix this or know of another way to do it? Below is my class file CODE <?php // member class // handlers member logon class member_class { var $message = '';
var $query_error = 'ERROR: something went wrong when accessing the database. Please consult your webmaster'; function member_class() { //constructor if (!isset($_SESSION['id'])) { //fills session with empty values $this->set_session_defaults(); } if ($_SESSION['logged_in']) { //already logged in $this->check_session(); } if (isset($_COOKIE['remember'])) { $this->check_remembered($_COOKIE['remember']); } } function register($username,$password, $email, $firstname, $lastname, $website, $show_email, $remember) { $username = mysql_escape_string($username); $password = mysql_escape_string(md5($password)); $result=mysql_fetch_array(mysql_query("SELECT * FROM user WHERE username = '{$username}'"), MYSQL_ASSOC); if (!$result) { //insert record if user name doesn't exist $date = date("F j, Y", time()); $insert = mysql_query("INSERT INTO user VALUES ('', '$username', '$password', '$firstname', '$lastname', '', '', '', '', '$date', '$email', '$website', '$show_email', 0)") or DIE ($this->query_error); $result = mysql_fetch_array(mysql_query("SELECT * FROM user WHERE username = '{$username}' AND password = '{$password}'"), MYSQL_ASSOC) or DIE ($this->query_error); header('Location: index.php'); $this->set_session($result,$remember,true); //log user on return true; }//if else { $this->message .= 'Username already exists! Please choose a different name.'; return false; }//else } function check_login($username,$password,$remember) { $username = mysql_escape_string($username); $password = mysql_escape_string(md5($password)); $result=mysql_fetch_array(mysql_query("SELECT * FROM user WHERE username = '{$username}' AND password = '{$password}'"), MYSQL_ASSOC);
if ($result) { $this->set_session($result,$remember,true); return true; }//if else { $this->failed = true; $this->logout(); $this->message .= 'Incorrect username or password.'; return false; }//else }//check_login function logout() { // blowup cookie setcookie('remember',time()-3600); $this->set_session_defaults(); } function set_session($result,$remember,$init = true) { $id=$result['id']; if ($init) { $session = mysql_escape_string(session_id()); $ip = mysql_escape_string($_SERVER['REMOTE_ADDR']); $newtoken = $this->token(); // generate a new token $update = mysql_query("UPDATE user SET session='{$session}', token='{$newtoken}', ip='{$ip}' WHERE id='{$id}'") or DIE ($this->query_error); } $_SESSION['id'] = $result['id']; $_SESSION['username'] = htmlspecialchars($result['username']); $_SESSION['token'] = $newtoken; $_SESSION['logged_in'] = true; if ($remember) { $this->update_cookie($newtoken); } } function update_cookie($token) { $cookie = serialize(array($_SESSION['username'],$token)); setcookie('remember',$cookie, time()+12099600); } function check_remembered($cookie) { $serializedArray=$cookie; $serializedArray = stripslashes($serializedArray); list($username,$token) = unserialize($serializedArray); if(empty($username) or empty($token)) { return; } else { $username = mysql_escape_string($username); $token = mysql_escape_string($token); $ip = mysql_escape_string($_SERVER['REMOTE_ADDR']); $result = mysql_fetch_array(mysql_query("SELECT * FROM user WHERE username = '{$username}' AND token ='{$token}' AND ip = '{$ip}'"), MYSQL_ASSOC) or DIE ($this->query_error); if (!$result) { $this->set_session($result,false,false); }else{ $this->set_session($result,true,true); } } } function token() { // generate a random token for($i=1;$i<33;$i++) { $seed .= chr(rand(0,255)); } return md5($seed); } function check_session() { $username = mysql_escape_string($_SESSION['username']); $token = mysql_escape_string($_SESSION['token']); $session = mysql_escape_string(session_id()); $ip = mysql_escape_string($_SERVER['REMOTE_ADDR']); $result = mysql_fetch_array(mysql_query("SELECT * FROM user WHERE username='{$username}' AND token='{$token}' AND session='{$session}' AND ip='{$ip}'"), MYSQL_ASSOC) or DIE ($this->query_error); if ($result != false){ }else{ $this->logout(); } } function set_session_defaults() { $_SESSION['logged_in'] = false; $_SESSION['id'] = 0; $_SESSION['username'] = ''; $_SESSION['password'] = ''; $_SESSION['cookie'] = 0; $_SESSION['remember'] = false; } } ?>
Reply
fffanatics
Jun 8 2005, 03:22 AM
Well since no one answered my post, i actually figured this one out myself. I just had to include the correct files and recreate the variable which would pick up the Session variables during its initialization and do the correct procedures. For any one interested or needs help doing something like this let me know.
Reply
Recent Queries:--
$_session["token"] - 60.45 hr back. (1)
-
php setcookie from drop down choice - 101.72 hr back. (1)
-
php session multiple folders - 186.05 hr back. (1)
-
set_session php - 202.58 hr back. (1)
-
php include class instance problem - 216.02 hr back. (1)
-
$_session php "new window" - 379.03 hr back. (2)
-
phpclasses session - 452.42 hr back. (1)
-
problems pagination "next link" "blank page" like php mysql - 513.01 hr back. (1)
-
how to hack logged_in function - 533.21 hr back. (1)
-
class php data access - 650.79 hr back. (1)
-
rember php instance other pages go back - 722.89 hr back. (1)
-
get existing instance php class - 726.53 hr back. (1)
-
php classes multiple session - 730.65 hr back. (1)
-
php delete class instance - 737.13 hr back. (1)
Similar Topics
Keywords : php, classes, access, class, instance, multiple, pages
- Ms-access Database Question
Allowing Web Access to the Informaton (3)
Pagination
? (3) People they create the databases in which like the news stories are placed. Then that news stories,
they are placed on certain page to be displayed and readable by other users on the web-site. How
people do that thing paging, like you can see bottom, whenever, you go to Any CMS engines. Need the
concept how you can create, 1, 2 or 3 pages, then next and back buttons, last and beginning page.....
Protect Pages
HOW? (20) I create certain pages for my web-site, and I would like to protect them that no one can hack or see
their source codes. So, if everybody knows how to do it, please post a reply over here. List of
the best ways, I can do it. Thanks.....
2 Pages Into One
how? (10) Hello, now this may be a stupid question but i'm very new to php so i need some help. what
i'm wanting to do is combine 2 pages in to one. like for example the install.php for
invisionpower board it starts with one page and you click continue and it gives you a whole new page
but if you look at the url you are still using the install.php file but it has somethinglike "?a=2"
at the end. how can i do this. Thanks....
Php Pages Problem [resolved]
Please help me im stuck ;-( (5) Hi, i have been working with a wap forum script, translating from russian and fixing errors etc..
but now im stuck, the problem is with the pages while viewing a forum.. Let me explain.. the pages
are set to show ten topics per page which all works fine as you can see in these screenshots: page
1: page 2: The problem occurs when there are PINNED topics (with the redish folder), it will
show ten topics but also the pinned ones on page one, and the "Next" link will appear before it
should leading to a blank page where there should be topics but they are still on th....
Php An Js Window.open Pages Trouble.
I need a way to set hidden input values to the new window. (3) I have 2 main pages Page A(events_locked.php) and Page B(add_attendance.php). Both are php files.
Page A takes a post var from another page(not Page B ) and then used to query for displaying records
in a mysql datase. This variable has set as a session variable because there is 1 <script
LANGUAGE="JavaScript"> window.name="main_index"; function openFormWindow() {
OpenWindow=window.open("add_attendance.php", "newwin", "height=250,
width=400,toolbar=no,scrollbars=no,menubar=no,location=no,resizable=no"); var x =
getElementByName("form1"); x.target="newwin"; x.s....
Multiple Drop Down Lists ?
Multiple drop down lists to take user to new page (4) Hi everyone I was wondering if anyone could help. I want to create a page with multiple drop down
lists and depending what the user selects decides the page they will be taken to. Sorry i havent
explained this too well. Here is an example of what i want (link below) the user is also emailed a
copy http://www.dermalogica.com/SpeedMappingOnl...US®ion=B I have searched the web and come
close but nothing does it right I would be extremely greatful if anyone could help! Thanks ....
Using Multiple Selection Array In Table To Order Data
Using multiple selection array in table to order data (1) have a form that has a multiple select choice, like this: CODE <form method="post"
action="display.php" <select multiple name="selectsort[]">
<option value="code">Code</option> <option
value="amount">Amount</option> <option value="dateammended">Date
Ammended</option> <option value="expreviewdate">Expiration/Review
Date</option> <option value="effectivedate">Effective Date</option>
<option value="e....
Php Pages Permission On Apache Server
PHP pages permission on Apache Server (1) Hello, I want to know what permissions for PHP pages should be given on Apache web server so that
PHP pages can be executed. If PHP pages are in a folder, what permissions should be given for that
folder? ....
Grabt Access To My Protected Files
grabt access to my protected files (2) Hi all, I am sure all of you are great programers but First i am no code programmer i am just
trying to learn to run my sites, will the problem is i got a code from the web to protect my files
,1st i want to know how to work it out then i will try other things but can't let it go without
a fight thanx all php: CODE <?php if ( ! defined( 'myname' )
) { print "You cannot access this file directly."; exit(); }
customer data here ?> now i can't access my files what is the meth....
Putting Data Of 2 Pages In Mysql At Once
(1) suppose i have a page, page.php?part=1 there i have some text fields. user will give input, but
after taking input, it will not put the data in mysql .. but it will take to the next step..
page.php?part=2 (if any field is left blank, it will not go to next page.. ) . and there also some
fields.. after the user has filled that form also, then it will insert all data (from part1 and
part 2) in mysql. i want to ask, how i can collect data from 2 pages and put in mysql at once.....
Dynamic Php Pages
Nice tutorial (5) This is a really good tutorial on making php pages that normally appear as
www.domainname.com/links.php appear as www.domainname.com/index.php?page=links
http://nuwen.com/tutorials/php-dynamic-pages ....
Evilboard (forum Software) - Multiple Categorys - Don't Work :(
I am creating a forum and i can't fix more then 1 category. (6) I am at the moment trying to program my own forum, but i need more then a single category, here is
my source: CODE function cat () { include("functions/functions.php");
echo '<table width="100%" border="0" cellspacing="0">
<tr> <td class="eb_top" colspan="3" style="border-bottom-width:
0; height: 30px; font-size: 12px;"> <b>Forum</b></td>
</tr>'; global $catid; $db = new db; $db->connec....
I Need Webmail On My Server
(so admins on my site can access it) (0) Right now, if i go to the cpanel of my site, I can access webmail of any of the email addresses I
have. Unfortunatly, I would prefer it if the administrators did not know the password to the
cpanel. I want them to be able to access mail from 1 of the email accounts. I have tried letting
all the admins access the account through their own cliants, but it became a mess, not knowing wich
admins have responded to which emails, because most emails are hosted localy when received by
cliants such as outlook. Then I had the idea of making one page, with webmail on it. Where....
How To Access A Folder In Php Page
(1) I have a folder on my hosting space..(i.e. public_html), i want to add this folder on my php page..,
. how it should be done that, when i add some file in the folder using ftp or anything , the folder
on that page automatically includes that file.for example , if the folder has 5 files..and on page
it says "folder has 5 files" and shows the files...and when i have uploaded 2 more files ,it should
automatically say that folder has 7 files.. ....
Multiple Options?
(3) Okay so what Im trying to figure out is how I would go about giving the people to uh, well for
examplkes sake it would be like "how many cats do you have" then theyd fill in a number, submit and
the next page would print out boxes for as many cats they have that will be too fill in a color of
the cat, so basically something like that, where it will only give them so many fields based on how
many they said they have, and then their final "reciept" will only print out stuff for as many as
they filled itn ....
Restricting Page Access Using Php (need Help)
(10) The code below is suppose to restrict access to pages without proper username and password.
I've copied it word for word from a book I bought and I've tested it offline. I've
already entered appropriate values in the database and nothing is wrong when I query. The problem
is when I enter a wrong combination of username and password nothing happens when it should go back
to index.html. Also when I correctly entered the username and password secretpage.php doesn't
display anything. I'm guessing it has do with the setcookie function in login.php or ....
Search Site Pages Using Keywords?
(6) We're doing a "Mock" e-commerce site for our project in Web Development and I was wondering how
to make a Search form like the ones in many sites. There will be a Search textbox and a button in
the form which will accept a string (keywords) which will then be processed by a script. If there
is a match, a page containg the keywords will be displayed. Is there a way to do this using PHP or
is there an existing free script out there already? Thanks very much.....
How Handle Sending Back Multiple Checkboxes
(1) I know how to send back the check-boxes, so that's not the issue. I have a form that contains a
group of 5 check-boxes. The user could select none, one, all, or any combination in between.
I'm working on form validation right now and am doing most of it server side. The validation is
set so that if the user has to go back all their data is retained. I'm using case statements,
which work wonderfully, but in this circumstance I don't know what would be the best method that
allows for a multitude of combinations. I think there is a possibility of somethi....
Changing Include Tag On All Pages
(11) I want to change an include tag (include menu.htm) to include menu.php on all my pages on my
website. Is there any fast way to do this, or do I have to edit all of my pages manually?
/unsure.gif' border='0' style='vertical-align:middle' alt='unsure.gif' /> ....
Parsing .html Pages
(9) This isn't really that urgent but I was wondering, I read somewhere that you can configure you
server to pars all html pages for php code, and I was wondering if that was true, and if trap17 has
that feature enabled?....
Blocking Pages & Making Ranks
(4) I would like to know how and where to put the code that would block certain pages so people could
only get to them if they logged in. And I would like to have ranks on the site and when you get to a
certain rank you get more options like being able to add members and stuff. And also. I would like
some code for a news sytem for the homepage. Like where you have to be logged in to post something
and only people with certain ranks will have access to it and only certain people can delete it. I
would like to be able to make it so on the members page it displays members and y....
Securing Pages
(2) just wondering if there is a easy safe way to secure some webpages. i have a payment facility on my
site which is linked through paypal. when the member has paid they are taken back to my site "thanks
your payment has been successful page", once its went to this page the item is no longer listed on
my site. now i have found away people can mess with this using the url. this means people can
change just a few digits in the url and and mess the listings up on my site. after payment has been
made the member is redirected to:- mydomain.com/class/thanks_paypal.php?myprod_....
Php Sessions
Multiple users using the same login (2) Hi, I'm realtively new to PHP and I'm considering creating some login functionality.
However I want a group of users to use the same loginname and password. They will be loggin infrom
different machines. The users will know they are sharing the account. Can anyone give me an idea
of what kind of effect this might have on my sessions? Will it create any odd hiccups or other
strange things?....
Pages In 1 File
?? (9) I know its possible to put many pages inside 1 file. But how? Lets say you have a guestbook with
different pages for signing and viewing. How to make so those pages are in 1 file? /huh.gif"
style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" />....
Embeding Pages
(3) Is there a way to have php act as an iframe? I dont want to have to change every single page when i
want to move something around. If anyone can give me a tutorial or somethign telling me how that
would be great, or ven another way of doing this without frames.....
Looking for php, classes, access, class, instance, multiple, pages
|
*RANDOM STUFF*
*SIMILAR VIDEOS*
Searching Video's for php, classes, access, class, instance, multiple, pages
*MORE FROM TRAP17.COM*
|
advertisement
|
|