Jump to content

[SOLVED] Sessions


Racc

Recommended Posts

Basically I've known php/mysql for a couple days.  After tons of reading and creating pages and a site as I go along, i've gotten stuck.

 

Basically this is my nav include.  I had threw logout in there and tried doing all sorts of nonsense. =P

 

<div id="nav">
<a href="?s=main" title="main" id="main"><span>Main</span></a> ~ 
<a href="?s=login" title="login" id="login"><span>Login</span></a> ~ 
<a href="?s=register" title="register" id="register"><span>Register</span></a> ~ 
<a href="?s=blog" title="blog" id="blog"><span>Blog</span></a> ~ 
<a href="?s=downloads" title="downloads" id="downloads"><span>Downloads</span></a> ~ 
<a href="?s=tutorials" title="tutorials" id="tutorials"><span>Tutorials</span></a> ~ 
<a href="?s=author" title="author" id="author"><span>Author</span></a> ~ 
<a href="?s=links" title="links" id="links"><span>Links</span></a>
</div>

 

This is my index coding.

 

<?php
include("include/session.php");
if (isset($_GET['s']))
$s = $_GET['s'];
else
$s = "main";
include("includes.php");
?>
<div id="content">
<?php
if ($s == "main") {
include("content/main.php");
} else if ($s == "login") {
include("content/login.php");
} else if ($s == "register") {
include("register.php");
} else if ($s == "blog") {
include("content/blog.php");
} else if ($s == "downloads") {
include("content/downloads.php");
} else if ($s == "tutorials") {
include("content/tutorials.php");
} else if ($s == "author") {
include("content/author.php");
} else if ($s == "links") {
include("content/links.php");
}	else {
echo "<p class=\"error\">The section $s does not exist!</p>\n";
}
?>
<?php
include("footer.php");
?>
</div>
</body>

 

When Logged in i'd like it to say "logout" and when i'm logged out "log in".  Though i'd like it in the navigation.  This is what it looks like as of now, I still have alot of coding to do. (I left the "log in" link there so you will get a feel for what i'm talking about and where I'm trying to put the link.)

 

previewxi3.jpg

 

Thanks!  Let me know.  ???

Link to comment
Share on other sites

your navigation would have to look like this. (note you may need to change the name of your session.

 

<div id="nav">
<a href="?s=main" title="main" id="main"><span>Main</span></a> ~ 

<?php
if(!isset($_SESSION['user'])){
?>
<a href="?s=login" title="login" id="login"><span>Login</span></a> ~ 
<?php }else{ ?>
<a href="?s=logout" title="logout" id="logout"><span>Logout</span></a> ~ 
<?php } ?>

<a href="?s=register" title="register" id="register"><span>Register</span></a> ~ 
<a href="?s=blog" title="blog" id="blog"><span>Blog</span></a> ~ 
<a href="?s=downloads" title="downloads" id="downloads"><span>Downloads</span></a> ~ 
<a href="?s=tutorials" title="tutorials" id="tutorials"><span>Tutorials</span></a> ~ 
<a href="?s=author" title="author" id="author"><span>Author</span></a> ~ 
<a href="?s=links" title="links" id="links"><span>Links</span></a>
</div>

 

i hope you understand. :)

Link to comment
Share on other sites

hmm.

 

When I try logging in I get this.

 

Fatal error: Call to a member function login() on a non-object in C:\xampp\htdocs\process.php on line 60

 

Then I go to line 60..

 

    $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));

 

I'm still VERY VERY new, i'd apprieate even more help if it's not too much of a bother.  Thanks for the quick response.  :)

Link to comment
Share on other sites

well its saying that the function login doesnt exist in the class session. check.

 

The thing is...

 

I figured out why i'm having such a hell of a time.  I include session.php in index.php.  Then I'd had it included in process.php (the logout) aswell.

 

This is where it fucks up.  I run the process.php (by clicking on logout), then "blah blah errors"  which means that it was included twice and you can't do that.  So I clear my cookies and cache, delete the inclusion from process.php.  I then go back to the site and click login, woo! looks like smooth sailing.  I then try to login and get this error. (such as last time)

 

Fatal error: Call to a member function login() on a non-object in C:\xampp\htdocs\process.php on line 60

 

Thanks for the reply last time. =D

 

*chronically presses f5*

Link to comment
Share on other sites

hmm.

 

When I try logging in I get this.

 

Fatal error: Call to a member function login() on a non-object in C:\xampp\htdocs\process.php on line 60

 

Then I go to line 60..

 

    $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));

 

And pardon my language.  You know, I could be a jerk because you were rude for NO reason.  "What's in line 60!?"  ::)

 

And yes it exists.

Link to comment
Share on other sites

eek, sorry i didnt see the post above. :)

 

anyways. so $session is your class, could you please search the class for a function called login. or just attach the file which contains the class $session.

thanks.

 

It's okay, I just got a little frustrated when I saw "Hey idiot I told you!"

 

I switched a few things around, I now have new errors. =| I made login.php, process.php, and register.php all include "include("include/session.php");" rather then including it in the index.php.  I now get this error when I click "login.php" and when I click "Register.php".

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\index.php:2) in C:\xampp\htdocs\include\session.php on line 46

 

And I will include the index.php line 2 ~ 10ish. and Will include session.php line 46.

 

46:      session_start();   //Tell PHP to start the session

 

and

2: <?php
3: if (isset($_GET['s']))
4:	$s = $_GET['s'];
5: else
6:	$s = "main";
7:	include("container.php");
8:	include("header.php");
9:	include("nav.php");
10: ?>

Link to comment
Share on other sites

session_start() must be at the very top of your page, right below <?php no whitespaces.

 

and sorry if this is stupid and you answered it in that post but whats this code:

2: <?php
3: if (isset($_GET['s']))
4:	$s = $_GET['s'];
5: else
6:	$s = "main";
7:	include("container.php");
8:	include("header.php");
9:	include("nav.php");
10: ?>

Link to comment
Share on other sites

session_start() must be at the very top of your page, right below <?php no whitespaces.

 

and sorry if this is stupid and you answered it in that post but whats this code:

2: <?php
3: if (isset($_GET['s']))
4:	$s = $_GET['s'];
5: else
6:	$s = "main";
7:	include("container.php");
8:	include("header.php");
9:	include("nav.php");
10: ?>

 

That would be my index.  line: 2 ~ 10.  Or are you asking what all it does? (which is quite odd sense you seem to know what you're doing.)

 

EDIT: almost there, I can now login, register and logout...sorta. =P  The logout page gives and error but logs out anyway.

 

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\container.php:1) in C:\xampp\htdocs\process.php on line 82

 

I'm still playing aroudn with it, I'm so close. O_O

Link to comment
Share on other sites

Oddly enough I cannot edit my post anymore, the forum will not allow me to. O_O  Either way, I deleted line 82, just for kicks.  It worked! No error...but the redirection obviously doesn't work. I'll have to work on that. =P

 

Thanks for all your help, as far as i'm concered you did your job helping me, i'll set this as case solved or whatever.  If you have any suggestions on the other part just send me a message or whatever.

 

EDIT:

 

(2:34:16 AM) Racc: =P

(2:36:01 AM) Racc: I LOVE YOU!

 

Thanks for the help, much apprietiated

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.