Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I check to see if a page exists ?

Status
Not open for further replies.

JerMyster

IS-IT--Management
Mar 17, 2003
49
US
Trying to verify that a page exists before I go to it. I have a page with a inputbox and a button. I ask the user to enter an account number and press a button. If the page doesn't exist I want to default to a page that informs the user that the page was not found. I want to display my own page when not found.

Thanks
 
Nothing HTML can do. Look into server-side language and server you are using. You could make a custom 404 page, I guess.
 
I ask the user to enter an account number and press a button. If the page doesn't exist I want to default to a page that informs the user that the page was not found.

Do you mean "page was not found" or "account was not found"?
If it's a case of a/c not found, I would inform the user with a specific page. It would be more informative than a 404.

"Page not found" has a quite specific meaning, which is very distinct from "A/C not found". Mixing the two can easily lead to confusion - especially for search engines, etc.

<marc>
 
What exactly are you trying to do? If I follow you, you are trying to get a page based on the account #. If so it would be easier to use a dbase, reference the acct# and build the page from the info in the dbase. Otherwise, I need a little more clarification on the problem, maybe show us an example of your work.

When in doubt, go flat out!
 
Cliff,
I agree, it would be better to use a dbase, but I don't know how yet and fell it would take a long time to learn. The system I have now works but could be nicer.

Can you steer me to a good book to learn the dbase approach.

Thanks
 
If you use PHP, it's very easy to see if a page is there..

Code:
if (!is_file("document.html")) {
    echo "Sorry, the document is missing!";
  }

if it's some kind of account, you simply do a query, then do:
Code:
if (mysql_num_rows($result) < 1)) {
    echo "Sorry, that account could not be found!";
  }

ref.: ref.:
Olav Alexander Mjelde
Admin & Webmaster
 
DaButcher,

Thanks, don't know how to use or do PHP yet, is it like usung javascript, I know a little of that.

 
I'm pretty much of a novice PHP user - it was pretty easy to learn. I think it's similar to java. Don't be afraid to dive in - you can have just a little PHP on a page and the rest can be straight HTML. You bracket the PHP code with

<?php
... php code ...
?>

I think the syntax might be slightly different for apache than for IIS. In apache, to test if a file exists, I use:

if (file_exists('Fully-Qualified-Filename.ext')) { ... code ...}
else { ... code ... }

Of course, the page name must end in PHP so the server knows it's PHP.

Mike Krausnick
Dublin, California
 
how compatiple is php with ie? do users need a plug-in or is it like javascript?

thanks for the info...
 
PHP is a server side language. The page that is served to the browser has no special tags in it. PHP constructs the page on the server and serves straight HTML (or whatever you want) to the browser. In my prior example, all the browser would see would be one of the two "...code..." parts, depending on whether the page existed or not.

Mike Krausnick
Dublin, California
 
PHP is done on the server-side. That means that client (browser) gets normal html at the end. You need a server that supports PHP (most free won't, most payable will) and that is that. Because PHP runs at the server it produces normal html code by the time browser sees it and there is no compatibility issues with browsers.
 
To say this in a more simple way:
PHP can produce anything or nothing.

PHP is a programming language, so is javascript.

As said above, PHP is serverside, while javascript is client-side.

client-side scripting, like javascript, is dependent on the clients browser. The client can turn off javascript to manipulate javascript pages, he can not do this for PHP pages.

The PHP page, will output what ever you program it to output!

eg. you can even make php dynamically create javascript (I dont know why you would want it to, though).

You can also make easy-to-use galleries, by modifying directory-listings, etc.
The ends of PHP are at your fingertips.

Olav Alexander Mjelde
Admin & Webmaster
 
Thanks guys,

I get it now. As long as my server supports it, it won't impact the user, because it just produces html.

Thanks again.
 
ps. if you have *dsl, you might even be able to host your own server.

you first need some server software, like apache. then you need the php: -> downloads

dont use php on any other apache than 1.3
1.33 is preferred!

then you need to set it up.. I found the best tutorial was on simple, quick and dirty!

ps. dont use CGI.
also: check with your TOS for your *dsl, are you allowed to run a server?

If you have a static ip, you can use services as (dynamic dns)

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top