hi everybody i have a question : I am writing a website and i havee a drop down menu. when the user is logged out he can see part of the menu and when hi is logged he see the other part. i hide the menu with <?php if(isset($logged)){ ?> <?php } > . also in the index file where is the menu i switch sites as ../?page='some number'. How to lock the number which are inside this code , because when i try change the number in the addressbar of my browser and write one which should be for a logged user i can see it. i will be very thankful if you show me an example because i am still new in php but it's interesting :D Thank you in advance :)
Ichcha 0 Light Poster
use PHP $_SESSION variable: set a variable in the session global array and use it by calling session_start() at the top of the script.
example test1.php
session_start();
$_SESSION['value'] = 'This variable was set on page test1.';
echo '<a href="test2.php">Session testing</a>';
test2.php
session_start();
echo $_SESSION['value'];
Edited by Ichcha because: n/a
Raimucka 0 Newbie Poster
Ans is it possible to see your code? I don't know if I understand the current code.
But my guess is it has to look something like this:
<?PHP
//first part testing is user is loged in with realy existing username and pass
$user = $_GET["username"]; //or POST["username"]
$pass= $_GET["password"]; //or POST["password"]
//some code testing if username with this password exists in database or just pasword is = to something. And it it is, then:
$logedin = 1;
}
?>
...
//part where there is menu seen to all
...
<?php
if($logedin == "1"){
?>
//menu seen ju loged in ones
<?php
}
?>
I don't know what type of login autentification you use, so my code is not full.
I hope it did some good, if not, just add some cone of login and of nenu part.
if login and menu pahes are diferent you can use url for username and pas carying like
website/index.php?id=manupage&username=name&password=mypassword
or write something to cookies.
spawn2004 0 Newbie Poster
i try several things but i didn't have any success. My code is
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<HEAD>
<link rel="stylesheet" href="css/dipl.css" type="text/css"/>
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<link href="css/styletext.css" rel="stylesheet" type="text/css" />
<link href="css/profilebutton.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Деца със специални образователни потребности</title>
</HEAD>
<BODY>
<center>
<div style="width:850px;">
<div id="logged">
<?php
session_start();
if(isset($_SESSION['user'])){
$logged=$_SESSION['user'];
print "Здравейте, ".$logged." ";
print "<a class='logged' href='../?page=49'>Профил</a><a class='logged' href='actionpages/logout.php'>Изход</a></li>"; }
else{
?>
</div>
<div><a href="../?page=48" style=" margin-top:3px; margin-left:15px; font-size:18px; float:left; color:#CC0033; ">Забравена парола.</a></div>
<div style=" padding:2px; text-align:right;">
<?php
if(isset($_POST['login'])){
include"actionpages/dbconnect.php";
$user=stripslashes($_POST['username']);
$pass=stripslashes($_POST['password']);
$user=mysql_real_escape_string($user);
$pass=mysql_real_escape_string($pass);
$pass=md5($pass);
$sql="SELECT * FROM account_data WHERE mail='$user' AND pass='$pass'";
$result=mysql_query($sql) or die(mysql_error());
$check=mysql_fetch_array($result);
$_SESSION['status']=$check['status'];
if($_SESSION['status']!=1)
{
print ("<font color='red'>Грешни e-mail или парола.</font>");
}
else {
$num=mysql_num_rows($result);
if($num==1)
{
session_start();
$sqldata=mysql_fetch_array(mysql_query("SELECT * FROM account_data WHERE mail='$user' AND pass='$pass'"));
$_SESSION['user']=$sqldata['FirstName'];
$_SESSION['email']=$sqldata['mail'];
header("location:../index.php");
}
}
}
?>
<form name="loginf" method="post" action="">
<span style="color:#CC0033; font-size:13px;">E-mail: </span><input type="text" name="username" style="padding:2px; width:120px; height:15px; border:1px #c7a158 solid; background:#f6d28d; color:#002EB8; font-size:13px;">
<span style="color:#CC0033; font-size:13px;">Password: </span><input type="password" name="password" style="margin-left:2px; padding:2px; width:120px; height:15px; border:1px #c7a158 solid; background:#f6d28d; color:#002EB8; font-size:13px;">
<input type="submit" name="login" value="Login" id="login"/>
</form>
</div>
<?php }?>
<div id="logo"><img src="images/logo.jpg"/></div>
<div id="menu" >
<ul class="dropdown">
<li><a href="../?page=1">Новини</a></li>
<li class="sub"><a href="../?page=2">Заболявания</a>
<ul>
<li><a href="../?page=3">Синдром на Даун</a></li>
<li><a href="../?page=4">Аутизъм</a></li>
<li><a href="../?page=5">Аспергер</a></li>
<li><a href="../?page=6">Синдром на Рет</a></li>
<li><a href="../?page=7">Фетален алкохолен синдром</a></li>
<li><a href="../?page=8">Синдром на дефицит на вниманието (Хиперактивност)</a></li>
</ul>
</li>
<li><a href="../?page=9">Организации</a></li>
<?php if(isset($logged)){ ?>
<li class="sub"><a href="../?page=10">Интеграция</a>
<ul>
<li><a href="../?page=11">Интеграция в България и проблеми</a></li>
<li><a href="../?page=12">Интеграция в детските градини</a></li>
<li><a href="../?page=13">Интеграция в училищата</a></li>
</ul>
</li>
<li class="sub"><a href="#">Предмети и Е-Обучение</a>
<ul>
<li class="dir"><a href="#">I клас</a>
<ul>
<li><a href="#">Български език</a></li>
<li><a href="#">Математика</a></li>
<li><a href="#">Роден край</a></li>
<li><a href="#">Музика</a></li>
<li><a href="#">Изобразително изкуство</a></li>
<li><a href="#">Домашен бит и техника</a></li>
<li><a href="#">Физическо възпитание и спорт</a></li>
</ul>
</li>
<li class="dir"><a href="#">II клас</a>
<ul>
<li><a href="#">Български език</a></li>
<li><a href="#">Математика</a></li>
<li><a href="#">Околен свят</a></li>
<li><a href="#">Музика</a></li>
<li><a href="#">Изобразително изкуство</a></li>
<li><a href="#">Домашен бит и техника</a></li>
<li><a href="#">Физическо възпитание и спорт</a></li> </ul>
</li>
<li class="dir"><a href="#">III клас</a>
<ul>
<li><a href="#">Български език</a></li>
<li><a href="#">Математика</a></li>
<li><a href="#">Човек и общество</a></li>
<li><a href="#">Човек и природа</a></li>
<li><a href="#">Музика</a></li>
<li><a href="#">Изобразително изкуство</a></li>
<li><a href="#">Домашен бит и техника</a></li>
<li><a href="#">Физическо възпитание и спорт</a></li>
</ul>
</li>
<li class="dir"><a href="#">IV клас</a>
<ul>
<li><a href="#">Български език</a></li>
<li><a href="#">Математика</a></li>
<li><a href="#">Човек и общество</a></li>
<li><a href="#">Човек и природа</a></li>
<li><a href="#">Музика</a></li>
<li><a href="#">Изобразително изкуство</a></li>
<li><a href="#">Домашен бит и техника</a></li>
<li><a href="#">Физическо възпитание и спорт</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="../?page=50">Прикачи урок</a></li><?php } ?>
<li><a href="#">Форум</a></li>
<li><a href="../?page=52">Контакти</a></li>
<?php if(!isset($logged)){ ?><li><a href="../?page=53">Регистрация</a></li><?php } ?>
</ul>
</div>
<div id="main">
<div style="margin:20px;">
<?php
include('switch.php');
?>
</div>
</div>
<div id="footer"></div>
<br /><br />
</div>
</center>
</BODY>
</HTML>
so where is
session_start();
if(isset($_SESSION['user'])){
$logged=$_SESSION['user'];
print "Здравейте, ".$logged." ";
print "<a class='logged' href='../?page=49'>Профил</a><a class='logged' href='actionpages/logout.php'>Изход</a></li>"; }
else{
i have to set some session timeout
and the aother part is line 80 :
<?php if(isset($logged)){ ?>
where i should check for users if they are logged in to see tgis part of the menu
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.