Header 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

mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Header Problem

Post by mohson »

I am posting this on a seperate post as my last post has dealt with the problem I was facing. A new problem has now emerged form that post which I would like advice one.

Ok Can anyone see a problem with this code - particularly the header parts. the else statement takes the user to another location buyt


I can see one way around this as it probably isnt working because of the confusing headers.

can someone help me modify the 'else' statement to send the users to the following location

http://www.soi.city.ac.uk/organisation/ ... index.html

with a message saying You do not have admin rights please contact the administrator at top of the page.

php:

Code: Select all

<?php

        include "perm.inc";
        if ( permcheck($REMOTE_USER,$ADMIN_USERS)) {
          //Do nothing and carry on rendering the page
    }
    else {
          header("Location: https://wwws.soi.city.ac.uk/intranet/plo/test/");
          exit;
        }
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Using header redirection it's not generally possible to show any text on the page before the user's browser has redirected them. So you'll have to change it to a standard page-level redirection via a <meta> with an in-page link for those who's browser doesn't like meta-redirection. Time for some Googling.

---

You've been here long enough to know about posting php in

Code: Select all

tags.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Thanks Feyd, can anyone provide me with some examples of what im trying to achieve, because looking at google none of the examples include an if else statement
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

That's maybe because the if-else doesn't matter ;)

Code: Select all

if (...) { }
else {
  // output the html stuff you find in all those meta-equiv tutorials
}
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

meta tags refer to redirecting when your site has moved and it redirects you in a number of second I want to throw the user to another site if he/she isnt a valid user and present a message. none of the tutorials do this.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

feyd wrote:Using header redirection it's not generally possible to show any text on the page before the user's browser has redirected them. So you'll have to change it to a standard page-level redirection via a <meta> with an in-page link for those who's browser doesn't like meta-redirection. Time for some Googling.

---

You've been here long enough to know about posting php in

Code: Select all

tags. [/quote]

Sorry I never read your reply properly. I dont want to give them the message before redirecting them. I want to redirect them back to the main homepage and then present the message saying authorisation required.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Pass a message in some fashion (url, sessions, sherpa) to that page. The page should look for these messages and integrate them somehow. How exactly, is up to you.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Ok looking around Ive dound this:

Code: Select all

<?
        include "perm.inc";
        if (!permcheck($REMOTE_USER,$ADMIN_USERS)) {
          $_SESSION['errmsg']="<font color=\"#ff0000\">You do not have admin rights please <a href=\"mailto:youremail@here.com\">contact the administrator</a></font>";
          header("Location: https://wwws.soi.city.ac.uk/intranet/plo/test/");
          exit; }
//rest of the page
?>
and put this at the top of the screen users are redirected to.

Code: Select all

//top of page script//
<body>
<?
if(isset($_SESSION['errmsg'])){
echo $_SESSION['errmsg'];
unset($_SESSION['errmsg']);
}
?>
//rest of page
2 problems with - 1 it wont solve my header problem as the 2 headers wil clash(if that is whats happening)

2- I tried this and got a whole new error message

PHP Parse error: parse error, unexpected T_STRING.

Dont know what that means
Last edited by mohson on Wed Aug 23, 2006 10:49 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You're missing a semicolon at the end of your $_SESSION line.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

where exactly Ive tried it and no change
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

strange,

Code: Select all

<?php
        include "perm.inc";
        if (!permcheck($REMOTE_USER,$ADMIN_USERS)) {
          $_SESSION['errmsg']="<font color=\"#ff0000\">You do not have admin rights please <a href=\"mailto:youremail@here.com\">contact the administrator</a></font>";
          header("Location: https://wwws.soi.city.ac.uk/intranet/plo/test/");
          exit; }
//rest of the page
?>
doesn't give me any parse errors.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

I put the semi colon in the correct place. I then got a new error which read unexpected '=' so I removed it (dont know if I was right to do so)

Now that I have removed it, I dont get any parse errors. I am now back to my old problem of

cannot modify header information problem.

How can something simple be so difficult to implement.

I think im nearly there though. Just the last push required. as usual any help appreciated.

Code: Select all

<?php
        include "perm.inc";
        if (!permcheck($REMOTE_USER,$ADMIN_USERS)) {
          $_SESSION ['errmsg']; "<font color=\"#ff0000\">You do not have admin rights please <a href=\"mailto:youremail@here.com\">contact the administrator</a></font>";
          header("Location: https://wwws.soi.city.ac.uk/intranet/plo/test/");
          exit; } 

?>
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

feyd wrote:Pass a message in some fashion (url, sessions, sherpa) to that page. The page should look for these messages and integrate them somehow. How exactly, is up to you.
I think I have now done this but am still faced with the same problem. Cannont modify header information - headers already sent. What do you or anyone suggest I do now.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

I have tried and exhausted absolutely everything and am still getting an error message saying:

'cannot modify header information: headers already sent by (output started at /export/TSG-Z/web-source/organisation/plCMS/organisation:2 in export/TSG-Z websource/organisation/PL/CMS/Uorgs.htm on line 6.

Heres the code I use to redirect theuser if he isnt a valid user.

Code: Select all

<?php
        include "perm.inc";
        if (!permcheck($REMOTE_USER,$ADMIN_USERS)) {
          $_SESSION ['errmsg']; "<font color=\"#ff0000\">You do not have admin rights please <a href=\"mailto:youremail@here.com\">contact the administrator</a></font>";
          header("Location: http://www.soi.city.ac.uk/organisation/pl/CMS/"); 

?>
Heres the include file this code is calling:

Code: Select all

<?php
$ADMIN_USERS = array ('pkogan','luan','jand','bevr','sj368','npalmer');



/* PHP4

function permcheck ($user, $ValidUser) {
  while ( $a = array_shift($ValidUser))
    if ($user == $a) return 1;
	return 0;

}
*/

// PHP3 version

function permcheck ($user,$ValidUser) {
  while (list ($k,$v) = each ($ValidUser) )
  if ($user == $v) return 1;
  return 0;
}
And heres the error message code:

Code: Select all

<?
if(isset($_SESSION['errmsg'])){
echo $_SESSION['errmsg'];
unset($_SESSION['errmsg']);
}
?>
Please can someone help with this
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

YESSSSSSS!! I Have managed to make this work!!!! The only problem is when it throws you back to the homepage it doesnt display the error message can anyone help with this?
Post Reply