Jump to content

[SOLVED] redirect: header vs. include?


fivestringsurf

Recommended Posts

hello there,

 

Would like some general advice regarding re-routing users.  (php5) I've been using two methods for re-directing users to a new page within a website-  header() or include()

 

What's the best way? Are there advantages to one over the other....for instance in a member system sometimes I'll use something like this to re-route non-logged in users:

if (!isset($_SESSION['c_id'])) {
             $msg ='hey loser, you're not welcome here!';
include('../contact.php');
exit();
}else{
$c_id = $_SESSION['c_id'];
}

 

 

Other times I'll use something like this:

if (isset($_SESSION['c_id'])) {
header('location:edit_profile.php');
}

 

Now, I like using include() because I can include variables like my $msg above, but (there's always a but isn't there!) I run into header/footer navigation bar linkage problems when using relative links within my included header and footer files

.This appears to happen for pages located in different directories.

 

I started using header()  to re-route users because i wasn't getting the problems wth my included nav bar links, but this method I can't have any variables or you get that infamous header warning that everyone and their grandma has had at somepoint (i don't want to use url vars)

 

Anyone familiar with these issues?

What do you guys do?

Thank you

Link to comment
https://forums.phpfreaks.com/topic/172212-solved-redirect-header-vs-include/
Share on other sites

aha, that's why i come here....you guys are slick.  really slick. 8)

I didn't even think of that.  Is that what you do waynewex?

 

I could see that adding to the whole modularity of the site too...all you messages are

in say one file and just include it at the top of each page.

 

The thing is though I've always had some trouble when including functions and variables...i seem to have to make anything i am including  global to get it to work.

Not sure if that is dangerous or uses excess resources?

 

could i just create a php file with my msg list and include it at the top of each page?

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.