problem with session

Hello im new coder and i like php but i have some problems with sessions at the last php version!

My code is:

[code]<?php
ob_start();
include(“conf.php”);
session_start();
if(!session_is_registered(myusername))
{
header(“location:index.html”);
}
$user=$_SESSION[‘myusername’];

$query=“SELECT * FROM admin where user=’$user’”;
$result=mysql_query($query);
$row = mysql_fetch_array( $result );
$userid=$row[‘id’];
?>[/code]

but i recieve an error
Deprecated: Function session_is_registered() is deprecated

Can you help me to fix my code to work… and where im wrong ? :slight_smile:
Thanks in advice! :slight_smile:

Change this line
[php]if(!session_is_registered(myusername))[/php]
To this
[php]if(!isset($_SESSION[‘myusername’]))[/php]

Nothing happened when i try to Login! Just stay on login screen! :slight_smile:
This is my check login php file code

[php]

<?php ob_start(); include("conf.php"); session_start(); $myusername = $_GET["myusername"]; $myusername1 = htmlspecialchars($myusername); $mypassword = $_GET["mypassword"]; $mypassword1 = htmlspecialchars($mypassword); $query = "SELECT * FROM admin WHERE user = '$myusername1' AND pass = '$mypassword1' "; $result=mysql_query($query); $totalnum = mysql_num_rows($result); if (mysql_num_rows($result)>0){ // Rister $myusername and redirect to file "admin.php" session_register('myusername'); header("Location: admin.php"); } if($totalnum==0){echo "Wrong username or password

[ назад ] " ;} ?>

[/php]

Well first off, your login script is totally not secure period. I honestly would scrap this whole thing and find some good tutorials on youtube and start over. Check out the phpacademy stuff on youtube, Alex has a ton of great tutorials.

But for your current issue, it would seem that you are not actually assigning a value to the $_SESSION[‘myusername’], you’re only setting it but not giving it a value. Try replacing this line
[php]session_register(‘myusername’);[/php]
With this
[php]$_SESSION[‘myusername’] = $myusername1;[/php]
But seriously, scrap this and start over.

Sponsor our Newsletter | Privacy Policy | Terms of Service