.htaccess question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

.htaccess question

Post by Nik »

Hello, i'am making a prog (an elecronik atzenta tha people sign up and the can post or view records. In order for a user to post something when he hist the post button i want a .htaccess window to pop-up and ask him for user and pass! When he gives the correct user and pass then he is ok to post....but the problem is that .htaccess checks the .htpasswd file for username and password and not my mysql table members that has two filelds user and pass. How must i do to point .htaccess to compare the PHP_AUTH_USER and PHP_AUTH_PW to compare its values with my mebers records??
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Send a 401 header from within your script, the browser will pop up the dialoag and resend the request with the given credentials. .htaccess or not the $_SERVER-elements are set and your script can decide wether to accept them or send a new 401.
see also, e.g. viewtopic.php?t=5937
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

Thanks volka i also wantes to ask about this:

<?php
ob_start(); error_reporting(E_ALL); $i=0;
echo "<body background=pics/anemos.bmp>";

if (@mysql_connect('localhost', 'nik', 'macgyver'));
else @mysql_connect('localhost', 'root');
mysql_select_db('db_nik');

$sql=mysql_query("SELECT * FROM member");
while ($row = mysql_fetch_array($sql))
if (($_SERVER['PHP_AUTH_USER']==$row['user']) && ($_SERVER['PHP_AUTH_PW']==$row['pass']))
$i=1;
else
$i=1;

if ($i==1)
{
header('WWW-Authenticate: Basic realm="Ðïéüò åßóáé?"');
die ("<font size=5 color=Cyan> Äåí åßóáé ìÝëïò ôçò ÁôæÝíôáò...ðñÝðåé ðñþôá íá ãñáöôåßò êáé ìåôÜ íá îáíÜñèåéò!!");
}
else
{
$onoma = $_POST['onoma'];
$eponymo = $_POST['eponymo'];
$til = $_POST['til'];
$email = $_POST['email'];
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];

if (isset($_POST['kataxorisi'])) header("Refresh: 1; URL=http://localhost/kataxorisi.php");
if (isset($_POST['emfanisi'])) header("Refresh: 1; URL=http://localhost/emfanisi.php");
if (isset($_POST['metavoli'])) header("Refresh: 1; URL=http://localhost/metavoli.php");
if (isset($_POST['diagrafi'])) header("Refresh: 1; URL=http://localhost/diagrafi.php");
}
?>

How am i gonna be able to give the variables to the selected php scripts?
Post Reply