Jump to content

Redirecting users if try to enter in a different URL ??


bri0987

Recommended Posts

I'm in the process of learning how to make a shopping cart. I'm making good progress but some things keep getting me off track.

 

Here is one of those things...

 

If a users going to a page that does not exist on the host how do I just direct them automatically to the home page.

 

For example:

 

www.yoursite.com/products/sdfgswfdgsgf.php

 

"sdfgswfdgsgf.php" does not exist so I want to direct them to the home page at www.yoursite.com

 

A real world example of this is at alienware.com  -- if you type after the "/" anything it will simply direct you to the home page.

 

This will help because getting an ugly error file not found message in awful.

 

Also another question:

(RELATED TO THE SAME AREA)

 

When constructing my shopping cart I noticed that if someone is linked to and taken to:

www.yoursite.com/products/index.php?product_id=3

 

the page will load fine. But if someone changes the URL to:

www.yoursite.com/products/index.php?product_id=5555

 

I will have an error (I think it was an SQL error) ...

 

How would I fix this so that it will just default to index.php OR EVEN BETTER Right back to the Homepage like the above question.

 

I'm asking all of this because I want to prevent people from snooping around and trying things on my shopping cart if they wanted too.

 

Let me know.

 

Thank you for reading my questions. :)

<?php

$dbhost = 'localhost';
$dbuser = 'username';
$dbpass = 'plassword';
$dbname = 'database';

$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);

$query = "SELECT product_id FROM table";
$result = mysql_query($query) or die(mysql_error());

if ($_GET['product_id'] > mysql_num_rows($result)) {

header( 'Location: /index.php' ) ;

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.