Anim8r Posted December 11, 2011 Share Posted December 11, 2011 Hi my name is Aidan and I am new here. Me and my friends are making a Social Network just for fun and to help us learn PHP in a more fun way. We are wanting to know if there is way to cover up the GET in the URL bar. For example when your visiting a user's profile it will say in the URL bar: www.com/profile.php?id=<userid> I also know that this is what Facebook do for their profile system. However they also have a feature called 'usernames' which allows you to get facebook.com/<anything> which replaces facebook.com/profile.php?id=<userid> I was wondering how I would be able to implement this. Many thanks, Aidan Quote Link to comment https://forums.phpfreaks.com/topic/252924-covering-up-with-any-text/ Share on other sites More sharing options...
phoenixx Posted December 11, 2011 Share Posted December 11, 2011 Just have it pull the username associated with the row id in the database. Quote Link to comment https://forums.phpfreaks.com/topic/252924-covering-up-with-any-text/#findComment-1296696 Share on other sites More sharing options...
Anim8r Posted December 11, 2011 Author Share Posted December 11, 2011 Just have it pull the username associated with the row id in the database. Could you please provide a code example? Quote Link to comment https://forums.phpfreaks.com/topic/252924-covering-up-with-any-text/#findComment-1296697 Share on other sites More sharing options...
phoenixx Posted December 11, 2011 Share Posted December 11, 2011 Sorry, misunderstood the question. Try using a custom 404 page and use the following: $userid=explode ("/",$url); // requested URL echo $userid[1]; // or $userid[3] if using http://www.domain.com/id instead of just www file_get_contents("http://mydomain.com/404.php?id="); //to reflect the output of the requested user Quote Link to comment https://forums.phpfreaks.com/topic/252924-covering-up-with-any-text/#findComment-1296699 Share on other sites More sharing options...
xyph Posted December 11, 2011 Share Posted December 11, 2011 The 'correct' way to do this is using mod_rewrite. This is an Apache directive, but other server will have an equivalent. This is beyond the scope of this forum, but there's plenty out there. Googling it will return TONS of information. Quote Link to comment https://forums.phpfreaks.com/topic/252924-covering-up-with-any-text/#findComment-1296704 Share on other sites More sharing options...
Anim8r Posted December 11, 2011 Author Share Posted December 11, 2011 Thank you guys. The 404 page thing worked great, FYI if anyone else wants to do something similar heres what I'm using now: <?php include_once "scripts/connect_to_mysql.php"; ///Connects to DB $username = $_SERVER['REQUEST_URI']; /// Gets the username from the URL (incl a forward slash) $username = ltrim($username, '/'); /// Removes the forward slash $sql = mysql_query("SELECT id FROM myMembers WHERE username='$username'"); /// Queries the DB, matches the usernames and returns the user's ID while($row = mysql_fetch_array($sql)){ /// Sets the variable $id from the DB $id = $row["id"]; } $profilelocation = "http://domain.com/profile.php?id=$id"; /// Sets the user's profile link $page = file_get_contents($profilelocation); echo $page; /// echos out the final profile page ?> Regards, Anim8r Quote Link to comment https://forums.phpfreaks.com/topic/252924-covering-up-with-any-text/#findComment-1296952 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.