Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8505677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:23:17+00:00 2026-06-11T02:23:17+00:00

I have my code for setting the session like: if($found>0){ session_start(); $_SESSION[‘user_name’]=$user; session_set_cookie_params(24*60*1,’/’,’.localhost’); $expire=time()+60*60*24;

  • 0

I have my code for setting the session like:

if($found>0){
    session_start();
    $_SESSION['user_name']=$user;

    session_set_cookie_params(24*60*1,'/','.localhost');

    $expire=time()+60*60*24;
    setcookie("cookiename", $user, $expire);

    header("location:http://localhost/UI/user/userprofile.php");
} else{
    $message =  "Username or  password is not correct.";
    header("Location:index.php?message={$message}");
}

here is my header content where i put login and logout

session_start();
if (isset($_COOKIE["cookiename"])){
    $unm = $_SESSION["user_name"];
    echo "User :  " . $_SESSION["user_name"] . "";
    echo " <a href='http://localhost/UI/user/logout.php'>logout</a>";
    echo " <a class='addmeeting' href='http://localhost/UI/user/createmeeting.php' title='Create New Meeting'>Create Meeting</a>";
} else{
    echo "<li><a href='register.php'>Register</a></li>";
    echo " User : Guest!<br />";
}

My session is working for subfolder but it is not working for the parent folder.
Here is the directory structure:

UI 
   user
      userprofile.php
      login.php
      logout.php 
   index.php
   headers.php

Please tell me what i am doing wrong ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:23:19+00:00Added an answer on June 11, 2026 at 2:23 am

    My guess is that it’s the cookie that’s not working, rather than the session (your session code is inside an if() block that checks the cookie first).

    Cookies default to being limited to the current folder, so it won’t apply to the parent folders.

    If you want it to apply to the whole site, you need to specify a / in the cookie, like so:

    setcookie("cookiename", $user, $expire, '/');
    

    This will set the cookie across your entire site, so your code should work.

    However, I don’t really understand why you’re not just using sessions here anyway; why have cookies and sessions in the same context? You may as well set everything in the session and be done with it. (sessions are cookie based anyway)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Session_Start code that looks like this: Sub Session_Start(ByVal sender As
So... is strange, I have the follow code in my Window control for setting
I have some python code using shutil.copyfile: import os import shutil src='C:\Documents and Settings\user\Desktop\FilesPy'
I have code like this in my view model: function ChatListViewModel(chats) { var self
I have a Moose class that i would like to store using Apache::Session::File. However,
I have used session to store some config setting in MVC3 application, in my
I am setting session time in web config. I also have a javascript for
I'm having a problem setting my Session back to Login. Here is my code:
I have some basic jquery code sitting in the header of the header file
I have this code for the settings: Dim settings As XmlWriterSettings = New XmlWriterSettings()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.