My lovely jovely php Folkies!
Look at this script. It shows you browsing history of a username (user of a web proxy).
Url format:
browsing_history.php?browsing_history_user=USERNAME
If the visitor goes to a wrong format url such as these then he should get an error.
This url does not contain the $_GET part.
browsing_history_v1.php?
This one does not contain the Username in the $_GET part.
browsing_history_v1.php?browsing_history_user=
I have a User “admin123”. Hence, this url should pull the browsing history of: admin123.
browsing_history_v1.php?browsing_history_user=admin123
But, I still get the error:
“In the url, type the Username of the visitor who’s browsing history you want to search! <br>
Type after the part:
“?browsing_history_user=”.
Then, press: ENTER.”.
Why is the ELSE getting triggered instead of the THEN when the url does contain the $_GET value ?
Full script.
Concentrate on the 3rd php tags (<?php & ?>).
[code]
<?php
//Required PHP Files.
include ‘configurations_site.php’; //Required on all webpages of the site. Must include here too. Else, conn.php data would not be found. conn.php residing in site_configurations.php.
include ‘header_site.php’; //Required on all webpages of the site.
include ‘header_account.php’; //Required on all webpages of the account.
include ‘sessions.php’; //Required on all webpages of the site.
?>
<?php
//Check if User is already logged-in or not. Get the login_check() FUNCTION to check.
if (login_check() === FALSE)
{
//Redirect User to Log-in Page immediately.
//header(“refresh:0; url=home.php”);
header(“location:login.php”);
exit();
}
?>
<?php
//Grab Username of who’s Browsing History needs to be searched.
if (isset($_GET[‘browsing_history_user=’]) && !empty($_GET[‘browsing_history_user=’]))
{
$browsing_history_user = $_GET[“browsing_history_user=”];
echo “$browsing_history_user”; //WHY THE VALUE OF THIS VARIABLE NOT GETTING ECHOED WHEN VISITING URL: browsing_history_v1.php?browsing_history_user=admin123
}
else
{
//WHY FOLLOWING GETTING ECHOED AFTER VISITING: browsing_history_v1.php?browsing_history_user=admin123
die(“In the url, type the Username of the visitor who’s browsing history you want to search! <br>
Type after the part:<br>
“?browsing_history_user=”. <br>
<br>
Then, press: ENTER. <br>”);
}
?>
<?php
$user = $_SESSION[“user”];
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional/EN”>
<html>
<head>
<meta content=”text/html; charset=ISO-8859-1″ http-equiv=” content-type”>
<title><?php echo “$site_name User $browsing_history_user Browsing History in $server_time time.”;?></title>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
</head>
<body>
<br>
<p align=”center”><span style=”font-weight:bold;”><?php echo “$site_name User $browsing_history_user Browsing History in $server_time time.”;?></span></align>
<br>
<br>
<?php
if (!$conn)
{
$error = mysqli_connect_error();
$errno = mysqli_connect_errno();
print “$errno: $errorn”;
exit();
}
else
{
$query = “SELECT * FROM browsing_histories WHERE username = “$browsing_history_user””;
$result = mysqli_query($conn,$query);
$rows_num = mysqli_num_rows($result);
//Total Number of Pages records are spread-over.
$page_count = 10;
$page_size = ceil($rows_num / $page_count);
//Get the Page Number. Default is 1 (First Page).
$page_number = $_GET[“page_number”];
if ($page_number == “”) $page_number = 1;
$offset = ($page_number -1) * $page_size;
$query .= ” limit {$offset},{$page_size}”;
$result = mysqli_query($conn,$query);
?>
<table width=”1500″ border=”0″ cellpadding=”5″ cellspacing=”2″ bgcolor=”#666666″>
<?php
if($rows_num)
{
printf(“<b> %d Result Found …</b>n”,$rows_num); ?><br>
<br>
<tr name=”headings”>
<td bgcolor=”#FFFFFF” name=”column-heading_submission-number”>Submission Number</td>
<td bgcolor=”#FFFFFF” name=”column-heading_logging-server-date-and-time”>Date & Time in <?php echo “$server_time”;?></td>
<td bgcolor=”#FFFFFF” name=”column-heading_browsed-page”>Browsed Page</td>
<td bgcolor=”#FFFFFF” name=”column-heading_referral-page”>Referral Page</td>
<td bgcolor=”#FFFFFF” name=”column-heading_username”>Username</td>
<td bgcolor=”#FFFFFF” name=”column-heading_gender”>Gender</td>
<td bgcolor=”#FFFFFF” name=”column-heading_age-range”>Age Range</td>
<td bgcolor=”#FFFFFF” name=”column-heading_religion”>Religion</td>
<td bgcolor=”#FFFFFF” name=”column-heading_education”>Education</td>
<td bgcolor=”#FFFFFF” name=”column-heading_profession”>Profession</td>
<td bgcolor=”#FFFFFF” name=”column-heading_marital-status”>Marital Status</td>
<td bgcolor=”#FFFFFF” name=”column-heading_working-status”>Working Status</td>
<td bgcolor=”#FFFFFF” name=”column-heading_home-town”>Home Town</td>
<td bgcolor=”#FFFFFF” name=”column-heading_home-city”>Home City</td>
<td bgcolor=”#FFFFFF” name=”column-heading_home-borough”>Home Borough</td>
<td bgcolor=”#FFFFFF” name=”column-heading_home-county”>Home County</td>
<td bgcolor=”#FFFFFF” name=”column-heading_home-region”>Home Region</td>
<td bgcolor=”#FFFFFF” name=”column-heading_home-state”>Home State</td>
<td bgcolor=”#FFFFFF” name=”column-heading_home-country”>Home Country</td>
</tr>
<?php while($row = mysqli_fetch_array($result))
{
?>
<tr name=”user-details”>
<td bgcolor=”#FFFFFF” name=”submission-number”><?php echo $row[‘id’]; ?></td>
<td bgcolor=”#FFFFFF” name=”logging-server-date-&-time”><?php echo $row[‘date_and_time’]; ?></td>
<td bgcolor=”#FFFFFF” name=”browsed-page”><?php echo $row[‘browsed_page’]; ?></td>
<td bgcolor=”#FFFFFF” name=”referral-page”><?php echo $row[‘referral_page’]; ?></td>
<td bgcolor=”#FFFFFF” name=”username”><?php echo $row[‘username’]; ?></td>
<td bgcolor=”#FFFFFF” name=”gender”><?php echo $row[‘gender’]; ?></td>
<td bgcolor=”#FFFFFF” name=”age-range”><?php echo $row[‘age_range’]; ?></td>
<td bgcolor=”#FFFFFF” name=”recligion”><?php echo $row[‘religion’]; ?></td>
<td bgcolor=”#FFFFFF” name=”education”><?php echo $row[‘education’]; ?></td>
<td bgcolor=”#FFFFFF” name=”profession”><?php echo $row[‘profession’]; ?></td>
<td bgcolor=”#FFFFFF” name=”marital-status”><?php echo $row[‘marital_status’]; ?></td>
<td bgcolor=”#FFFFFF” name=”working-status”><?php echo $row[‘working_status’]; ?></td>
<td bgcolor=”#FFFFFF” name=”home-town”><?php echo $row[‘home_town’]; ?></td>
<td bgcolor=”#FFFFFF” name=”home-borough”><?php echo $row[‘home_borough’]; ?></td>
<td bgcolor=”#FFFFFF” name=”home-city”><?php echo $row[‘home_city’]; ?></td>
<td bgcolor=”#FFFFFF” name=”home-county”><?php echo $row[‘home_county’]; ?></td>
<td bgcolor=”#FFFFFF” name=”home-region”><?php echo $row[‘home_region’]; ?></td>
<td bgcolor=”#FFFFFF” name=”home-state”><?php echo $row[‘home_state’]; ?></td>
<td bgcolor=”#FFFFFF” name=”home-country”><?php echo $row[‘home_country’]; ?></td>
</tr>
<?php
}
?>
<tr name=”pagination”>
<td colspan=”19″ bgcolor=”#FFFFFF”> Result Pages:
<?php
if($rows_num <= $page_size)
{
echo “Page 1”;
}
else
{
for($i=1;$i<=$page_count;$i++)
echo “<a href=”{$_SERVER[‘PHP_SELF’]}?page_number={$i}”>{$i}</a> “;
}
?>
</td>
</tr>
<?php
}
else
{
?>
<tr>
<td bgcolor=”#FFFFFF”>No record found! Try another time.</td>
</tr>
<?php
}
?>
</table>
<br>
<br>
<p align=”center”><span style=”font-weight:bold;”><?php echo “$site_name User $browsing_history_user Browsing History in $server_time time.”;?></span></align>
<br>
<br>
</div>
<br>
</body>
</html>
<?php
}
?>