Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Captcha code not working

Featured Replies

Hello friends,

I am new to php and was following a youtube tutorial

to create captcha

but the code doesn't generate  random number as i see in the tutorial

 

here is the code

 

index.php

<?php
 //ini_set('display_errors','1');
//error_reporting(E_ALL);
  session_start();
  
  $_SESSION["secure"] =rand(1000,9999);
?>

<img src="generate.php"/>

and the code for generate.php

<?php
session_start();
header("Content-type: image/jpeg");

$text =$_SESSION["secure"];
$font_size =30;

$image_width =200;
$image_height =40;

$image = imagecreate($image_width,$image_height);

imagecolorallocate($image,255,255,255);

$text_color = imagecolorallocate($image,0,0,0);

imagettftext($image,$font_size,0,15,30,$text_color,"font.ttf",$text);
imagejpeg($image);
?>

i have attached the font.ttf file font.ttf

but when i run index.php all i see is blank page

i checked php error log on wamp server

it says the error on this line

Quote

 imagettftext($image,$font_size,0,15,30,$text_color,"font.ttf",$text);

but not sure how to fix

 

any help will be highly appreciated

Edited by sash_oo7
replaced font.ttf file

  • Author
5 hours ago, davep said:

why is your font named font.ttf.ttf? i.e. a double extension?

 

I replaced it with font.ttf but still same result..blank page

Lots of useful advice here along with working examples:

https://www.php.net/manual/en/function.imagettftext.php

I suspect the error is your font path

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.