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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:33:39+00:00 2026-06-10T06:33:39+00:00

I am currently using a SESSION variable for redirection. Hoprfully code snippets will make

  • 0

I am currently using a SESSION variable for redirection. Hoprfully code snippets will make it clear.

addForm.php:

if (!isset($_SESSION['myusername'])){
            if (isset($_COOKIE['username'])){   
                $_SESSION['myusername'] = $_COOKIE['username'];

            }
        else{   
                #using a session var to redirect back to addForm.php
                $_SESSION['addForm'] = 1;
                header("location:loginForm.php");       
            }
}

LoginSuccess.php

session_start();
if (!isset($_COOKIE['username'])){

    header("location:loginForm.php");
}
if (isset($_SESSION['addForm'])){
    header("location:addForm.php");
}

the above works (redirects to addForm.php). My question is, are there any risks in doing it this way? is there a better way to do it? I guess i’m looking for ‘best practice’.

  • 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-10T06:33:41+00:00Added an answer on June 10, 2026 at 6:33 am

    You have some errors:

    1. The valid header is header('Location: http://www.example.org/script.php'); notice L and full URL?
    2. After each header('Location: http://www.example.org/script.php'); it should be exit();
    3. You cannot rely just on $_COOKIE['username'], you need to have something from password, I mean not the password, maybe an MD5() hashed password in $_COOKIE also. And you should know not to rely on $_COOKIE that much.
    4. In LoginSuccess.php you have to unset($_SESSION['addForm']) before redirection, addForm from session will still be set.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently doing a website in php, we are using a Session variable
I am currently running a simple EJB application using a stateless Session Bean. I
Currently I am loading data from a previous session into my application using the
I currently using android NDK to write some native code in C. I have
I'm currently using inline javascript to clear an input text's default value on focus.
I am currently using the Tonic PHP framework to build a RESTful application (
I am currently populating an array with checkboxes, imploding the array variable and using
I am currently building a PHP application using the MVC pattern. I have implemented
I am currently using session to hold the user ID at my web application.
I'm currently using session variables as a cache to cut down the calls to

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.