PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Dec 10, 2018 12:27 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: Tue Mar 13, 2012 2:22 pm 
Offline
Forum Commoner

Joined: Fri Feb 24, 2012 10:56 am
Posts: 70
does this code have something to do with it?
Syntax: [ Download ] [ Hide ]
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );


I am supposed to add code for cookies because I have no code for that

I searched for username is all the pages of my code and heres the result:
Syntax: [ Download ] [ Hide ]
Search "userName" (29 hits in 6 files)
  C:\wamp\www\project\header.php (1 hits)
        Line 26:        echo 'Hello <b>' . ($_SESSION['userName']) . '</b>. <a class="item" href="signout.php">Sign out</a>';
  C:\wamp\www\project\topic.php (2 hits)
        Line 46:        users.userName
        Line 71:        <td class="user-post">' . $posts_row['userName'] .  '</td>
  C:\wamp\www\project\signin.php (10 hits)
        Line 19:                Enter Username: <input type="text" name="userName" /><br />
        Line 19:                Enter Username: <input type="text" name="userName" /><br />
        Line 28:                if(!isset($_POST['userName']))
        Line 30:                $errors[] = 'The username field must not be empty.';
        Line 54:                userName,
        Line 59:                userName = '" . mysql_real_escape_string($_POST['userName']) . "'
        Line 59:                userName = '" . mysql_real_escape_string($_POST['userName']) . "'
        Line 87:                $_SESSION['userName']   = $row['userName'];
        Line 87:                $_SESSION['userName']   = $row['userName'];
        Line 92:                echo 'Welcome, ' . $_SESSION['userName'] . '. <br /><a href="index.php">Return to home page</a>.<br/>';
  C:\wamp\www\project\signup.php (13 hits)
        Line 11:                Enter a Username: <input type="text" name="userName" /><br />
        Line 11:                Enter a Username: <input type="text" name="userName" /><br />
        Line 22:        if(isset($_POST['userName']))
        Line 24:                if(!ctype_alnum($_POST['userName']))
        Line 26:                $errors[] = 'The username can only contain letters and digits.';
        Line 28:                elseif(strlen($_POST['userName']) > 45)
        Line 30:                        $errors[] = 'The username cannot be longer than 45 characters.';
        Line 34:                        $sql = mysql_query("SELECT userID FROM users WHERE userName='".$_POST['userName']."' LIMIT 1");
        Line 34:                        $sql = mysql_query("SELECT userID FROM users WHERE userName='".$_POST['userName']."' LIMIT 1");
        Line 38:                        $errors[] = 'The username already exists please choose another.';
        Line 45:                $errors[] = 'The username field must not be empty.';
        Line 87:                                        users(userName, userPassword, userEmailAddress ,userDate, userLevel)
        Line 88:                                VALUES('" . mysql_real_escape_string($_POST['userName']) . "',
  C:\wamp\www\project\signout.php (1 hits)
        Line 41:        $_SESSION['userName'] = NULL;
  C:\wamp\www\project\connect.php (2 hits)
        Line 6: $username = "root";
        Line 11: if(!mysql_connect($host, $username, $password))

are any of these lines storing username?


Top
 Profile  
 
PostPosted: Wed Mar 14, 2012 2:35 pm 
Offline
Forum Commoner

Joined: Fri Feb 24, 2012 10:56 am
Posts: 70
hello?


Top
 Profile  
 
PostPosted: Wed Mar 14, 2012 3:25 pm 
Offline
Jack of Zircons
User avatar

Joined: Thu Nov 09, 2006 9:30 pm
Posts: 4484
Location: California, USA
Quote:
are any of these lines storing username?

Well, anyplace that says $userName = something is storing something in that variable.

But that's not really going to help you, since there's only one script running at a time and unless it's the script that is causing the problem, it doesn't matter. Start with telling us, step by step, what you are doing and what scripts are being run (in other words, what is the URL that is showing in the browser address bar at the time the problem occurs). Something like this:

User logs in from login page, signin.php.
User logs out from logout page, signout.php.
User closes the browser.
User opens the browser again.
User returns to main page, header.php.
User's name appears in header.php, even though he has logged out.

This is the only way we can possibly get any idea of what's going on. If we can isolate it to the script, we may then ask you to post that entire script, but if you do, please remember to use the [PHP Code] button in our Post A Reply form, to make it easier for us to read.


Top
 Profile  
 
PostPosted: Wed Mar 14, 2012 3:46 pm 
Offline
Forum Commoner

Joined: Fri Feb 24, 2012 10:56 am
Posts: 70
ok so user signs in from sign in page, signin.php
user returns to home page, index.php and name appears in userbar, header.php (i #included the header file to all pages)
user closes brower
user opens brower again
user returns to home page, index.php
user's name still in userbar


Top
 Profile  
 
PostPosted: Wed Mar 14, 2012 3:48 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6424
Location: Montreal, Canada
So after having closed the browser, the user is not required to sign in again? Is that right? If so, please post the complete index.php and header.php code. Please also post the output of the following
Syntax: [ Download ] [ Hide ]
var_dump($_COOKIE);
var_dump($_SESSION);

after having closed and re-opened the browser.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Mar 14, 2012 3:52 pm 
Offline
Forum Commoner

Joined: Fri Feb 24, 2012 10:56 am
Posts: 70
ok the user is still sign in when i reopen the brower so the name is still in the userbar
heres is the index page:
Syntax: [ Download ] [ Hide ]
<?php
//index.php
include 'connect.php';
include 'header.php';

$sql = "SELECT
                        categories.categoryID,
                        categories.categoryName,
                        categories.categoryDescription,
                        categories.sticky,
                        COUNT(topics.topicID) AS topics
                FROM
                        categories
                LEFT JOIN
                        topics
                ON
                        topics.topicID = categories.categoryID
                GROUP BY
                        categories.categoryName, categories.categoryDescription, categories.categoryID
                ORDER BY
                        sticky
                        DESC"
;
               

$result = mysql_query($sql);

if(!$result)
{
        echo 'The categories could not be displayed, please try again later.';
}

else
{
        if(mysql_num_rows($result) == 0)
        {
                //no categories have been made yet
                echo 'No categories defined yet.';
        }
        else
        {
                //make the table
                echo '<table border="1">
                          <tr>
                                <th>Category</th>
                                <th>Last topic</th>
                          </tr>'
;      
                       
                while($row = mysql_fetch_assoc($result))
                {                              
                        echo '<tr>';
                                echo '<td class="leftpart">';
                                        echo '<h3><a href="category.php?id=' . $row['categoryID'] . '">' . $row['categoryName'] . '</a></h3>' . $row['categoryDescription'];
                                echo '</td>';
                                echo '<td class="rightpart">';
                               
                                //fetch last topic for each category
                                        $topicsql = "SELECT
                                                                        topicID,
                                                                        topicSubject,
                                                                        topicDate,
                                                                        topicCategory
                                                                FROM
                                                                        topics
                                                                WHERE
                                                                        topicCategory = "
. $row['categoryID'] . "
                                                                ORDER BY
                                                                        topicDate
                                                                DESC
                                                                LIMIT
                                                                        1"
;
                                                               
                                        $topicsresult = mysql_query($topicsql);
                               
                                        if(!$topicsresult)
                                        {
                                        //error
                                                echo 'Last topic could not be displayed.';
                                        }
                                        else
                                        {
                                                if(mysql_num_rows($topicsresult) == 0)
                                                {
                                                        echo 'no topics';
                                                }
                                                else
                                                {
                                                        while($topicrow = mysql_fetch_assoc($topicsresult))
                                                        echo '<a href="topic.php?id=' . $topicrow['topicID'] . '">' . $topicrow['topicSubject'] . '</a> at ' . date('d/m/Y', strtotime($topicrow['topicDate']));
                                                }
                                        }
                                echo '</td>';
                        echo '</tr>';
                }
        }
}

include 'footer.php';
?>
 


and here is the header page:
Syntax: [ Download ] [ Hide ]
<html>
<head>
        <title>PHP-MySQL forum</title>
        <link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<h1>Forum</h1>
        <div id="wrapper">
        <div id="menu">
                <a class="item" href="/project/index.php">Home</a> -
                <a class="item" href="/project/create_topic.php">Create a topic</a> -
               
                <?php
                if(isset($_SESSION['signed_in']) == true && $_SESSION['userLevel'] == 1)
                {
                        echo "<a class=\"item\" href=\"/project/create_cat.php\">Create a category</a> -
                        <a class=\"item\" href=\"/project/delete_cat.php\">Delete a category</a> -
                        <a class=\"item\" href=\"/project/delete_topic.php\">Delete a topic</a>"
;
                }
                ?>
               
                <div id="userbar">
                <?php
                if(isset($_SESSION['signed_in']) == true)
                {
                        echo 'Hello <b>' . ($_SESSION['userName']) . '</b>. <a class="item" href="signout.php">Sign out</a>';
                }
                else
                {
                        echo '<a class="item" href="signin.php">Sign in</a> or <a class="item" href="signup.php">create an account</a>';
                }
                ?>
                </div>
                </div>
                <div id="content">
 


sorry don't know what you mean with show the output for var_dump($_COOKIE); and var_dump($_SESSION);


Top
 Profile  
 
PostPosted: Wed Mar 14, 2012 3:54 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6424
Location: Montreal, Canada
Add that code to the top of header.php. It will produce output onscreen. Copy/paste that output here, please.

At a glance, I don't see anything unusual about either of the files you've posted and it still isn't clear to me why the user isn't being signed out.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Mar 14, 2012 3:59 pm 
Offline
Forum Commoner

Joined: Fri Feb 24, 2012 10:56 am
Posts: 70
do you mean copy it on the top of my index.php page because if i put it in header.php it just prints var_dump($_COOKIE);var_dump($_SESSION);

when I put it into index.php it says
array
'PHPSESSID' => string 'gp372hfr0arechepo65aq5tc90' (length=26)

and then the message
( ! ) Notice: Undefined variable: _SESSION in C:\wamp\www\project\index.php on line 3

null




Top
 Profile  
 
PostPosted: Wed Mar 14, 2012 4:07 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6424
Location: Montreal, Canada
There's no reason it shouldn't work in header.php. You did enclose it in <?php ?> tags, right?

Worst case, post the entire script here, along with a database dump, and I'll set it up locally and take a look.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Mar 14, 2012 4:38 pm 
Offline
Forum Commoner

Joined: Fri Feb 24, 2012 10:56 am
Posts: 70
yes all php tags are closed. I'll will take another close look at all the code and if I still can't find the problem I'll post all the code here


Top
 Profile  
 
PostPosted: Wed Mar 14, 2012 5:51 pm 
Offline
Jack of Zircons
User avatar

Joined: Thu Nov 09, 2006 9:30 pm
Posts: 4484
Location: California, USA
I can't see any reason that it doesn't work, either. I don't have time today to really debug it.


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 1:18 am 
Offline
Forum Newbie

Joined: Thu Apr 12, 2012 2:28 am
Posts: 3
It tell you that indeed the username session variable is not defined, so it was destroyed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group