Jump to content

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?

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.