Crea sito

Archivio per la categoria php

How to redirect to an other URL with PHP

Using PHP, there is a very easy way to redirect the web page that you’re visiting to an other URL. To do that you need to use the method header, in this way: header(“Location: new URL”); Example: <?php /* Redirect browser */ header(“Location:”); exit; ?> The method header is used to send a raw HTTP header. […]

Client TCP with PHP

Here there is a simple example of tcp client written in php that tries to connect to a server, sends to it 2 messages and prints the server replies <?php /* Get the port for the WWW service. */ $service_port = getservbyname(‘www’, ‘tcp’); /*if you already know the destination port, you don’t need getservbyname, you can […]

Tags: , , ,

Server TCP with PHP

Here there is a simple example of tcp server written in php that accepts a connection from a client and for each message that the client sends to the server, it reply with the same message. <?php /* Allow the script to hang around waiting for connections. */ set_time_limit(0); /* Turn on implicit output flushing […]

Tags: , , ,

How to use php to extract xml value

How to use php to extract a value of a field from an xml file: -Example of xml file: <?xml version=”1.0″ encoding=”UTF-8″?> <o> <meta class=”object”> <id>200</id> </meta> </o> -PHP script that will print the value of meta class and id: <?php $input_file = “path of xml file”; $xml = @simplexml_load_file($input_file) or die (“no file loaded”) […]

Tags: ,

How to run php script on linux shell

How to run a php script on a Linux shell as a normal script: -name of the script:    script_name.php -Inside the script: #!/usr/bin/php <?php Here you can insert your php code ?> -On the shell: chmod +x script_name.php ./script_name.php -Done!!

Tags: , , ,