bri0987 Posted October 9, 2007 Share Posted October 9, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/72400-redirecting-users-if-try-to-enter-in-a-different-url/ Share on other sites More sharing options...
sKunKbad Posted October 9, 2007 Share Posted October 9, 2007 Make a "file not found" 404 error page with a redirect in it's header, or use .htaccess to redirect when "file not found". Quote Link to comment https://forums.phpfreaks.com/topic/72400-redirecting-users-if-try-to-enter-in-a-different-url/#findComment-365128 Share on other sites More sharing options...
bri0987 Posted October 9, 2007 Author Share Posted October 9, 2007 I'm fairly new. Can you please explain how to do what you just said... about making a 404 page or the .htaccess thing. Quote Link to comment https://forums.phpfreaks.com/topic/72400-redirecting-users-if-try-to-enter-in-a-different-url/#findComment-365180 Share on other sites More sharing options...
Aureole Posted October 9, 2007 Share Posted October 9, 2007 Make a file called "404.shtml" then in the <head> put... <meta http-equiv="refresh" content="0;url=http://yourwebsite.com/index.php"> That should work... Quote Link to comment https://forums.phpfreaks.com/topic/72400-redirecting-users-if-try-to-enter-in-a-different-url/#findComment-365216 Share on other sites More sharing options...
onenonly Posted October 9, 2007 Share Posted October 9, 2007 <?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' ) ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72400-redirecting-users-if-try-to-enter-in-a-different-url/#findComment-365242 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.