Hi! I have some some sections in my site and I use a header for each of them. In my header file I have the next code:
Every section require this php file. And I have file: login.php:PHP Code:<?php
session_start();
?>
<div id="kazan">
<div id="gore">
<?php
if(empty($_SESSION['username']))
{
require('login/reg_data.php');
}
?>
<div id="begin"><a href="index.php">Начало</a></div>
</div>
<div id="flash">
<div>
<object id="myId" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="576" height="116">
<param name="movie" value="cat_and_mouse.swf" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="cat_and_mouse.swf" width="576" height="116">
<!--<![endif]-->
<div>
<h1>flash movie clip</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</div>
</div>
<div id="goreright">
<?php
if(!empty($_SESSION['username']))
{
echo '<div id="lognat"><ul><li></li>Здравей,<li><a href="login/members.php">'.$_SESSION['username'].'</a></li></ul>
<p><a href="login/logout.php">Изход</a></p></div>';
}
else if(isset($_SESSION['error'])){
echo '<div class="mistake">';
echo $_SESSION['error'];
echo '</div>';
session_destroy() ;
echo '<form method="POST" action="login/login.php" class="login">';
echo '<label for="name">Име</label><br>';
echo '<input type="text" name="username" size="15" maxlength="13" />';
echo '<label for="password">Парола</label><br>';
echo '<input type="password" name="password" size="15" maxlength="14" />';
echo '<input type="submit" value="Влез" style="margin: 3px 0 0 0; font-size:11px;" />';
echo '<input type="checkbox" name="autologin" value="1" checked="checked" />Помни';
echo '</form>';
}else{
echo '<form method="POST" action="login/login.php" class="login">';
echo '<label for="name">Име</label><br>';
echo '<input type="text" name="username" size="15" maxlength="13" />';
echo '<label for="password">Парола</label><br>';
echo '<input type="password" name="password" size="15" maxlength="14" />';
echo '<input type="submit" value="Влез" style="margin: 3px 0 0 0; font-size:11px;" />';
echo '<input type="checkbox" name="autologin" value="1" checked="checked" />Помни';
echo '</form>';
}
?>
</div>
1 header file and 1 login file. The problem is that in this situation if i am in a section of my site after login I am redirected to index.php. This is uncomfortable for the visitors. I want after login the user to remain on the same pade, where he has been befor login. I can't write php code - only a little editing. Can someone help me with writing this code? Every help will be appreciated. Thank's in advance!PHP Code:<?php
session_start();
require ("dbConfig.php");
$username = addslashes($_POST['username']);
$password = md5(addslashes($_POST['password']));
if($_SERVER['REQUEST_METHOD'] != 'POST') header('Location:../index.php');
if(isset($username) && isset($password)){
$q = mysql_query("SELECT username, password FROM users WHERE username='$username' AND password='$password'LIMIT 1");
if($row=mysql_fetch_array($q)){
$_SESSION['username'] = $row['username'];
header('Location:../index.php');
}else{
$_SESSION['error'] = '<div class="mistake">Грешни данни</div>';
header('Location:../index.php');
}
}
?>


Reply With Quote
Bookmarks