First foray into OOP: Correct implementation?

  • (8 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »

113 Replies - 8196 Views - Last Post: 23 March 2013 - 11:52 PM Rate Topic: -----

#31 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 08:42 AM

View PostDarkranger85, on 26 February 2013 - 04:19 PM, said:

Wish me luck and tell my family I love them.

good luck.

and for the next Id need a phone number or such.
Was This Post Helpful? 0
  • +
  • -

#32 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 10:11 AM

Alright, need a little help with directory paths because it's hindering my search for the elusive array.

Here is my directory that we are talking about:

core>functions

Inside core there is the connection.php and init.php.
Inside functions is the general.php and user.php.

On my init file I have the connection script included like so:

include 'core/connection.php';

But it says that it can't find it.

I also tried '/core/connection.php' and that didn't work either.

What am I missing?

EDIT: So far I've done print_r at the top of every page that includes init.php and the $errors array has an empty array in it from the very beginning.

But I declare it as $error = array();.

lol I found the problem, though I'm ashamed to admit it. . .

I declared the array like this $errors[] = array();

So I ended up putting an array into the first element of the array. . . .

This post has been edited by Darkranger85: 26 February 2013 - 10:09 AM

Was This Post Helpful? 0
  • +
  • -

#33 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 11:31 AM

View PostDarkranger85, on 26 February 2013 - 06:11 PM, said:

Inside core there is the connection.php and init.php.

On my init file I have the connection script included like so:

include 'core/connection.php';

read again with care.

if that doesn’t help, try echo __DIR__;

This post has been edited by Dormilich: 26 February 2013 - 11:31 AM

Was This Post Helpful? 0
  • +
  • -

#34 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 12:16 PM

Sigh. . .

I don't know why I keep missing these little things. And it's not like I just have a problem and post a question. . . I actually sat there looking at that path for a while. . .

Sometimes I think I need a new brain.

After that, I think I'm going to take another look at the problem I'm having now. It's probably stupid and I don't want to make myself look like a bigger fool than I already am.

This post has been edited by Darkranger85: 26 February 2013 - 12:18 PM

Was This Post Helpful? 0
  • +
  • -

#35 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 12:40 PM

You are not a fool and I doubt you are being perceived as one by anyone here. You have questions and you are trying to find answers while working through problems as well as you can on your own. The fool would be the one who remains ignorant :).
Was This Post Helpful? 1
  • +
  • -

#36 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 12:58 PM

Alright, I'm getting closer but I'm a little puzzled. Big surprise. I just hope to God the solution doesn't end up to be staring me in the face.

In my login script after it validates the user input it sets the session etc etc. I know that this works because as you can see I have a die in there and when I do it outputs the correct user id from the database.

else{
			$_SESSION['user_id'] = $login;
			die($_SESSION['user_id']);
			header('Location: index.php');
			exit();
		}



So, thinking I'm successfully setting the session, I check for it on another page to see if the page should display a login box or a user profile.

	<?php
		if (check::loggedIn()){
			include 'includes/modules/logged_in.mod.php';
		} else{
			include 'includes/modules/login.mod.php';
		}						
	?>




However when I call the following function to check if a user is logged in, it fails and triggers the else block in the above snippet.

	public static function loggedIn(){
	//Calling scripts: init.php
		return (isset($_SESSION['user_id'])) ? true : false;
	}


Was This Post Helpful? 0
  • +
  • -

#37 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 01:18 PM

two things: did you start the session in that another page? second, isset() already returns a boolean, no need for that ternary there.

and maybe a third, if error reporting is disabled, you may not see the "header already sent" error (should setting the session cookie fail).
Was This Post Helpful? 0
  • +
  • -

#38 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 04:21 PM

Ok, I'll fix the ternary. Thanks! :)

Error reporting is on. As for the session, I'm pretty sure it has a session.

See, the other file is a file that is included into the index page though it's in a separate folder. I include init.php on the index page and init starts with ob_start() and session_start().

So if the file is included into index.php wouldn't it have access to the init.php file aswell?
Was This Post Helpful? 0
  • +
  • -

#39 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,869
  • Joined: 12-December 12

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 04:37 PM

View PostDarkranger85, on 26 February 2013 - 12:16 PM, said:

Sigh. . .

I don't know why I keep missing these little things. And it's not like I just have a problem and post a question. . . I actually sat there looking at that path for a while. . .

Sometimes I think I need a new brain.

After that, I think I'm going to take another look at the problem I'm having now. It's probably stupid and I don't want to make myself look like a bigger fool than I already am.

It is good that you are persisting, and taking on board the advice given to you here. You might be encountering difficulties along the way but you are also learning a lot :smartass:

Quote

So if the file is included into index.php wouldn't it have access to the init.php file aswell?

If you have already included a file then, yes, you should have access to the classes, functions, variables, etc., defined in that file. A simple way to check is to define a variable in the included file and then echo it from the other file.
Was This Post Helpful? 1
  • +
  • -

#40 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 04:42 PM

You guys are awesome!

Seriously, you have no idea how much you have encouraged me.

I'm naturally a very self conscious person and I doubt myself so when I have a lot of questions that I see as stupid questions I think that everyone around me is seeing me as some annoying moron that should just go away lol.

Scripting and design is like the first skill that I have ever started to learn and had a true interest in, almost to where it's becoming a passion. I've spent 9+ hours in front of this computer watching videos, reading guides, etc etc.

Honestly, after all the stupid simple errors that have puzzled me for days I was beginning to think that you guys might think I'm retarded. lol

Thanks guys!

However I'm still pounding my head on the keyboard lol.

This post has been edited by Darkranger85: 26 February 2013 - 08:44 PM

Was This Post Helpful? 0
  • +
  • -

#41 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 08:53 PM

Ok, I can't figure this out.

The page has session access, I echoed out a variable on the init script. The session data is successfully passed to the loggedIn() function.

So I'm dumbfounded. . :(
Was This Post Helpful? 0
  • +
  • -

#42 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 10:09 PM

try var_dump($_SESSION); to check if and what is missing.
Was This Post Helpful? 0
  • +
  • -

#43 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 11:49 PM

This is what it comes up with.

array (size=1)
  'user_id' => string '1' (length=1


Was This Post Helpful? 0
  • +
  • -

#44 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: First foray into OOP: Correct implementation?

Posted 26 February 2013 - 11:52 PM

then loggedIn() should return true (well, var_dump() that as well).
Was This Post Helpful? 0
  • +
  • -

#45 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: First foray into OOP: Correct implementation?

Posted 27 February 2013 - 12:02 AM

boolean false


Was This Post Helpful? 0
  • +
  • -

  • (8 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »