Page 1 of 1

Fake Directory Name returns Value

Posted: Tue Feb 21, 2006 1:25 pm
by VKX
If I send a user to a page (say http://www.tbmchicago.com/somekindauniquename) how can I make it so they get moved to http://www.tbmchicago.com/index.php and $username gets set to somekindauniquename?

Posted: Tue Feb 21, 2006 1:27 pm
by josh
The script will have to POST it to that page using http://www.php.net/curl your other page will have access to it in the standard $_POST superglobal array

Posted: Tue Feb 21, 2006 1:28 pm
by feyd
mod_rewrite for part 1.
part 2, you can't. The best you can do is set an environment variable then fetch it from php or stick the information in the redirected/rewrote url.

Posted: Tue Feb 21, 2006 2:12 pm
by s.dot
mod_rewrite to a script that will assign a unique name for $username

IE

Code: Select all

// if traffic's sparse this will do
$username = time();

// this will do if traffic's heavy
$username = sha1(uniqid(1));
Either set a cookie or session variable and then redirect to index.php using header("Location: index.php"); You could also stick it in the url.

Posted: Tue Feb 21, 2006 2:15 pm
by s.dot
Oh, I read wrong.

mod rewrite something like this

Code: Select all

RewriteEngine On

RewriteRule ^([a-z0-9]+)$ redirect_script.php?username=$1
Redirect_script.php

Code: Select all

session_start();
$_SESSION['username'] = $_GET['username'];
header("Location: index.php");

Posted: Tue Feb 21, 2006 3:12 pm
by pickle
Doing what ~scrotaye said will work, but you *can* change it a bit to not even worry about tacking on the $username. $_SERVER['REQUEST_URI'] won't be rewritten, so you can still get the requested dir from there:

.htaccess

Code: Select all

RewriteEngine On
RewriteRule ^.+$ redirect_script.php
redirect_script.php

Code: Select all

list(,$username) = explode('/',$_SERVER['REQUEST_URI']);
This particular code is untested, but I use this theory on my website and it works beautifully.