Jump to content

[SOLVED] PHP Sessions help required


daveeboi

Recommended Posts

I have been trying to restrict a page opening to users that aren't logged into my site but I have tried loads of different alternatives but to no avail.

 

I have recently tried :

 

<?
session_start();
if(!session_is_registered(myusername)){
header("Location: login.php");
}
?>

 

and

 

<?
  session_start();
  if(!isset($_SESSIOIN['myusername'])){
   header("Location:login.php");
}
?>

 

But niether of them worked.

 

Within my log in process I take in the username and password and pass it to checklogin.php where the session register part is done.

session_register("myusername");

 

I really can't see where I am going wrong and have spent hours attempting to alter it.  Any advice right now would be fantastic.

 

 

Link to comment
https://forums.phpfreaks.com/topic/114942-solved-php-sessions-help-required/
Share on other sites

session_is_registered and session_register were depreciated long ago in php4.2 in the year 2002, when register_globals were turned off (they don't work unless register_globals are on.)

 

If the code you posted is actual code, $_SESSIOIN is spelled incorrectly.

 

You should be setting a value using code similar to this -

 

<?php
session_start(); // once at the start of any page using sessions
$_SESSION['myusername'] = "whatever";
?>

 

and to reference a value on a different page -

 

<?php
session_start(); // once at the start of any page using sessions
if(!isset($_SESSION['myusername'])){
header("Location: login.php");
}
?>

Thanks for the advice.  I had noticed the spelling mistake after my post.

 

I had tried putting that different decleration in my checklogin.php in place of thr session register line and also altered the php at the top of my page as you had suggested but when testing it still just opens up the target page even though I am not logged in.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.