Question: **My Profile php**

```
<?php
//profile.php

require_once 'includes/global.php';

//check to see if they're logged in
if(!isset($_SESSION['logged_in'])) {
    header("Location: login.php");
}

// finding user and viewing it
$tools = new FindUser();
$user = $tools->get($_REQUEST['userID']);

?>

```

This is my php for viewing user profile.

<http://mywebsite.com/profile.php?userID=5> its working fine in this way. 

i want my code to check if user is available in database for example if i add `?userID=10` which is not present in database it gives out mysql error or even if i use `http://mywebsite.com/profile.php`then also it give error. 

so now i want if user is not available in database it should give that user is not available and when we use simple `http://mywebsite.com/profile.php` it should give auto add it to `userID=1` OR REDIRECT it to home.php

If there is other way of doing this please let me know. well im very newbie in this field 

Thanks for looking my question and answering :)

**Solved**

```
<?php
//profile.php

require_once 'includes/global.php';

//check to see if they're logged in
if(!isset($_SESSION['logged_in'])) {
    header("Location: login.php");
}

$UserID = $_GET['userID'];
$CheckQuery = mysql_query("SELECT * FROM users WHERE id='$UserID'");

$CheckNumber = mysql_num_rows($CheckQuery);
if ($CheckNumber !== 1)
{
    header("Location: index.php");
}

// finding user and viewing it
$tools = new FindUser();
$user = $tools->get($_REQUEST['userID']);

?>

```

Answer: 
Seems to me that less script overhead would make things faster.

```
fgrep -r -h 'LINE_TXT' $1

```

Just let grep do its own recursion through your directories with `-r`. And if you don't want its output to include the filename in its output, include the `-h` option. You can pipe its output through whatever you need for post-processing.

If you want to search only for specific filenames, grep's `-r` option has options of its own: `--include` and `--exclude`, mentioned on its man page. For example:

```
fgrep -h -r --include '*/filename.txt' 'LINE_TXT' $1

```

While the `find` command is excellent, and invaluable in certain situations, if you can use options built in to a single tool like `grep`, you will incur less overhead. The `find` command doesn't look inside files, so it would still have to launch `grep` for each one of them. If you DID want to use `find`, it might look something like this:

```
find $1 -name 'filename.txt' -exec fgrep 'LINE_EXT' {} \;

```

This has the benefit of giving you access to `find`'s directory searching capabilities, but if all you want to do is look for a particularly named file in your directory tree, grep's `-r --include` is probably sufficient and is sure to run faster.
Yes, `find $1 -type f -name 'filename.txt' | xargs fgrep LINE_TXT`, if all you want is to locate all matches of "LINE\_TXT" in any of those files.