Jump to content

load as blank page


orange08

Recommended Posts

recently, when i testing my php site, sometimes the page just load as blank page without anything(i experience it twice and both are happen after i just modify my php file and uploading to hosting)...so, i thought is my code error causing this...then, i just try to load the page again, then it load normally. so, anyone can tell me what's the error i experience here?

Link to comment
Share on other sites

Could be a multitude of errors, usually syntactical.  Put this at the top of the pages that display blank right after your opening <?php tag:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Link to comment
Share on other sites

Could be a multitude of errors, usually syntactical.  Put this at the top of the pages that display blank right after your opening <?php tag:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

for testing purpose, while site development process, the above script is put on the top of every php file?

 

and the script should put above session_start() or below session_start() because i was told that session_start() must put at the very beginning line of the php file?

Link to comment
Share on other sites

session_start() just needs to go before any output.

 

is not valid

<h1>Welcome!</h1>
<?php
session_start();
?>

 

is valid

<?php
session_start();
?>
<h1>Welcome!</h1>

 

but, what i meant is

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

not other code...is that the above code should put before session_start()?

Link to comment
Share on other sites

Put this at the top of the pages that display blank right after your opening <?php tag:

 

sorry, i'm a bit poor in english, so not too sure what it meant? is that?

 

<?php ini_set ("display_errors", "1");
         error_reporting(E_ALL);
         session_start();
?>

Link to comment
Share on other sites

Almost, the ini should be on a separate line.

 

<?php 

ini_set ("display_errors", "1");
error_reporting(E_ALL);
session_start();

?>

 

ok, thanks a lot!

when i try this, i found almost all my pages got error displayed...

 

is that need to ensure all these errors are solved?

as a newbie, till now i'm only know got such script to test for the error...so, really need more guidance in this case...

 

and most of the error i get is like

 

Notice: Use of undefined constant myvariable - assumed 'myvariable' in /home/mytest/domains/mytestsite.com/public_html/mylogin.php on line 61

 

some of 'myvariable' is used in my GET link...

what's this error meant? and how can i debug it?

thanks again!

Link to comment
Share on other sites

Can I see that portion of the code?

 

ok, this is the line of codes that create the error in my login page

 

mylogin.php

if (isset($_GET[loginfo])){
      if($_GET[loginfo]==1){
         session_destroy();

         echo "<META HTTP-EQUIV='refresh' content='0;URL=mylogin.php'>";
      }
  }

 

and the above code will be called, when user click a link from another file to logout(this is code in another php file.)

<a href="mylogin.php?loginfo=1">Logout</a>

 

as i have mentioned, almost all errors i get is 'use of undefined constant...'

so, i really need to know where my mistake has create such error...to debug all the files.

 

thanks for the help!

Link to comment
Share on other sites

The notices are stemming from your array, you need to put single quotes around the associative key. i.e.:

 

$_GET['loginfo']

 

You should do this with all your POST, GET, and associative array values.  Everything else looks fine to me.  The notices are appearing because of the error reporting we turned on.  Change that and tell me if the pages still turn up blank, like I said before, that usually means there's a syntax error somewhere.  Do you get any other errors?

 

(If that's not line 61 in mylogin.php, we need to see that and some surrounding code, before and after line 61.)

Link to comment
Share on other sites

The notices are stemming from your array, you need to put single quotes around the associative key. i.e.:

 

$_GET['loginfo']

 

You should do this with all your POST, GET, and associative array values.  Everything else looks fine to me.  The notices are appearing because of the error reporting we turned on.  Change that and tell me if the pages still turn up blank, like I said before, that usually means there's a syntax error somewhere.  Do you get any other errors?

 

(If that's not line 61 in mylogin.php, we need to see that and some surrounding code, before and after line 61.)

 

really thanks a lot! i have added single quote for some of the cases, and it solve the error. i need to check back all those error because it's quite a lot.

 

here, got another kind of error, it's happen for my combox box, the error just appear inside the combo

 

Notice: Undefined index: lang in C:\xampp\htdocs\myfolder\mypage.php on line 187>English

Notice: Undefined index: lang in C:\xampp\htdocs\myfolder\mypage.php on line 188>Chinese

 

and this is my line 187 and 188

<option value="English" <?php if($_SESSION['lang']=="English"){?>selected<?php } ?>>English</option>
<option value="Chinese" <?php if($_SESSION['lang']=="Chinese"){?>selected<?php } ?>>Chinese</option>

 

thanks again!

Link to comment
Share on other sites

Before the select menu put this line in:

 

$_SESSION['lang'] = (isset($_SESSION['lang'])) ? $_SERVER['lang'] : "English";

 

This will assign $_SESSION['lang'] to English if it is not set, if it is then it will stay the same.  The error you were seeing was due to that session variable not being set, if you want the default selected language to be something else, then just change English to whatever you want.

Link to comment
Share on other sites

I always turn notices like that off because they don't really effect anything.  I believe you need to make it:

 

if (isset($_SESSION['lang'])){ before the check of $_SESSION['lang']:

 

<option value="English" <?php if (isset($_SESSION['lang'])){ if($_SESSION['lang']=="English"){?>selected<?php } } ?>>English</option>

<option value="Chinese" <?php if (isset($_SESSION['lang'])){ if($_SESSION['lang']=="Chinese"){?>selected<?php } } ?>>Chinese</option>

 

Link to comment
Share on other sites

I always turn notices like that off because they don't really effect anything.  I believe you need to make it:

 

I agree, but it's good to have them on for when developing on development environment.  The notices won't cause fatal errors but could potentially cause other problems like you're seeing in your situation.  In a live environment you don't want these turned on.

 

The code I provided does effectively the same thing as fanfavorites, but mine will give you a default value, and is only 1 line  ;)

Link to comment
Share on other sites

Before the select menu put this line in:

 

$_SESSION['lang'] = (isset($_SESSION['lang'])) ? $_SERVER['lang'] : "English";

 

This will assign $_SESSION['lang'] to English if it is not set, if it is then it will stay the same.  The error you were seeing was due to that session variable not being set, if you want the default selected language to be something else, then just change English to whatever you want.

 

yup, your code again solve my problem...thanks!

 

for the previous case about the blank page, do you think that is really my problem of not include single quote for my GET value? the blank page won't happen every time...for example, when i load the page and it turn up as blank, then i just click the refresh key of my browser, then the page just appear...so, is that the single quote problem will causing such problem?

 

and for your information, the happen of the blank page that i experienced for a few times are happen just after i modify the php file and upload to the hosting.

Link to comment
Share on other sites

All the errors that you posted are just notices/warnings and will not cause a blank page.  Blank pages are usually caused by, like I've said before, fatal syntax errors.  Are there any actually errors?

 

for example, when i load the page and it turn up as blank, then i just click the refresh key of my browser, then the page just appear...so, is that the single quote problem will causing such problem?

 

No that wouldn't cause a blank page.  It's hard to tell without looking at your code.  Can you post your entire code?

Link to comment
Share on other sites

All the errors that you posted are just notices/warnings and will not cause a blank page.  Blank pages are usually caused by, like I've said before, fatal syntax errors.  Are there any actually errors?

so, will the fatal syntax errors displayed when the error_reporting is turned off? i get no error when the error_reporting is turned off last time...

 

No that wouldn't cause a blank page.  It's hard to tell without looking at your code.  Can you post your entire code?

 

but, the code is quite long and not only happen on 1 page. for your information, a few times happen on my login page and got another time, when i clicked a a href link to open an edit page but end up with open my login page as blank...

 

so, which part of code i should provide to you?

Link to comment
Share on other sites

i have a page that will be opened in new browser when a link in an sent email is clicked. for that page, i try to open it with IE, and always end up with open as blank page. but, if using mozilla, all of my test, only one fail, not a blank page but an error of connection interrupted...i just can't guess what's the problem? is my code problem?

 

so, if i provide the code of this page here, is it useful for you expert to help me to track the error?

 

thanks!

Link to comment
Share on other sites

IE is slower than most other browsers, so could be timing out at a certain point.  I ran into a similar issue once where it randomly would display a blank page instead of loading the page.  I contacted the host of the clients and they were able to resolve it.  I can't remember exactly what the cause was though. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.