Search This Blog

Loading...
Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Thursday, October 16, 2014

404 - File or directory not found. when use codeigniter in windows iis

Facing error message when deploy codeigniter php site to windows server 2013 (iis8)


404 - File or directory not found.

The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.


The main issue is because of the url rewrite doesn't work in IIS without proper setting in web.config (IIS doesn't read .htacess)

What we need to do is open web.config

Add code below into the correct


<rewrite>
  <rules>
    <rule name="Rule" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
        <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
    </rule>
  </rules>
</rewrite> 

>


If you are want to create the new web.config without others configuration, the web.config shoud looks like this

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<system.webServer>

    <httpErrors errorMode="Detailed" />
    <asp scriptErrorSentToBrowser="true"/>

   <rewrite>
  <rules>
    <rule name="Rule" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
        <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
    </rule>
  </rules>
</rewrite> 

</system.webServer>


</configuration> 
Hope this helps




Friday, September 26, 2014

Cannot modify header information - headers already sent by

Facing error when try to use codeigniter and the page won't redirect after update / edit

 A PHP Error was encountered

    Severity: Warning

    Message: Cannot modify header information - headers already sent by (output started at xxxxx:1)

    Filename: libraries/Session.php

    Line Number: 675
 A PHP Error was encountered

    Severity: Warning

    Message: Cannot modify header information - headers already sent by (output started at xxxxx:1)

    Filename: helpers/url_helper.php

    Line Number: 542

How to solve my issue?

open index.php and add ob_start();  like below

ob_start();

/*
 *---------------------------------------------------------------
 * APPLICATION ENVIRONMENT
 *---------------------------------------------------------------
 *
 * You can load different configurations depending on your
 * current environment. Setting the environment also influences
 * things like logging and error reporting.
 *
 * This can be set to anything, but default usage is:
 *
 *     development
 *     testing
 *     production
 *
 * NOTE: If you change these, also change the error_reporting() code below
 *
 */

Thursday, October 10, 2013

Error Message 500 – Internal server error when try to access image uploaded into wordpress in IIS

When try to access to the photo / image that uploaded in WordPress that setup in IIS 7, Windows Server 2008 R2, error message below displayed:

Issue:

Server Error 

500 – Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.




This is the big issue because all the uploaded image cannot displayed in the browser when click on it. Although we have granted the modify permission for user IUSR and {servername}\IIS_IUSRS to the directory and childdirectory /blog/wp-content/uploads/subdirectory but it still cannot be displayed.

Root Cause:
After check around, we found out that when we use PHP to upload a file. PHP will sends the file to a temporary directory on the hard drive (In my case C:\Windows\Temp) and then copies it over to it’s intended directory. You can find which one is the temporary folder by checking on the line “upload_tmp_dir” in php.ini.

Solution: 
Go to C:\Windows\Temp folder, grant “modify” permissions to both IUSR and {servername}\IIS_IUSRS user accounts.

It solve my problem.

Wednesday, November 2, 2011

Warning: Please select a file! in Opencart

I'm using Opencart version 1.9.4.3,  windows server 2003, IIS 6 and PHP Version 5.3.8. Try to upload image in opencart and error message "Warning: Please select a file!" prompted.



After check on the php eror log file, The error log show "Warning: File upload error - unable to create a temporary file in Unknown on line 0"

Solution for this issue is edit upload_tmp_dir in php.ini.

For example, change to
upload_tmp_dir = "C:\PHP\temp"

after the finish edit, restart the web server.

Done. Problem solved.

Friday, March 4, 2011

rename htaccess.txt to .htaccess in windows

We will hit error when try to rename htaccess.txt to .htaccess in windows. Error message "You must type a file name."



.htaccess is usually used in php application like joomla and some of the shopping card. The purpose is to provide more user friendly url for SEO purposes or reading purposes by using Apache mod_rewrite.

To overcome this problem, we need to use windows command promp to rename the file. Below is the step by step how we can solve the problem.



  1. Go to windows start and click on Run.


  2. Type cmd in the text box and hit enter


  3. A command prompt will popup, change to the folder location your file htaccess.txt located. In my sample, my file located in C:\temp_folder. So i type

    cd C:\temp_folder

    and hit enter. My current directory will be in "C:\temp_folder"


  4. Use ren command to rename the file.

    type ren .htaccess.txt .htacess

    and hit enter.


    Done.


Hope this help.

Sunday, October 11, 2009

PHP: Warning: split() [function.split]: REG_EMPTY in xxx

I try to php split to split out the concatenated data. Below are the sample that i use

$comp = "V1001|VI003";

$comp_arr = split("|",$comp);

i hit error:

PHP: Warning: split() [function.split]: REG_EMPTY in xxx

after search around and found that the issue is caused by symbol "|".
"|" is an operator in PHP. If want to use the this symbol as a delimiter, we must excape it with a back slash, "\|"

now it become

$comp = "V1001|VI003";

$comp_arr = split("\|",$comp);

and it works.

Hope this help

Sunday, September 27, 2009

phpsoap: retrieve returned array data

Well, i'm newbie in soap especially phpsoap. I'm facing problem to retrieve data returned from a soap api written in .net. I can see the whole data printed out by using print_r but i'm not able to get the each data from the array returned.

Situation:
I want to get the data returned by the soap server in array form after i've called the function "GetAccountInfo" by passing in parameter "AccoundID" by using phpsoap client.
My soap server url: http://10.10.100.101/soapserver.asmx

below are the code that i can get the data printed out.
<?php
$ini = ini_set("soap.wsdl_cache_enabled","0");

//instantiate the SOAP client
$client = new SoapClient("http://10.10.100.101/soapserver.asmx?WSDL");

$params = array();
$params["AccountID"] = "inblues";

$result = $client->GetAccountInfo($params);
print_r ($result ->GetAccountInfoResult);

?>

Output on the browser:


Array (
[GetAccountInfoResult] => Array (
[memberData] => Array (
[lastlogin] => 6/19/2009 2:10:51 AM
[lastip] => 219.95.192.254
[datecreated] => 6/19/2009 2:10:51 AM
[active] => 1
)
)
)



But what i want is only [active] field's data. What can i do? Finally, by looking at the printed result and by try and error, i found out that it's a 3 dimensional array, below code helps me to get the data i want.

<?php
$ini = ini_set("soap.wsdl_cache_enabled","0");

//instantiate the SOAP client
$client = new SoapClient("http://10.10.100.101/soapserver.asmx?WSDL");

$params = array();
$params["AccountID"] = "inblues";

$result = $client->GetAccountInfo($params);

// the result is in 3 dimensional array
print_r ($result->GetAccountInfoResult->memberData-> active);

?>

Solve. I get my value 1 printed out in the browser.

Monday, July 13, 2009

Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0

this will happen in linux server when the owner permissions is set to read/write/execute only. There is no public and group permissions setting. To solve this, i can the permissions to 755.

Problem solved.

Friday, June 5, 2009

PHP call external cgi and process responses

This is tough for me. First time to code in PHP with cgi and don't know how to start. Thanks google for this.

My task is call a cgi script to execute some function and process the return data. Well, here i'll mention on how to call external cgi and the process part can be settled using PHP string processing.

Let's start by example:

cgi domain location: www.xincube.com/script/handler/api.cgi

The code will strip header below and return the content of the response data.

HTTP/1.1 200 OK
Date: Sat, 06 Jun 2009 02:23:33 GMT
Server: Apache
Proxy-x-forwarded-for: 203.116.10.206
X-returncode: 0
X-returndesc: Access denied
Cache-control: no-cache
Pragma: no-cache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/plain

We can do anything we want to get the information we need in $content.

CODE:

/* sample for calling cgi */
$host = 'www.xincube.com';
$path = '/scripts/handler/API.cgi';

$data_to_send = 'action=GetSupportedData';


PostToHost($host, $path, $data_to_send);

/* function that will call cgi */
function PostToHost($host, $path, $data_to_send) {

$header = "not yet";
$content = '';
$fp = fsockopen($host,80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)\n";
}
else {
fputs($fp, "POST $path HTTP/1.1\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: ".strlen($data_to_send)."\n");
fputs($fp, "Connection: close\n\n");
fputs($fp, $data_to_send);

while(!feof($fp)) {
//echo fgets($fp, 4000);
$line = fgets( $fp, 4000 );
if( $line == "\r\n" && $header == "not yet" ) {
$header = "passed";
}
if( $header == "passed" ) {
$content .= $line;
}
}
echo $content;
fclose($fp);
}
}


Hope this help. Support me to write more by clicking on the ads sponsor or donation. Thanks

Friday, December 12, 2008

AJAX PHP CAPTCHA

Thanks for http://www.phpcaptcha.org/documentation/quickstart/ provide a cool php captcha code. One of my colleague supporting a php site which need CAPTCHA to prevent spamming but most of the example given needed page post back which is not so practical. I have implement an AJAX CAPTCHA for ASP in my previous post on AJAX ASP CAPTCHA.

Now, we are using the same method to implement in PHP. By reuse the same javascript code with jquery, there is only a small changes in PHP part. Within 20 minutes, the code done and tested working. The files available for download here.

Happy programming. Please let me know if you have any problem.

Sunday, September 14, 2008

osticket - admin login error "Authentication Required"

i have tried to setup osticket few times and i'm very sure that my admin username and password is correct but i still got error message "Authentication Required"

After browse and google around, i found one solution to enable me to login but i'm not sure what is the effact for this change.

go to scp/staff.inc.php, and find the line below

//1) is the user Logged in for real && is staff.
if(!is_object($thisuser) !$thisuser->getId() !$thisuser->isValid()){

comment out !$thisuser->isValid() and now become

if(!is_object($thisuser) !$thisuser->getId() /* !$thisuser->isValid()*/){

go to try again. it's working. Perhap, someone can tell me what is the issue and i'm not php expert. Not working on 15 Sep 2008

Update: 15 Sep 2008
No Luck. It only work for one day. Not sure what happen and now not working. I'll keep updating this post until get some solution or work around. I have to un comment previous changes.

Solution:
line 41 in scp\login.php, comment out @header("Location: $dest"); and try again.
// @header("Location: $dest");
it's work for me, at least for now.

Update: 21 Sep 2008
It's working fine since changes on 15 Sep 2008. SOLVED!