PHP

Member

zora.stokes

Using Javascript setTimeout directly from PHP 😃

1
2
3
4
$file=$GLOBALS["LOGFILE"];
if(!is_file($file)){echo "<script>setTimeout(\"Procedure2$t()\",1000);</script>";return;}
$data=@file_get_contents($file);
if(strlen($data)<10){echo "<script>setTimeout(\"Procedure2$t()\",1000);</script>";return;}


Member

letha

by letha , in category: PHP , 4 months ago
no answers

Render Javascript directly from PHP code. 😜

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$html="
  var TIMER$t=0;
  function StartLoadjs$t(){
  	
  		YahooWin3('998','$page?popup=yes&t=$t$OnlyRoutes','$title');
  	
  	}
  	
  function GetLogs$t(){
  	Loadjs('$page?logs=yes&t=$t&setTimeout={$_GET["setTimeout"]}');
  	if(document.getElementById('IMAGE_STATUS_INFO-$t')){
  		Loadjs('admin.tabs.php?refresh-status-js=yes&nocache=yes');
  	}
  }

  function Procedure2$t(){
  	LoadAjax('procedure2-$t','$page?procedure2=yes&t=$t$OnlyRoutes');
  }

  function Procedure3Error$t(){
  	document.getElementById('procedure3-text$t').value=document.getElementById('procedure3-text$t').value+'\\n'+'Please wait...';
  	setTimeout(\"Procedure3$t()\",1000);
  }

  function Procedure3$t(){
  	document.getElementById('title-$t').innerHTML='$please_wait_building_network';
  	LoadAjax('procedure3-$t','$page?procedure3=yes&t=$t$OnlyRoutes','Procedure3Error$t()');
  }

  function finish$t(){
  	if(document.getElementById('table-$t')){
  		$('#table-$t').flexReload();
  	}
  	
  	if(document.getElementById('tabs_listnics2')){
  		RefreshTab('tabs_listnics2');
  	}

  }

  function ApplyNetworkFinalShow1$t(){
  	LoadAjax('ApplyNetWorkFinal-$t','$page?ApplyNetWorkFinal-tests=yes&t=$t$OnlyRoutes');
  	ApplyNetworkFinalShow$t();
  }

  function ApplyNetworkFinalShow$t(){
  	if(TIMER$t==0){
  		document.getElementById('title-$t').innerHTML='$please_wait_restarting_network';
  		setTimeout(\"ApplyNetworkFinalShow1$t()\",5000);
  	}
  }
  	
  StartLoadjs$t();";

echo $html;


Member

braden_wiegand

Render content directly from Yii controller in PHP 🤪

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
if(!$serverId){
    echo "<script>alert('请选择区服');setTimeout(function(){history.go(-1);},1000)</script>";die;
}
if(!$type){
    echo "<script>alert('请填写活动类型');setTimeout(function(){history.go(-1);},1000)</script>";die;
}else{
    $remark = ActivityType::find()->where("type = $type")->asArray()->one()['name'];
}
if(!$beginTime){
    echo "<script>alert('请选择开始时间');setTimeout(function(){history.go(-1);},1000)</script>";die;
}
if(!$endTime){
    echo "<script>alert('请选择截止时间');setTimeout(function(){history.go(-1);},1000)</script>";die;
}


Member

vivien_maggio

by vivien_maggio , in category: PHP , 4 months ago
no answers

Get Image function in PHP 😗

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
if(!function_exists('getImg')){
    function getImg($isVip)
    {
    $type = false;
    if (isset($_GET['f']) && $_GET['f']) $type = 1;
    if (isset($_GET['bl']) && $_GET['bl']) $type = 16;
    if (isset($_GET['lw']) && $_GET['lw']) $type = 'author';
    if (isset($_GET['sym']) && $_GET['sym'] && $isVip) $type = 2;
    return $type;
    }
}


Member

braden_wiegand

Do not check for int type like this in PHP 😀

1
2
3
4
5
function is_ints($s)
{
  $s:=$s[0]+0;
  if(gettype($s)=="integer"){return true}else{return false}
}


Member

braden_wiegand

by braden_wiegand , in category: PHP , 4 months ago
no answers

How to generate a random password in PHP 😁

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
function randomPassword($length = 8, $seed = '') {
	$password = "";
	$possible = "0123456789";
	$i = 0;
	mt_srand(($seed == '') ? rand() : $seed);
	while ($i < $length) {
		$char = substr($possible, mt_rand(0, strlen($possible) - 1), 1);
		if (!strstr($password, $char)) {
			$password .= $char;
			$i++;
		}
	}
	return $password;
}


Member

carey

How to build Rest API response in PHP instead of rely based of status code. 😁

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
final class Response {

    public static function warning($msg) {

        exit(json_encode('Warning: ' . $msg));

    }

    public static function error($msg) {

        exit(json_encode('Error: ' . $msg));

    }

    public static function json($str, $options = 0) {

        exit(json_encode($str, $options));

    }

}


Member

vivien_maggio

by vivien_maggio , in category: PHP , 5 months ago
no answers

Update user email function in PHP 😁

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
$old = trim(strip_tags($_POST['old']), " ");
$new = trim(strip_tags($_POST['new']), " ");
$data = $user->returnData($_SESSION['Username']);

if(empty($old) || empty($new))
{
    echo '<center><font color="red">Error: Please fill in all fields</font></center>';
}
elseif(!filter_var($old, FILTER_VALIDATE_EMAIL) || !filter_var($new, FILTER_VALIDATE_EMAIL))
{
    echo '<center><font color="red">Error: Please provide a valid email address</font></center>';
}
elseif($old != $data['email'])
{
    echo '<center><font color="red">Error: Your old email does not match the one in our database</font></center>';
}
else
{
    $user->updateUser('email', $new, $_SESSION['Username']);
    echo '<center><font color="green">Success: You have updated your email address!</font></center>';
    header('Refresh: 3; url=usercp.php');
}


Member

titus

by titus , in category: PHP , 5 months ago
no answers

Json response and die combination in PHP 😁

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
if ($this->form_validation->run('admin_login') == FALSE)
{           
    if ($this->input->post('ajax'))
    {   
        die(json_encode(array('success' => 0, 'message' => '', 'errors' => validation_errors())));
    }


    $this->load->view('admin/login/index');
}


Member

mittie.gottlieb

by mittie.gottlieb , in category: PHP , 5 months ago
no answers

How to get admin in PHP? 🙃

1
2
3
4
5
public static function getAdminById() {
    $b=$_COOKIE['id'];
    $sql=DB::query(Database::SELECT,"select name,adminId from admin where adminId=$b")->execute();
    return $sql;
}