Jessica Posted February 6, 2007 Share Posted February 6, 2007 "Are you sure there's no simple way to redirect www.mysite.com/username to www.mysite.com/userpage.php?id=$userid" mod_rewrite IS the simple way. That's exactly what it's for! Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 As jesirose said, mod_rewrite is the simplest way. However, if you can't access mod_rewrite (like me, my webhost doesn't allow mod_rewrite for some stupid reason) setup a custom error page (let's call it 404.php) with this: <?php $req = $_SERVER['REQUEST_URI']; $reqarr = explode('/', $req); header("Location: http://www.mysite.com/userpage.php?id=".$reqarr[1]); ?> That should do exactly what you need it to. So when somebody access http://www.mysite.com/username it'll transfer to http://www.mysite.com/userpage.php?id=username Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 6, 2007 Author Share Posted February 6, 2007 well...I've gone back to writing a new page...I've got this: $directory = mkdir("/home/koggdesi/public_html/$user[username]", 0777); $file = fopen("$user[username]/index.php","w") or die("Cannot open file!"); $stringData = "header( 'Location: http://www.koggdesigns.co.uk/users/main.php?id=$userid' ) or die("Cannot DO!"));"; fwrite($file, $stringData); fclose($file); yet I get an error: Parse error: syntax error, unexpected T_STRING in /home/koggdesi/public_html/activate.php on line 30 Line 30 is the $stringData = blah line Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 $stringData = "header( 'Location: http://www.koggdesigns.co.uk/users/main.php?id=$userid' ) or die("Cannot DO!"));"; It's your die statement, as the syntax highlight shows. $stringData = "header( 'Location: http://www.koggdesigns.co.uk/users/main.php?id=$userid' ) or die('Cannot DO!'));"; That should do it. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 6, 2007 Author Share Posted February 6, 2007 Thanks I'd also added one extra bracket and left out the <? ?> to write in It now works!!!!!!! BUT next problem is that if somebody has a space in their username their directory comes out funny when you type it in any ideas how to add a - or _ or some symbol inbetween each word? Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 Hmm...don't allow them to register with spaces in their username? Other then that, you might want to do a preg_replace(" ","_",$user[username]) to add them in. Then preg_replace("_"," ",$whatever) to remove them again. Though this in itself would eliminate the ability for a user to have the same name with an underscore where the space is, and vice versa. This is assuming all usernames with a "_" are the same as all usernames with a " ". However, if you used some oddball character, you should be good. There's also urlencode() and urlencode(). Look them up, as they'll allow you to not have to use replacements. Quote Link to comment Share on other sites More sharing options...
alpine Posted February 6, 2007 Share Posted February 6, 2007 Use str_replace() instead of preg_replace() if you don't need fancy replacing rules <?php $username = str_replace(" ", "_", $username); ?> Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 Use str_replace() instead of preg_replace() if you don't need fancy replacing rules Yeah, that there. I forgot about str_replace, and I wanted to reply quickly. x.x Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.