Jump to content

PHP & htaccess


elite311

Recommended Posts

I have been reading a lot on this and I can't seem to find the answer, I have a protected directory with .htaccess and I'm wondering if there is a way I can have the PHP script enter the password on the url redirect? Basically I only want the directory to be able to be accessed from my site so I created and SQL database with "id", "site", "url" and then a web form. If the user enters "testsite" and it matchs the "site" in the SQL it redirects the browser to that site. The script works great but the user would have to enter the .htaccess username and password in the popup and I'd like the site to just do that automatically in the background.

 

header('Location: ' . $project_info['url'])

 

I thought I could do something like this

 

header('Location: username:password ' . $project_info['url'])

 

or

 

header('Location: ' . $htuser . $htpass . $project_info['url'])

 

But that doesn't work and I'm not even sure what I'm trying to do is possible.

Link to comment
https://forums.phpfreaks.com/topic/252435-php-htaccess/
Share on other sites

it's most likely easier to have a login system using sessions

 

on top of the page the session would start

 

if user is logged in continue, else redirect them somewhere else or to login

 

the login process would check if it's a proper user and password

 

There was a tutorial online that I edited it so it worked

http://www.phpfreaks.com/forums/index.php?topic=338735.msg1596372#msg1596372

 

use this for the sql


CREATE TABLE IF NOT EXISTS `dbusers` (
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(32) collate utf8_unicode_ci default NULL,
  `password` char(32) collate utf8_unicode_ci default NULL,
  `email` varchar(32) collate utf8_unicode_ci default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

 

I myself took this code here and modified it a lot for my own use

http://www.evolt.org/node/60265

 

Ther may have been a few errors in it, can look through the comments or ask me and maybe I'll whip up a version of my edited one.

Link to comment
https://forums.phpfreaks.com/topic/252435-php-htaccess/#findComment-1294290
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.