|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
SitePoint Member
Join Date: Sep 2004
Location: Virginia
Posts: 23
|
Trouble have CREDS carry over from page1 to page2
I am very new to Basic Auth in PHP. Thus far I have been doing basic auth from the web server itself. I am ready to move on.
The following code seems to work for my initial auth. However, I would like this one auth to suffice for pages and redirects called from "it". Code:
<?
function check_creds($user, $pass) {
if (isset($user) && isset($pass) && $user === strrev($pass)) {
return true;
} else {
return false;
}
}
?>
<?php
if (! check_creds($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
header('WWW-Authenticate: Basic realm="Eric"');
header('HTTP/1.0 401 Unauthorized');
exit;
}
?>
<?php
header('Locaton: page2.php');
exit();
?>
page2.php looks like this... I am certain it is completely wrong. Code:
<?php
require 'auth.php';
if (! check_creds($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
header('WWW-Authenticate: Basic realm="Eric"');
header('HTTP/1.0 401 Unauthorized');
echo "<h1>You must authenticate</h1>";
exit;
}
?>
<H1>Arrived at Page 2</H1>
|
|
|
|
|
|
#2 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2001
Location: Atlanta, GA, USA
Posts: 5,059
|
I like going with sessions.
My recommendation would be to try to get sessions working in the simplest way possible, then look at making a login around it. PHP Code:
Access it via: test.php?var=working Session = working should appear on the page. Then access the page via just test.php If you get the same message, you just got sessions working! |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 14:31.








Hybrid Mode
