milosev.com
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
      • Italy2022
      • Côte d'Azur 2024
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home

Passing $_POST variable to redirected page.

Details
Written by: Stanko Milosev
Category: PHP
Published: 08 September 2008
Last Updated: 18 July 2011
Hits: 6232

If you need to redirect page and pass $_POST variable (or any other variable) you should use following code:

<?php
header("HTTP/1.0 307 Temporary redirect");
header("Location: http://localhost/test.php");
?>

List all files in a directory tree.

Details
Written by: Stanko Milosev
Category: PHP
Published: 03 September 2008
Last Updated: 03 March 2015
Hits: 6264
I am too lazy, I know.

Here is recursive way:

<?php
	function rec_listFiles( $from = '.')
	{
		if(! is_dir($from))
		return false;

		$files = array();
		if( $dh = opendir($from))
		{
			while( false !== ($file = readdir($dh)))
			{
				// Skip '.' and '..'
				if( $file == '.' || $file == '..')
				continue;
				$path = $from . '/' . $file;
				if( is_dir($path) )
				$files += rec_listFiles($path);
				else
				$files[] = $path;
			}
			closedir($dh);
		}
		return $files;
	}
?>
And here is iterative:
<?php
	function listFiles( $from = '.')
	{
		if(! is_dir($from))
		return false;
		$files = array();
		$dirs = array( $from);
		while( NULL !== ($dir = array_pop( $dirs)))
		{
			if( $dh = opendir($dir))
			{
				while( false !== ($file = readdir($dh)))
				{
					if( $file == '.' || $file == '..')
					continue;
					$path = $dir . '/' . $file;
					if( is_dir($path))
					$dirs[] = $path;
					else
					$files[] = $path;
				}
				closedir($dh);
			}
		}

		return $files;
	}
?>
Searching for a file in a directory tree:
<?php
	function rec_listFiles( $fileName, $from = '.', &$pathOut)
	{
		if ($pathOut != '')
			return true;
		else
		{

			if(! is_dir($from))
				return false;

			if( $dh = opendir($from))
			{
				while( false !== ($file = readdir($dh)))
				{
					// Skip '.' and '..'
					if( $file == '.' || $file == '..')
						continue;
					$path = $from . '/' . $file;
					if( is_dir($path) )
					{
						//echo $path.'<p/>';
						rec_listFiles($fileName, $path, $pathOut);
					}
					else
					{
						if ($fileName == $file)
						{
							$pathOut = $path;
						}
					}
				}
			closedir($dh);
			}
			if ($pathOut == '')
				return false;
			else
				return true;
		}
	}

	$pom = '';
	if (rec_listFiles('mod_newsflash.php', '.', $pom))
	echo $pom;
	else
	echo 'Could not find file.';
?>

NuSoap

Details
Written by: Stanko Milosev
Category: PHP
Published: 29 August 2008
Last Updated: 10 September 2008
Hits: 7749

Here are my expirience in working with NuSoap (SOAP) in PHP.

Creating simple SOAP function is simple, so there is no need to explain.

Problems are coming when you need a complex types, like array, and UTF-8 encoding.

Here is an example of adding complex type to your SOAP server:

$server->wsdl->addComplexType(
'Chapter', //name
'complexType', //typeClass (complexType|simpleType|attribut)
'struct', //phpType: currently supported are array and struct (php assoc array)
'all', //compositor (all|sequence|choice)
'', //restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
array( //elements = array ( name = array(name=>>,type=>>) )
'title' => array('name'=>'title','type'=>'xsd:string'),
'page' => array('name'=>'page','type'=>'xsd:int')
) );
$server->wsdl->addComplexType(
'ChapterArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Chapter[]')
),
'tns:Chapter' );

$server->wsdl->addComplexType(
'Book',
'complexType',
'struct',
'all',
'',
array(
'author' => array('name'=>'author','type'=>'xsd:string'),
'title' => array('name'=>'title','type'=>'xsd:string'),
'numpages' => array('name'=>'numpages','type'=>'xsd:int'),
'toc' => array('name'=>'toc','type'=>'tns:ChapterArray')
) );

$server->register(
'getBook', // method name
array('title'=>'xsd:string'), // input parameters
array
('return'=>'tns:Book'), // output parameters
$NAMESPACE); // namespace

function
getBook($title) {
// Create TOC
$toc = array();
$toc[] = array('title' => 'Chapter One', 'page' => 1);
$toc[] = array('title' => 'Chapter Two', 'page' => 30);

// Create book
$book = array(
'author' => "Jack London",
'title' => $title,
'numpages' => 42,
'toc' => $toc);

return $book;
}

Taken from here.

Comments are taken from here.

Client example:

<?php
require_once('nusoap.php');

$namep = "Title";
$param = array('String_1' => $namep);

$endpoint = "http://localhost/server.php";

$mynamespace = "http://
localhost/server.php";
$client = new soapclient($endpoint);

$client->decodeUTF8 = true;
$response = $client->call('
getBook', $param, $mynamespace);
print_r ($response['author']);
echo '<p/>'.$client->response;
?>

Now, if you want to use utf - 8, you will have to in nusoap.php on line 152, instead of:

var $soap_defencoding = 'ISO-8859-1';

Add or uncomment:

var $soap_defencoding = 'UTF-8';

Also, on server side I added:

$server->decode_utf8 = true;

If you are using MySQL and data are encoded in Windows-1252 (like mine) then you will need to put:

mysql_query('set names utf8');

In your server side.

I hope that is all.

Instalation PHP 5.2.6 on Windows XP IIS

Details
Written by: Stanko Milosev
Category: PHP
Published: 27 August 2008
Last Updated: 30 November -0001
Hits: 5365

If you are receiving error "The specified module could not be found." then try to instead of "C:Program FilesPHPphp5isapi.dll" write C:Progra~1PHPphp5isapi.dll (without quotes) in Web Sites node, and in Default Web Site node, or any other. Right -> Properties -> Home Directory -> Cofiguration, find .php and click edit.

Also,extension are now in C:Program FilesPHPext, so if you are using MS SQL PHP extension for MS SQL then you will need manually to copy files php_sqlsrv_ts.dll and php_sqlsrv.dll to that folder.

Taken from my brain :P

  1. Parametrized query
  2. Saving file.
  3. Check if anything is assigned to $_GET
  4. Installing the GitHub Copilot CLI on Windows 11

Subcategories

C#

Azure

ASP.NET

JavaScript

Software Development Philosophy

MS SQL

IBM WebSphere MQ

MySQL

Joomla

Delphi

PHP

Windows

Life

Lazarus

Downloads

Android

CSS

Chrome

HTML

Linux

Eclipse

Page 104 of 168

  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108