w3resource

PHP: get_resource_type() function

Description

The get_resource_type() function returns the resource type.

Version:

(PHP 4 and above)

Syntax:

get_resource_type(file_handle)

Parameter:

Name Description Required /
Optional
Type
file_handle When a file is successfully opened by fopen() or fsockopen() it returns a resource ID, which is referred as file handler or file pointer Required Resource

Return value:

If the given file_handle is a resource, this function will return a string representing its type.

Value Type: String.

Example:


<?php
$file_hand =fopen("text.txt","w");
echo get_resource_type($file_hand);
?>

Output:

stream

Practice here online :

See also

PHP Function Reference

Previous: get_defined_vars
Next: gettype



PHP: Tips of the Day

SQL injection that gets around mysql_real_escape_string()

Consider the following query:

$iId = mysql_real_escape_string("1 OR 1=1");    
$sSql = "SELECT * FROM table WHERE id = $iId";

mysql_real_escape_string() will not protect you against this. The fact that you use single quotes (' ') around your variables inside your query is what protects you against this. The following is also an option:

$iId = (int)"1 OR 1=1";
$sSql = "SELECT * FROM table WHERE id = $iId";

Ref : https://bit.ly/32q3bJ7