please help me with this coding problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aashish_2025
Forum Newbie
Posts: 7
Joined: Mon Jun 14, 2010 2:37 am

please help me with this coding problem

Post by aashish_2025 »

Well, first of all, let me tell that I am a newbie on php and that's why, I believe, I am getting this problem.

Now, let me tell my problem. Actually, I have a website for creating which I firstly created an index page(with header, navigation bar and footer). Then, I put individual pages as separate PHPs. So, what basically I've done is put a link like "?bas=feedback" which trigers a function on the index page("index.php") for the following task:

Code: Select all

$basket = $_GET ['bas']
function samlagna ($basket) {
switch ($basket) {
    case 'home':
        include ('home.php');
        break;
	case 'feedback':
        include ('feedback.php');
        break;
}
}
So, this is how my site goes on. So, every single page(like "feedback.php") contains nothing more than a form, I mean, that is without any header, navigation & footer. This is not a problem because every visitor will get that page through the index page having the link "www.mysite.com/?bas=feedback" and so, everything(header,.....) is included over there not bringing any problem.

But, here comes my problem.
When Google has indexed my site, multiple pages have been indexed (not just index.php) and one of the index is just,

"www.globalcollegiate.edu.np/general.php"

And so, if someone opens that page from google, then the page will display that boring feedback form without any header, navigation bar and footer. This is my problem.

Hoping to receive any sort of help!
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Re: please help me with this coding problem

Post by Phoenixheart »

Check for a predefined constant inside your included files. That constant should be defined in index.php before including. Like this:

Code: Select all

// inside, like, feedback.php
if (!defined('YOUR_CONSTANT'))
{
    header("HTTP/1.0 404 Not Found"); // trigger a 404 file not found error. You may want another error code
    die('No direct access.');
}

//... other stuff

Code: Select all

// on top of index.php
define('YOUR_CONSTANT', 1);
As Google won't index 404 pages, you should be safe. This is good for security too.
aashish_2025
Forum Newbie
Posts: 7
Joined: Mon Jun 14, 2010 2:37 am

Re: please help me with this coding problem

Post by aashish_2025 »

Thank You very much for replying. I'll give it a try and tell you if my problem gets solved. Hope it does! :D :D :D
aashish_2025
Forum Newbie
Posts: 7
Joined: Mon Jun 14, 2010 2:37 am

Re: please help me with this coding problem

Post by aashish_2025 »

While reading this anther thought crossed my mind. So, I just want to ask you something. Using the above mentioned 404 Error page when feedback.php hasn't been queried from index.php, I assume, my Search engine position will drop.(because of less no. of files to be indexed)

Am I right in this regard or not? Or, as feedback.php will be there, my position won't get affected?

Plz do reply! :)
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Re: please help me with this coding problem

Post by Phoenixheart »

In such a case, don't use 404. Use a 301 Moved Permanently instead. Ie in feedback.php you force a 301 redirection to index.php?action=feedback and so on.
See http://www.webconfs.com/how-to-redirect-a-webpage.php.
aashish_2025
Forum Newbie
Posts: 7
Joined: Mon Jun 14, 2010 2:37 am

Re: please help me with this coding problem

Post by aashish_2025 »

Thank You very much for your help. That's exactly what I wanted. Thank You very much.

As you suggested for a redirect, I did that but not as the way mentioned in the link you gave rather I used a bit of Javascript. So, basically I've first declared a constant in index.php as you said and then use an if statement for a redirect in general.php, like the follwing:

Code: Select all


// inside general.php
if (!defined('MY_CONSTANT'))
{
 	echo ("<script language=\"JavaScript\">location.href=\"/?bas=general\"</script>");   
}

Anyway, you're idea of declaring a constant and then checking it was awesome. Thank you very much! :)
Post Reply