then you have either different keys (line break???) or your method has a different code.
113 Replies - 3965 Views - Last Post: 23 March 2013 - 11:52 PM
#46
Re: First foray into OOP: Correct implementation?
Posted 27 February 2013 - 03:36 AM
#47
Re: First foray into OOP: Correct implementation?
Posted 27 February 2013 - 05:34 AM
Not sure what you mean.
#48
Re: First foray into OOP: Correct implementation?
Posted 27 February 2013 - 08:09 AM
well, if the index is set (var_dump on session), and your method returns false (var_dump on method), something is very wrong there (you could test var_dump(isset($_SESSION['user_id'])); just for fun).
#49
Re: First foray into OOP: Correct implementation?
Posted 27 February 2013 - 03:40 PM
IT also says boolean false.
I dont understand what could be wrong with such a simple function.
I dont understand what could be wrong with such a simple function.
#50
Re: First foray into OOP: Correct implementation?
Posted 27 February 2013 - 04:09 PM
Ok, I might have had a small breakthrough but I'm not sure.
I am now getting an infinite redirect loop.
And I found that it goes away when I comment out the block of code that checks for the user to be active and then logs them out.
So perhaps that block is where the error is and it's destroying the session.
Hmm, after some testing I'm not sure anymore. Cause with that block commented out it seems I can't log out. And var_dumping the session aray on the init script then shows an empty array. . .
I'm really starting to feel overwhelmed.
I'm wondering if there are simply so many things that aren't working right because of my changing from functions to classes that I can't even figure out where the actual issues are coming from.
I am now getting an infinite redirect loop.
And I found that it goes away when I comment out the block of code that checks for the user to be active and then logs them out.
So perhaps that block is where the error is and it's destroying the session.
Hmm, after some testing I'm not sure anymore. Cause with that block commented out it seems I can't log out. And var_dumping the session aray on the init script then shows an empty array. . .
I'm really starting to feel overwhelmed.
I'm wondering if there are simply so many things that aren't working right because of my changing from functions to classes that I can't even figure out where the actual issues are coming from.
#51
Re: First foray into OOP: Correct implementation?
Posted 27 February 2013 - 06:22 PM
I'm wondering between two options.
Should I continue debugging this code, or should I completely redo the script again but this time rather than just copying and pasting functions into classes, reworking it one by one.
Or am I jumping the gun with my frustration and giving up on it too soon?
Should I continue debugging this code, or should I completely redo the script again but this time rather than just copying and pasting functions into classes, reworking it one by one.
Or am I jumping the gun with my frustration and giving up on it too soon?
#52
Re: First foray into OOP: Correct implementation?
Posted 27 February 2013 - 11:11 PM
at this point I recommend to to completely redo it.
#53
Re: First foray into OOP: Correct implementation?
Posted 28 February 2013 - 04:52 PM
Alright
Progress is going well.
The login system and registration system works as expected.
The issue I'm having now is I have two function scripts, I'm trying to call a function from one in the other and it says that it's an undefined variable.
I have the class set in init.php and yet it's not working.
Here's the function, it's the $Check variable that it has a problem with.
Yet on init.php I have
I've double checked spellings and such and everything seems fine.
Progress is going well.
The login system and registration system works as expected.
The issue I'm having now is I have two function scripts, I'm trying to call a function from one in the other and it says that it's an undefined variable.
I have the class set in init.php and yet it's not working.
Here's the function, it's the $Check variable that it has a problem with.
public static function protectPage(){
if(!$Check->loggedIn()){
header('Location: protected.php');
exit();
}
}
Yet on init.php I have
global $Check;
I've double checked spellings and such and everything seems fine.
#54
Re: First foray into OOP: Correct implementation?
Posted 28 February 2013 - 05:05 PM
You shouldn't need to use global, but does init.php instantiate $Check?
global should be used within your function:
global should be used within your function:
public static function protectPage(){
global $Check;
if(!$Check->loggedIn()){
header('Location: protected.php');
exit();
}
}
#55
Re: First foray into OOP: Correct implementation?
Posted 28 February 2013 - 05:30 PM
No, users.php instantiates it.
#56
Re: First foray into OOP: Correct implementation?
Posted 28 February 2013 - 10:16 PM
first, forget global. pass variables if you need them.
second, avoid redirects. you’re inside the script, so you can easily provide the content you want.
though the question remains, why do you have that static method there? it is not related to the class and it uses a foreign object …
public static function protectPage(whatever_intterface_it_is $Check){
if(!$Check->loggedIn()){
header('Location: protected.php');
exit();
}
second, avoid redirects. you’re inside the script, so you can easily provide the content you want.
though the question remains, why do you have that static method there? it is not related to the class and it uses a foreign object …
#57
Re: First foray into OOP: Correct implementation?
Posted 01 March 2013 - 07:30 AM
Ok, lose the globals, pass the variables. Avoid using the redirect, I'll work on that.
Not so sure what you mean by it not being related. I thought protecting a page was related to security.
As for the foreign object. Are you saying it's bad to use it in the first place?
Not so sure what you mean by it not being related. I thought protecting a page was related to security.
As for the foreign object. Are you saying it's bad to use it in the first place?
#58
Re: First foray into OOP: Correct implementation?
Posted 01 March 2013 - 09:31 AM
Darkranger85, on 01 March 2013 - 03:30 PM, said:
Not so sure what you mean by it not being related. I thought protecting a page was related to security.
depends what you understand by security. I would group it (access to restricted content) under "content control".
Darkranger85, on 01 March 2013 - 03:30 PM, said:
As for the foreign object. Are you saying it's bad to use it in the first place?
let me put it this way: you have a method that doesn’t interact with the class and the only object used in that method needs to be imported.
#59
Re: First foray into OOP: Correct implementation?
Posted 01 March 2013 - 09:47 AM
Ok, I passed the variables and such and got it working. I also replaced the header redirect.
EDIT: So I should make a separate class for one method? And if I make a content control class, isn't it going to have the same issue? Having to call on the method to check the users session.
public function protectPage(){
if(!$this->Check->loggedIn()){
include '/includes/overall/header_main.php';
echo '<div class="msg_module">';
echo '<h2>Protected Page:</h2>';
echo 'The page you are trying to access requires you to login.<br /><br />';
echo '<a href="index.php">Login</a>';
echo '</div>';
include '/includes/overall/footer_main.php';
exit();
}
}
EDIT: So I should make a separate class for one method? And if I make a content control class, isn't it going to have the same issue? Having to call on the method to check the users session.
This post has been edited by Darkranger85: 01 March 2013 - 09:51 AM
#60
Re: First foray into OOP: Correct implementation?
Posted 01 March 2013 - 09:55 AM
at this point I usually recommend templates …
one tip for re-useability of objects: don’t echo inside methods, only return. this way you still have the choice what to do with the content.
one tip for re-useability of objects: don’t echo inside methods, only return. this way you still have the choice what to do with the content.
|
|

New Topic/Question
Reply




MultiQuote



|