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 7641037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:49:21+00:00 2026-05-31T08:49:21+00:00

I’m running a login script and according to who logs in I redirect to

  • 0

I’m running a login script and according to who logs in I redirect to one of two pages

If I direct to a page that is in a directory below the main directory all works fine, however if i direct to a page that is above the directory in which the index.php file sits, the session information seems to be lost and the user is asked to login again

I know that I could simply place the second page in a directory below the main directory but I would like to understand if it is possible to maintain the session information when directing to a page above the main directory

the user goes to a page called login.html, when they have input there information, they are sent to login.php, it is here where the redirect occurs

if ($username==$dbusername&&$password==$dbpassoword)
{
    if($admin == "1"){
        header('location: http://www.edit.domain_name.co.uk/');
        $_SESSION['username']=$username;
        $_SESSION['id']=$id;

    }else{
        header('location: /member');
        $_SESSION['username']=$username;
        $_SESSION['id']=$id;
    }
}

I have put session_start (); at the beginning of every page where the user would need to login to access. Any input would be greatly received

the full code for the login script is

<?php
session_start () ;

$username = $_POST['username'] ;
$password = $_POST['password'] ;

################# ADMIN OR NOT   ###################################################

include_once "mysql/global.php";
$result = mysql_query("SELECT admin FROM users WHERE username = '$username'");
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}


$row = mysql_fetch_row($result);

$admin = $row[0];


################# ###############################################################

if ($username&&$password)
{

include "mysql/global.php";

$query = mysql_query("SELECT * FROM users WHERE username='$username'") ;

$numrows = mysql_num_rows($query) ;

if ($numrows!=0)
{

  while ($row = mysql_fetch_assoc($query) )
  {
      $dbusername = $row['username'] ;
      $dbpassoword = $row["password"] ;

  }

  // check to see if they match!
  if ($username==$dbusername&&$password==$dbpassoword)
  {
      if($admin == "1"){
          session_start();
          header('location: http://www.edit.domin_name.co.uk/admin');
          $_SESSION['username']=$username;
          $_SESSION['id']=$id;

      }else{
      session_start();
      header('location: /member');
      $_SESSION['username']=$username;
      $_SESSION['id']=$id;


      }
  }
  else 
      echo "<center>incorrect password!</center>" ;

}
else
    die ("<center>That user does not exist!</center>") ;


}
else
    echo ("<center>Please enter a username and password</center><br/>") ;
    die ("<a href=\"index.php\"><center><b>Click here to try again</b></center></font>");


    ?>
  • 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-31T08:49:22+00:00Added an answer on May 31, 2026 at 8:49 am

    In order to load sessions, you must place session_start() at the top of each page.

    Also, you need to call session_start() before setting them and before redirecting:

    if ($username == $dbusername && $password == $dbpassoword) {
        if($admin == "1"){
            session_start();
            $_SESSION['username']=$username;
            $_SESSION['id']=$id;
            header('Location: http://www.edit.domain_name.co.uk/');
        } 
        else {
            session_start();
            $_SESSION['username']=$username;
            $_SESSION['id']=$id;
            header('Location: /member');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a

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.