+ Reply to Thread
Results 1 to 6 of 6

Thread: php post request: random characters output to screen

  1. #1
    wizkid is offline x10Hosting Member wizkid is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    25

    Exclamation php post request: random characters output to screen

    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 Code:
    require('accesscontrol.php');
    $page_access_level=1;
    check_access_status($page_access_level); 

    PHP Code:
    //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 Code:
    //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

  2. #2
    sybregunne is offline x10Hosting Member sybregunne is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    54

    Re: php post request: random characters output to screen

    <?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 by sybregunne; 07-24-2008 at 11:25 PM. Reason: Automerged Doublepost

  3. #3
    scopey is offline x10Hosting Member scopey is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    62

    Re: php post request: random characters output to screen

    Yes... You shouldn't have a variable in the require or require_once function :S .

  4. #4
    wizkid is offline x10Hosting Member wizkid is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    25

    Re: php post request: random characters output to screen

    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.

  5. #5
    TechAsh's Avatar
    TechAsh is offline Retired TechAsh is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    UK
    Posts
    5,853

    Re: php post request: random characters output to screen

    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.
    Useful Links:
    Terms of Service | Server News | Buy a Domain
    Free Domains: co.cc | Dot.tk -- Free File Storage: Dropbox -- Website Monitoring: Service Uptime


    My Websites:
    Earthtime Games & TechAsh's Blog

  6. #6
    wizkid is offline x10Hosting Member wizkid is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    25

    Re: php post request: random characters output to screen

    Quote Originally Posted by TechAsh View Post
    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 Code:
    //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"$result2); 
    //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 by wizkid; 07-25-2008 at 08:36 AM. Reason: Automerged Doublepost

+ Reply to Thread

Similar Threads

  1. Random numbers in PHP
    By cursedpsp in forum Tutorials
    Replies: 8
    Last Post: 11-13-2008, 06:43 AM
  2. php errors galore
    By DMG Online in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 05-17-2008, 06:23 AM
  3. PHP: post hidden textboxes' values
    By anuj_web in forum Programming Help
    Replies: 4
    Last Post: 05-12-2008, 07:24 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers