php post request: random characters output to screen

wizkid

New Member
Messages
25
Reaction score
0
Points
0
i am using php post requests for restricting access to certain pages to my website.


here's the function that calls for access check
PHP:
require('accesscontrol.php');
$page_access_level=1;
check_access_status($page_access_level);


PHP:
//accesscontrol.php


                    if(!isset($_SESSION['uid']))
                                {
                                require('post_request.php');
                                $var_arr=array('status'=>'1');

//$no_access=no_access.php                                
            list($header,$contents)=post("/".$no_access,$var_arr);

                                echo "$contents";


                                exit();
                                }
                                break;


here's the page that should be displayed when access is denied
PHP:
//no access.php

<?php 
//require_once('accesscontrol.php');
//session_start();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>

<title> NO ACCESS</title>
<link rel="stylesheet" type="text/css" href="layout.css"/>
<link rel="stylesheet" type="text/css" href="head.css"/>
<link rel="stylesheet" type="text/css" href="menu.css"/>
<link rel="stylesheet" type="text/css" href="register.css"/>
</head>
<body>

<div class="head" id="head" >

  <h1>ACCESS DENIED</h1>
</div>
<div id="user_status">
<?php
require('source_link.php');
require_once("$user_status");
disp_status();
?>
</div>


    <div  id="left">
      
      <?php  
      require_once('navigation.php');
     
      
      $thisPage="home";
      menu($thisPage);
     
      ?>

    </div>

    <div class="content" id="right">
        <p>
            <h3></h3>
<?php 

if($_POST['status']==1)
    {
    echo"\n<br/>Please login to view this page";
    }
else
    {
    echo"\n<br/>you are not logged in or do not have enough privileges to view this page";
    }    
?>

        </p>
    </div>
</body>
</html>

the problem is that whenever the page no_access.php is displayed some random characters are displayed on the screen
click here to view the page
 

sybregunne

Member
Messages
54
Reaction score
0
Points
6
<?php
require('source_link.php');
require_once("$user_status");
disp_status();
?>

I'm not sure but it could be that require_once("$user_status"); is the one giving you the random characters?

because require_once is used to include files once. Although this should generate an error.

I'm confused also. anyway try to check that certain "require_once" and please correct me if I'm wrong. :)
Edit:
maybe you meant to use a different function but typed in require_once in error?
 
Last edited:

scopey

New Member
Messages
62
Reaction score
0
Points
0
Yes... You shouldn't have a variable in the require or require_once function :S .
 

wizkid

New Member
Messages
25
Reaction score
0
Points
0
i tried removing the variable name from require function but it did not bring out any change.
i dont think the problem is due to this because i have used the same syntax on every page on my site, but only this page shows up random characters.
 

TechAsh

Retired
Messages
5,853
Reaction score
7
Points
38
i dont think the problem is due to this because i have used the same syntax on every page on my site, but only this page shows up random characters.
Well if this is the only page where it happens then you need to compare it with a page that works and find the difference, there must be one.
 

wizkid

New Member
Messages
25
Reaction score
0
Points
0
Well if this is the only page where it happens then you need to compare it with a page that works and find the difference, there must be one.


when i go to the page directly
no_access.php
it displays correctly

however when this page is accessed via a post request it displays correctly
for example
upload.php
Edit:
apologies sought.......
i think i missed posting a important part of my code
it is the contents of the page post_request.php
PHP:
//page_request.php 
//post function 
<?php 

function post($url,$var_arr) 
{ 
$host="nitesh.x10hosting.com"; 
//$host="localhost"; 
$var_list=""; 
foreach($var_arr as $name=>$value) 
{ 
if(isset($var_list)) 
$var_list.="&"; 

$var_list.="".$name."=".urlencode($value); 
} 

$content_len=strlen($var_list); 
/* 
$request_header= 
"  
POST $url HTTP/1.1  
Host : $host  
Content-Type : application/x-www-form-urlencoded  
Content-Length : $content_len  
Connection : close 

$var_list \n\n"; 

*/ 
$socket=fsockopen($host,80,$errno,$errstr); 
if(!$socket) 
{ 
    die("\n<br/>post request failed ERROR $errno : ".$errstr ); 
} 
/* 
if(!fputs($socket,$request_header)) 
{ 
    die("\n <br/>error"); 
} 
*/ 

fputs($socket,"POST $url HTTP/1.1 \r\n" ); 
fputs($socket,"Host : $host \r\n" ); 
fputs($socket,"Content-Type : application/x-www-form-urlencoded \r\n" ); 
fputs($socket,"Content-Length : $content_len \r\n" ); 
fputs($socket,"Connection : close \r\n\r\n"); 
fputs($socket,"$var_list \r\n"); 


while(!feof($socket)) 
$result.=fgets($socket,128); 

 $result = explode("\r\n\r\n", $result, 2); 
//if(isset($result["errno"])); 
//    die("\n<br/>post failed ".$result['errno'].": ".$result['errstr']); 
//else 
fclose($socket);  
//    for($i=0;$i<count($result);$i++) 
//    echo"\n<br/><br/>".  $result[$i] ; 
return array($result[0],$result[1]); 
} 

?>
 
Last edited:
Top