Jump to content


check mysql database against the URL

  • Please log in to reply
3 replies to this topic

#1 kurtis

  • Members
  • PipPip
  • Member
  • 13 posts

Posted 08 August 2006 - 10:33 PM

does anyone know how i can get what is after the slash in a URL?
im wanting to edit my 404 error page so if people go to blabla.con/username it will search the database for the username and if its there save all the needed info to a session and forward the reader to profile.php and display the info. All i need is how to get the URL thing i can do the rest but obviously if someone allready has the code somewhere i wouldnt mind them copying it all in  ;D
Also if anyone knows a easyer way to do this then sugestions are welcome :)

#2 SharkBait

  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 08 August 2006 - 10:38 PM

So you're looking for what is after the forward slashes?

Could try exploding the URL
$url = array();

// Can automate it with a $_SERVER['PHP_SELF'] too if you wish
// but this example is manually entered

$url = explode("/", "blabla.com/username")

// 2nd place is the username would be stored
$username = $url[1];


#3 corbin

  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 10:55 PM

I did something similar to that when i was making a script a few weeks back...  Only bad thing is that the servers error logs become use less when it comes to page not found...
Why doesn't anyone ever say hi, hey, or whad up world?

#4 kurtis

  • Members
  • PipPip
  • Member
  • 13 posts

Posted 08 August 2006 - 11:38 PM

would this idea work:

$user_check = "SELECT * FROM users WHERE username='$url'";
$result_user_check = mysql_query($user_check);
$userfound = mysql_num_rows($result_user_check);
	if ($userfound < 1) {
	$error = "user or directory was not found.";
} else {
	$user_info = mysql_fetch_array(mysql_query($user_check));
	$_SESSION['username1'] = $user_info['username']
//rest of the sessions...........

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users