Jump to content

check mysql database against the URL


kurtis

Recommended Posts

hi,
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 :)
thanks
Link to comment
Share on other sites

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

Could try exploding the URL
[code]
<?php
$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];

?>
[/code]
Link to comment
Share on other sites

would this idea work:
[code]
<?php
$url = $_SERVER['REQUEST_URI'];

$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...........
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.