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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.