Page 1 of 2
Header Problem
Posted: Tue Aug 22, 2006 8:58 am
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;
}
?>
Posted: Tue Aug 22, 2006 9:04 am
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
Posted: Tue Aug 22, 2006 9:38 am
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
Posted: Tue Aug 22, 2006 9:55 am
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
}
Posted: Tue Aug 22, 2006 10:13 am
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.
Posted: Tue Aug 22, 2006 3:33 pm
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.
Posted: Tue Aug 22, 2006 3:58 pm
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.
Posted: Wed Aug 23, 2006 9:46 am
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
Posted: Wed Aug 23, 2006 9:49 am
by feyd
You're missing a semicolon at the end of your $_SESSION line.
Posted: Wed Aug 23, 2006 9:55 am
by mohson
where exactly Ive tried it and no change
Posted: Wed Aug 23, 2006 9:57 am
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.
Posted: Wed Aug 23, 2006 10:13 am
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; }
?>
Posted: Wed Aug 23, 2006 10:29 am
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.
Posted: Thu Aug 24, 2006 6:59 am
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
Posted: Thu Aug 24, 2006 7:19 am
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?