Yves Posted September 13, 2007 Share Posted September 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/ Share on other sites More sharing options...
phat_hip_prog Posted September 13, 2007 Share Posted September 13, 2007 Your passing an argument via $_GET and handling it, so if there is no match you need to redirect to a 404 (or just put a message in it's place would be better here, e.g. 'expert not found!') Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347644 Share on other sites More sharing options...
jitesh Posted September 13, 2007 Share Posted September 13, 2007 (1) Do not show "expert" in address bar.I mean to use post method. Or (2) Fetch data according to input (expert=input). If record do not found then redirect to home page. Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347645 Share on other sites More sharing options...
Yves Posted September 13, 2007 Author Share Posted September 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347649 Share on other sites More sharing options...
phat_hip_prog Posted September 13, 2007 Share Posted September 13, 2007 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 } } Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347654 Share on other sites More sharing options...
Yves Posted September 13, 2007 Author Share Posted September 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347667 Share on other sites More sharing options...
phat_hip_prog Posted September 13, 2007 Share Posted September 13, 2007 You need to count the number of results, something similar to this... $s = ""SELECT varFullName FROM `tblauthor` where varFullName = '$expert'""; $res = mysql_query($s, $conn); $num = mysql_num_rows($res); Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347671 Share on other sites More sharing options...
Yves Posted September 13, 2007 Author Share Posted September 13, 2007 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 { ... } Now. What do I add after echo "page not found"; to load the homepage after 3 seconds? header("location:http://".$site_URL.""); Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347701 Share on other sites More sharing options...
phat_hip_prog Posted September 13, 2007 Share Posted September 13, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347707 Share on other sites More sharing options...
phat_hip_prog Posted September 13, 2007 Share Posted September 13, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347709 Share on other sites More sharing options...
Yves Posted September 13, 2007 Author Share Posted September 13, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347714 Share on other sites More sharing options...
phat_hip_prog Posted September 13, 2007 Share Posted September 13, 2007 As post #9 ! Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347715 Share on other sites More sharing options...
Yves Posted September 13, 2007 Author Share Posted September 13, 2007 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347738 Share on other sites More sharing options...
phat_hip_prog Posted September 13, 2007 Share Posted September 13, 2007 You need a connection (e.g. no resource!), for instance: $conn = mysql_connect("localhost", "username", "password"); mysql_select_db("db_name", $conn); Then as before... Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347755 Share on other sites More sharing options...
Yves Posted September 13, 2007 Author Share Posted September 13, 2007 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! 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 Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347759 Share on other sites More sharing options...
phat_hip_prog Posted September 13, 2007 Share Posted September 13, 2007 You've not shown any include!!! eh? Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347762 Share on other sites More sharing options...
Yves Posted September 13, 2007 Author Share Posted September 13, 2007 Correct, I didn't. Appologies. I got it working following your advice. Quote Link to comment https://forums.phpfreaks.com/topic/69172-solved-unvalid-urls-dont-show-content-of-404php/#findComment-347817 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.