Hi,

im having a mental breakdown,
iv created a script where a user will type a password into a box and if it matches the one in the config file then it creates a session.

on all of my pages i have the following code.

<? 
session_start();
if(!session_is_registered(admin)){
header("location:login.php");
}
ini_set('display_errors','Off');
?>

but the problem im having is if i host the script somewhere else and go directly to the index.php page it doesnt ask for the password.

it should in theory redirect me to login.php

can anyon help

Member Avatar for nileshgr

if the name of the session you are initiating on login is admin then you need to put it in quotes.

in your code admin becomes a global constant and since you have turned errors off, you are not redirected to the login page.

use this -

if(!session_is_registered('admin'))) // NOTE THE QUOTES

i should have added,

this only happens when i log in on one site and then try to go into a differnt site using my script.

i think i need to add somesecurity to the sesson

Member Avatar for nileshgr

i should have added,

this only happens when i log in on one site and then try to go into a differnt site using my script.

i think i need to add somesecurity to the sesson

Didn't get you :icon_question:

check the PHP version of your hosting server

I need to know the easiest way I can learn PHP as a begginer

session register or whatever doesnt work anymore.
i guess u have to set a variable to check if there is a session already started.
if the variable is empty akak $_SESSION[variablename] == ""
then there wasnt a session. make sure u set the variable to equal somethin when the session starts tho

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.