Fake Directory Name returns Value

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
VKX
Forum Commoner
Posts: 41
Joined: Mon Oct 03, 2005 1:43 pm

Fake Directory Name returns Value

Post 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?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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");
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply