Jump to content

[SOLVED] Unvalid URL's don't show content of 404.php


Recommended Posts

Hello everyone. I'm Yves and ready to learn. So I hope I joined the right forum, cause I need some expert help here (i guess).

 

Here's my attempt to explain:

 

Have a look at this url: http://smallarticles.com/index2.php?expert=Jan_Michaels

As you can see a user called 'Jan Michaels' exists so it shows stuff. But when you change Jan_Michaels to Jan_Michael in the url it doesn't show a page not found or url not valid kind of thing.

 

Actually there are many pages on my site where I would want it to say the url is not valid whenever values in url's are set but not present in my database.

 

You can see I haven't eaten alot of php-cheese yet. But, nevertheless, I do hope you got an answer. If you need more info in order to help out, I appologise. Just let me know.

phat_hip_prog

Thanks for the quick reply, phat_hip_prog. Awsome!

 

- Actually I'm passsing an argument via $_REQUEST. Is $_REQUEST the same as $_GET? Does it matter?

- You said "if there's no match": how can I let the code check that the argument isn't found anywhere in the database?

- And how can I redirect it to the 404 without the url in the address bar changing to http://domain.com/404.php ? (leave invalid url visible + show content of 404.php)

 

jitesh

I don't understand.

Hmmm, i've never used $_REQUEST... but it say's

The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE.
(somewhere!)...

 

So what you need to do is:

if(isset($_GET['expert'])) // or $_REQUEST
{
   $e = $_GET['expert'];

   // Do your search of database for $e
   // Then count the results... 
   if($num == 0)
   {
      echo "Sorry page not found!";
   }
   else
   {
      // gen normal page
   }

}

I get it, though ...

 

if(isset($_GET['expert'])) {
$expert = $_GET['expert'];
$expert = str_replace("_"," ",$expert);
$result = $obj_db->select("SELECT varFullName FROM `tblauthor` where varFullName = '$expert'");
if($num == 0) {
echo "page not found";
}
else {
// find some more stuff of that author
$result1 = $obj_db->select("SELECT * FROM `tblauthor` where varFullName = '$expert' AND intStatus = 1");
$authorId = stripString($result1[0]['intId']);
// ...
// gen normal page
}
}

... it seems to print page not found eventhough the author is in the database. The 4th line of code must be incorrect.

Allright, phat_hip_prog.

After bit of research, I got it working this way. Thanks.

 

	$result = mysql_query("SELECT * FROM `tblauthor` where varFullName = '$expert'", $link);
$num = mysql_num_rows($result);
if($num == 0) {
echo "page not found";
}
else { ... }

 

:D

 

Now. What do I add after echo "page not found"; to load the homepage after 3 seconds?

header("location:http://".$site_URL."");

 

 

Use javascript's 'settimeout()' to call a function which use's 'location' to redirect... e.g.

 

http://www.tizag.com/javascriptT/javascriptredirect.php

 

<html>
<head>
<script type="text/javascript">
<!--
function delayer(){
    window.location = "../javascriptredirect.php"
}
//-->
</script>
</head>
<body onLoad="setTimeout('delayer()', 5000)">
<h2 >Prepare to be redirected!</h2>
<p>This page is a time delay redirect, please update your bookmarks to our new 
location!</p>

</body>
</html>

P.S.

 

It doesn't have to be in the onload handler... put this in the body somewhere...

 

<script type="text/javascript"><!--
function delayer(){
    window.location = "../javascriptredirect.php"
}

setTimeout('delayer()', 5000);
//-->
</script>

Do you know if I could call that function in a div?

<div onLoad="setTimeout('delayer()', 5000)"><div>

Or is it only possible using it in the body tags?

 

EDIT: Oh, yes. Didn't see your next post. Fabulous!

PS: Is Tizag besides RawStar 7 also your site?

To come back to Reply #7; These lines work when located between the <body> tags. But, when I put them above the <html> tags it doesn't function properly.

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource ...

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource ...

 

To what should I change these to lines so that they can be above the <html> tags and still work?

 

<?php 
$resnum = mysql_query("SELECT * FROM `tblauthor` where varFullName = '$expert'", $link);
$num = mysql_num_rows($resnum);
?>

OK. I'll retype it and try it out.

It just seems a bit strange; my config.inc.php is included and $link in there is properly defined. This $link is properly called when between the <body> tags, but not above the <html> tags. I doesn't seem logical to me. But anyway, I'll try like you suggested! 8)

 

EDIT: After a closer look at my config.inc.php, I figured out why $link isn't defined above my <html> tags.....

 

Again - Big Thanks, phat_hip_prog

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.