Session_register(); - what do I do to fix it?

I’m making an admin site and I’m having problems with the session_~ codes
I understand that they have been taken out since PHP 5.4, but I don’t know how to create the same code in the new language…
is this correct? I want it to send to success.php if the login was successful, if not i want it to head back to the admin index.php

[php]<?php
session_start();
if($_SESSION[“inloggning”]!=true){
header(“location:index.php”);

}
include("…/connect.php");
?>
[/php]

Also, how would I destroy it?
logout.php
[php]

<?php session_start(); session_unregister("inloggning"); session_unset(); session_destroy(); header("location:index.php"); ?>[/php]

In the admin-site .phps I’ve added codes so that people can’t access it if they haven’t logged in with the admin account, but I dont know if they are correctly written anymore since the language has been developed.

for example, category.php
[php]

<?php session_start(); if($_SESSION["inloggning"]!=true){ header("location:index.php"); } include("../connect.php"); ?>[/php]

When using SESSION remember that:
[php]session_start();[/php]
should used before any html is output to the browser, therefore, use session_start(); before html doctype.

Here is your code.
[php]

<?php session_start(); if (empty($_SESSION['inlogging'])){ header ('Location: index.php'); exit(); } include("../connect.php"); ?>

[/php]

logout.php
[php]

<?php session_start(); session_destroy(); $_SESSION = array(); header("Location: index.php"); exit(); ?>

[/php]

What tanzeelniazi said, and, you don’t show anywhere where you are setting the session vars.

I’m not sure I follow, the way I wrote it is the exact same I would when I learned php (y. 2009). If there is something new I need to add, I have probably missed it :confused:

The only thing that you have shown that is deprecated in 5.3 and removed in 5.4 is session_unregister(). You should use:
[php]unset($_SESSION[“inloggning”]);[/php]

Anywhere else where you have used session_register() you should change to:
[php]$_SESSION[“inloggning”] = true; //or whatever the case may be[/php]

I don’t know, I ended messing everything up =7

I did this instead to the main pages

[php]<?php
$_SESSION[“login”] = true;
/* if (empty($_SESSION[“login”])){
header (‘Location: index.php’);
exit();

} placeholding*/
include("…/connect.php");
include(“checklog.php”);
?>[/php]

checklog.php being:
[php]<?php
$_SESSION[“login”] = true;

if (!isset($_SESSION[“login”]) || $_SESSION[“login”] !== true) {
header(“Location: index.php”);
exit;
}?>[/php]

logout i think is missing something:
[php]<?php
$_SESSION[“login”] = true;
if (isset($_SESSION[“login”])) {
unset($_SESSION[“login”]);
}

header(“Location: index.php”);
?>[/php]

Also now, I’m having issues logging in, with this being the logon.php that’s supposed to bring me to the success.php-page
[php]

<?php $_SESSION["login"] = true; header ('Location:success.php'); /* if (empty($_SESSION["login"])){ header ('Location: index.php'); exit(); }*/ include("../connect.php"); include("checklog.php"); ?> <?php $Password= mysql_real_escape_string(stripslashes($_POST['Password'])); $Username = mysql_real_escape_string(stripslashes($_POST['Username'])); $Password = md5($Password); $sql="SELECT * FROM admin WHERE Username = '$Username' AND Password = '$Password'"; $result=mysql_query($sql) or die(mysql_error()); $count=mysql_num_rows($result); if($count==1){ } else { header("location:index.php"); exit(); } ?>

[/php]

getting a bit frustrated with myself…

Sponsor our Newsletter | Privacy Policy | Terms of Service