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

  • SEARCH
  • Home
  • 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 7548489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:42:41+00:00 2026-05-30T09:42:41+00:00

i having problem with sessions in localhost, the problem is the session doesn’t work

  • 0

i having problem with sessions in localhost, the problem is the session doesn’t work actually when it redirects to new post page it response’s as you should login first

Login code

<?php
include '../Class/db.class.php';
include '../Class/validation.class.php';
@session_start();
if(!$_SESSION['user']){
    $link=$_GET['dir'];
    if($link){
echo <<<EOF
<html> <head><title>ورود</title></head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<form method='post' action='index.php?dir=$link'>
  Username: <input type='text' name='user'><br />
 password<input type='password' name='pass'><br />
  <input type='hidden' name='hidd' value=1>
    <input type='submit' value='login'><br />
</form>
EOF;
    }
 else {
    echo <<<EOF
<html> <head><title>login</title></head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<form method='post' action='index.php'>
   username: <input type='text' name='user'><br />
 password: <input type='password' name='pass'><br />
  <input type='hidden' name='hidd' value=1>
    <input type='submit' value='login'><br />
</form>
EOF;
    }
}
$db=new db("localhost", "root", "", "blog");
$con=$db->connect();
$logout=$_GET['logout'];
$user=$_POST['user'];
$pass=$_POST['pass'];
$hidden=$_POST['hidd'];
if($hidden){
if(!$user){
    echo "username field can't left blank";
}
 elseif (!$pass) {
    echo 'password field can't left blank!';

}
else{
    $userres=$db->usersearch($user, $pass);

    if($userres==FALSE){
        echo 'username or password is wrong';
    }
 else {
       $_SESSION['user']=$user;

    }
}
}
if($_SESSION['user']){
  $link=$_GET['dir'];


echo "you logged in ".$_SESSION['user']; 
if($link=="new")
    echo  '<meta http-equiv="REFRESH" content="0;url=../admin/post/new.php">';

}

if($logout)
    session_destroy();
if($_SESSION['user'])
echo '<br /><a href="?logout=1">logout</a>';

?>

new post code

<?php
@session_start();

if($_SESSION['user']=="admin"){
   include '../../Class/db.class.php';
echo <<<EOF
<form method=post action="new.php">
 <br />   subject:
    <br />
    <input type="text" name="title"><br />
   post:<br />

   <textarea cols=50 rows=10 name="post"></textarea><br />
    <input type="submit" value="send">

EOF;
$title=$_POST['title'];
$post=$_POST['post'];
$db=new db("localhost", "root", "", "blog");
$db->connect();
if($title && $post){

   $d=$db->post_insert($title, $title, 1);
    if($d==TRUE)
            echo "post created";
    else
        echo "an error occurred while sending the post";




}

$dd=$db->read(0, 20);
for($i=0;$i<20;$i++){
   echo $dd['content'][$i]."<br />";
}

}
else
{
    echo "you should login first";
    echo $_SESSION['user'];
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>

please help me!

  • 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-05-30T09:42:42+00:00Added an answer on May 30, 2026 at 9:42 am

    The fact you’re suppressing error output from session_start() with the @ symbol suggests that session_start is reporting errors that you’re ignoring.

    If it’s reporting errors, you should look at the error it’s generating to determine what’s wrong.

    Usually, session_start fails due to headers having already been sent. This happens if your script outputs any text before session_start is called. Once headers have been sent, the session cannot be started as it depends on sending headers.

    The fix for this is to make sure that session_start is the first thing to happen in your script. As session_start happens as the first thing after your includes, then this means there’s either whitespace at the start of your script, or whitespace or statements that generate output in the scripts you include. You need to check the included files and fix any white space (anything that’s outside of the PHP tags) and check that they don’t output anything until the session_start occurs.

    On a side note, never use @ for error suppression. It’s the coding equivalent of sweeping potentially serious problems that need to be addressed under the carpet.

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

Sidebar

Related Questions

I'm having a problem with java sessions. I'm developing a simple web app, where
i'm having an weird problem, my project have a login page, that's working, but
I'm teaching myself Zend am and having a problem with using my session to
I'm having a problem with Express under Node.js. I'm trying to use sessions to
Right now I'm having a weird problem with my own written session class, the
I'm having a problem where my session variables aren't getting set/saved. Here is my
I am having a problem of setting the data of a (persistent/cross browser session)
I'm having an odd problem with my sessions. I haven't found a solution even
I'm having problems with retrieving multiple instances of a session variable from an InProc
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how

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.