# PHP script gives no output



## John Musbach (Nov 11, 2007)

I have the latest version of FUDforum setup and am trying to create a hack that'll allow users who authenticate through our groups kerberos authentication gateway to automatically be logged in. The source code is as follows:


```
<?php
//Here we grab the authenticated user's name
//and either automatically log them in using an existing account
//or register them
error_reporting(E_ALL);
ini_set('display_errors',1);

require('/users/u15/jmusbach/.html_pages/FUDforum2/GLOBALS.php');
require('/users/u15/jmusbach/FUDforumDAT/scripts/fudapi.inc.php');
require('/users/u15/jmusbach/FUDforumDAT/scripts/forum_login.php');

global $_SERVER;
$user=$_SERVER['WEBAUTH_USER'];
$realname = $_SERVER['WEBAUTH_LDAP_GIVENNAME'] . ' ' .$_SERVER['WEBAUTH_LDAP_SN'];
$email = $user . '@blah.com';
$error="";

if(external_fud_login(fud_fetch_user($user)['id']))!=NULL) //User ID is valid and logged in
{
        echo("Welcome, " . $user . ", please wait while you are logged in...");
	header( 'Location: https://blah.com/~jmusbach/FUDforum2/' ) ;
}
else //User ID is invalid, register and log in
{
	echo("Welcome, " . $user . ", please wait while you are registered and logged in...");
        if(fud_add_user(array($user,"password",$email,$realname),$error)!=0)
        {
          external_fud_login(fud_fetch_user($user)['id']));
          header('Location: https://blah.com/~jmusbach/FUDforum2/');
	}
        else
        {
          echo($error);
          die();
        }
	
}



?>
```
Unfortunately no errors are returned and the output is completely blank, any ideas as to where I've gone wrong (e.g. obvious syntax errors)? I'm new to PHP so I've probably done something with the syntax that you're not supposed to do in PHP. I would gladly ask this question in the FUDforum support forums but despite it being many days since I've registered the administrator still has yet to manually activate my account so hopefully I can get some help here. 

P.S. In case it helps you can see the source code to the API files I referenced here:

fudapi.inc.php: http://pastebin.com/m349a4bff
forum_login.php: http://pastebin.com/m176b28b3


----------



## MMJ (Oct 15, 2006)

1. $_SERVER is a Superglobal, you don't need to use the global keyword on it.

2. I think you want $_POST, not $_SERVER.


----------



## John Musbach (Nov 11, 2007)

MMJ said:


> 1. $_SERVER is a Superglobal, you don't need to use the global keyword on it.
> 
> 2. I think you want $_POST, not $_SERVER.


Thanks, turns out there were multiple problems with my code. My final
working code is:


```
<?php
//Here we grab the authenticated user's name
//and either automatically log them in using an existing account
//or register them

require_once('/users/u15/jmusbach/.html_pages/FUDforum2/GLOBALS.php');
require_once('/users/u15/jmusbach/FUDforumDAT/scripts/fudapi.inc.php');
require_once('/users/u15/jmusbach/FUDforumDAT/scripts/forum_login.php');

global $_SERVER;
$user=$_SERVER['WEBAUTH_USER'];
$realname = $_SERVER['WEBAUTH_LDAP_GIVENNAME'] . ' '
.$_SERVER['WEBAUTH_LDAP_SN'];
$email = $user . '@blah.com';
$uid=_fud_simple_fetch_query(array("'".$user."'"), "SELECT * FROM
".$GLOBALS['DBHOST_TBL_PREFIX']."users WHERE login IN({ARG})");
$login=external_fud_login($uid->id);
if(!empty($uid->id) && !empty($login)) //User ID is valid and logged in
{
       //echo("Welcome, " . $user . ", please wait while you are
logged in...");
       header( 'Location: https://blah.com/~jmusbach/FUDforum2/?S='.$login);

}
else //User ID is invalid, register and log in
{
       //echo("Welcome, " . $user . ", please wait while you are registered
and logged in...");
       $vals['login']=$user;
       $vals['passwd']="password";
       $vals['email']=$email;
       $vals['name']=$realname;
       $uid=fud_add_user($vals,$error);
       $login=external_fud_login($uid);

       if($uid!=0 and empty($error))
       {
         header('Location: https://blah.com/~jmusbach/FUDforum2/?S='.$login);
       }
       else
       {
         echo($error);
         die();
       }

}



?>
```
for anyone who may be trying to accomplish the same thing as me. In
addition I edited index.php in the themes folder and added a php
clause such that in the event the user is anonymous they are
redirected to the autologin.php script and I also edited the
register.php themes script to omit the UserCP password field and
password confirmation since everyone in this setup is assigned one
long random password (the thought being that the kerberos
username/password is enough to worry about, there should be no need to
worry about another username/password).


----------



## John Musbach (Nov 11, 2007)

I almost forgot, I resolved the blank page issue by looking at the
.htaccess file FUDforum installed in its main public directory
...turns out the file contained a directive which suppressed all php
errors even when the value was specified differently in individual php
scripts, modifying that directive to show all php errors resolved that
issue.


----------

