Jump to content

Newbie problems


Bethrezen

Recommended Posts

hi all

 

I'm trying to understand some of the mechanics of php but I'm having problems I set up a simple test page here

 

http://h1.ripway.com/Bethrezen/demo/Web-Site-Demo/test.php

 

now when you go to that page the snippet of php on that page should display the contents of the included file but if i go here

 

http://h1.ripway.com/Bethrezen/demo/Web-Site-Demo/test.php/

 

it should display the error message "Error Bad Input" but i must be doing something wrong because i cant seem to get it to work here is the code i have

 

<?php

$file = array('test.php', 'Content/Section-1-Introduction.php');

if(in_array ($file))
{
include('Content/Section-1-Introduction.php');
}
else
{
header("Refresh: 3; url=index.php?page=Site-Map");
die('Error Bad Input');
}
?>

 

now the idea behind this is should someone miss type the url for one of the pages instead of getting something like

 

Warning: Wrong parameter count for in_array() in \\192.168.1.16\webfiles\files\2005-3\275289\demo\Web-Site-Demo\test.php on line 18

 

they will instead get a custom error and then redirected to the site map page so what am i doing wrong ?

Link to comment
Share on other sites

hi

 

I see ok so for the second argument how do I have it read the url that has been typed in ??

 

because the first thing that would need to happen is to read the url that was typed in to determine if its a bogus url and if it is redirect

 

is $_SERVER['REQUEST_URI'] the correct command for that ??

 

because it doesn't seem to work correctly i input the url http://h1.ripway.com/Bethrezen/demo/Web-Site-Demo/test.php

 

which should resolve to true because both test.php & Content/Section-1-Introduction.php are in the array but yet i get a false answer and get the bad input error which is not corect

Link to comment
Share on other sites

because the first thing that would need to happen is to read the url that was typed in to determine if its a bogus url and if it is redirect

 

If its a bogus url, your script won't run, make sense? This type of thing needs to be handled by Apache, well before it ever gets to any php scripts.

Link to comment
Share on other sites

This type of thing needs to be handled by Apache, well before it ever gets to any php scripts.

 

can't leave it up to Apache because the servers where ripway is housed are IIS aka (Microsoft)

 

so how do i write a simple little script that will detect when people have incorrectly typed a url for one of my pages and then give them a custom error message before redirecting them to the site map page

 

I though the best way to go about this would be through an array but I'm pritty new to php so maybe there is a simpler way that might be more appropriate

Link to comment
Share on other sites

I understand what you are saying that this is best handled by the server but that's not an option I don't have server access so i'm going to have to do this my self through php now while this is a far from idea solution i don't see that there is much else i can do

 

there must be some way to pull this off and either have a custom error page pop-up and then redirect or just have the script output a message and then redirect

 

it should be possible to insert some code in to the main page index.php that will intercept any requests to it valid or not and then take appropriate action

Link to comment
Share on other sites

ok obviously I have failed to adequately explain what its is that I am trying to achieve so ill try again presently if you go to one of my pages and miss type the address

 

example:

http://h1.ripway.com/Bethrezen/demo/Web-Site-Demo/Index.php/

 

you get a load of horrid error code

 

example:

Warning: main(): open_basedir restriction in effect. File(\\192.168.0.16\webfiles\files\2005-3\275289\demo\Web-Site-Demo/Switch/style-switcher.php) is not within the allowed path(s): (.) in \\192.168.0.16\webfiles\files\2005-3\275289\demo\Web-Site-Demo\Index.php on line 15

 

which even the most inexperienced coder will be able to tell you is a bad idea for reasons of security, professionalism and accessibility. Obviously this is an undesirable situation that needs to be resolved so what can we do ?

 

well the first and most obvious solution is to change php error reporting so that it outputs errors to an error log instead of the browser

 

question is how ??

 

while this does go part way to addressing the situation trouble is that should users mistype an address they are left looking at a blank screen

 

now the obvious solution in this event would be to display an error message informing the user that they had mistyped the address and then redirect them to the site map

 

however this is where i hit my second problem i don't have server access also the server is also IIS not apache so I cant use a .htaccess file

 

so my next question is how do i have an error message pop up and then subsequently them redirected to the site map so that they can find the page they are looking for ? with out server access ??

Link to comment
Share on other sites

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.