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
https://forums.phpfreaks.com/topic/16964-check-mysql-database-against-the-url/
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]
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.