-
Posts
251 -
Joined
-
Last visited
Never
Posts posted by Tandem
-
-
[code]<?php
ob_start();
header('Content-type: image/png');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
$img = array();
//////////
// Image settings...
//////////
# Image width in pixels:
$img['width'] = 65;
# Image height in pixels:
$img['height'] = 30;
# Use TTF?
$img['use_ttf'] = true;
# Link to image true type font (only if above value is true):
$img['ttf_font'] = "verdana";
# TTF pt size?
$img['ttf_size'] = 12;
# Not using TTF? Still need a font size. (1-5)
$img['normal_font_size'] = 4;
# Image handle:
$img['handle'] = imagecreatetruecolor($img['width'],
$img['height']);
//////////
// Colors...
//////////
# Black:
$colors['black'] = imagecolorallocate($img['handle'],
0, 0, 0);
# White:
$colors['white'] = imagecolorallocate($img['handle'],
255, 255,
255);
# Gray:
$colors['gray'] = imagecolorallocate($img['handle'],
(255 / 2), (255 / 2),
(255 / 2));
# Red:
$colors['red'] = imagecolorallocate($img['handle'],
255, 0, 0);
# Transparent:
$colors['transparent'] = imagecolorallocate
($img['handle'], 1, 1, 1);
$colors['transparent'] = imagecolortransparent
($img['handle'], $colors['transparent']);
//////////
// Time to get drawing!
//////////
# Background:
imagefilledrectangle($img['handle'], 0, 0,
$img['width'], $img['width'], $colors['black']);
# Left border:
imageline($img['handle'], 0, 0, 0,
$img['height'], $colors['gray']);
# Top border:
imageline($img['handle'], 0, 0,
$img['width'], 0, $colors['gray']);
# Bottom border:
imageline($img['handle'], 0, $img['height'] - 1,
$img['width'], $img['height'] - 1, $colors['gray']);
# Right border:
imageline($img['handle'], $img['width'] - 1, 0,
$img['width'] - 1, $img['height'] - 1, $colors['gray']);
//////////
// Create the string and draw it.
//////////
$img['random_string'] =
strtoupper(substr(md5(uniqid(rand(),true)),0,6));
if($img['use_ttf'] ==
true && file_exists($img['ttf_font'].".ttf"))
{
$img['random_angle'] = rand(-45/4, 45/4);
imagettftext($img['handle'],$img['ttf_size'],$img['random_angle'],
(($img['width'] / 2) - (imagefontwidth($img['ttf_font'])
* strlen($img['random_string']))) + 2,($img['height'] / 2)
+ 2,$colors['gray'],$img['ttf_font'], $img['random_string']);
imagettftext($img['handle'],$img['ttf_size'],
$img['random_angle'],($img['width'] / 2) -
(imagefontwidth($img['ttf_font'])
* strlen($img['random_string'])),$img['height'] / 2,
$colors['white'],$img['ttf_font'],$img['random_string']);
} else {
imagestring($img['handle'],$img['normal_font_size'],(
$img['width'] / 2) - $img['normal_font_size']
* strlen($img['random_string']),$img['height'] /
2.5,$img['random_string'],$colors['white']);
}
//////////
// Finish up...
//////////
imagepng($img['handle']);
imagedestroy($img['handle']);
?>[/code]
Just save the code into a new file, and then use:
<img src="filename.php">
Should work.
Note: It produces an alphanumeric string, so you may need to change it to suit your needs. -
Is it possible to get the HTML code of a remote page into a variable? Or is it only the textual output that you can get?
I've used file_get_contents() before to get the contents of remote pages but i've only ever used it for pages with only text in them
Thanks in advance for any replies. -
One method of checking if the query was successful:
[code]
$result2 = mysql_query("SELECT expyear, expmonth, ccnumber FROM xxxxx ORDER BY id DESC") or die(mysql_error());
$result2_num = mysql_num_rows($result2);
if ($result2_num > 0) {
$result3 = mysql_fetch_array($result2);
}
if ($result2_num < 1) {
echo "Unsuccessful";
}
[/code] -
The problem with that is that i echo some other messages to go at the top of the included page if the validation is successful.
I don't think it is possible for me to keep the message due to the structure of my script, was just asking on the off chance that there was a magic function that would solve my problems :P
Thanks for the replies. -
Yeah i can do that, it's just it is a useful indicator and was wondering if there was any way for it to be saved rather than having to scrap it. I guess not though.
Thanks for the replies. -
Sorry, it's not as simple as that.
The original echo needs to be done before the validation begins, but if the validation is successful then i include a different page (can't use headers in this instance) and exit the script before anything else but the text is output, but then i am left with an obscure output at the top of the included page. I'm asking if there is any sort of function or way that stops anything that has already been told to output, from actually being output so that i'm not left with the obscure message at the top of the included page. -
Add a or die(mysql_error()) to the end of the query in question, i.e.
$result2 = mysql_query("SELECT expyear, expmonth, ccnumber FROM xxxxx ORDER BY id DESC") or die(mysql_error());
Maybe that will tell you the problem, as i can't see any obvious errors. -
Is there a way to stop things that you've already told php to output from actually being output?
For example if i needed to echo something out before a form validation process, but under certain results of the validation i no longer want that to be echoed at the beginning, is there a way of making it not be echoed? Sort of like making your script not echo things that you have already told php to echo further up the script.
Sorry if that makes no sense but i'm having trouble finding explaining it properly.
Thanks in advance for any replies. -
Thanks.
-
Hi,
Was just wondering if doing this:
$_POST = false;
would make all post data false?
I'm not at my regular computer and can't just try it myself.
Thanks in advance. -
You can't make a real time chat feature with just php. I'm not sure about combining with other language, but not with 100% php.
You can make forums, with php, but that's about as close as your going to get i'm afraid. -
Just add the money to their total. i.e
$give = mysql_query("UPDATE MEMBERS SET CASH=CASH+$amount WHERE USERNAME='$username'"); -
Thanks very much.
-
Quick question about arrays that i'm sure i've done lots of times but can't test it right now.
If i have an array full or values, and then i set the array to false, would it empty the entire array?
For example:
[code]
$blah[0] = 1;
$blah[1] = 9;
$blah[2] = 4;
$blah[3] = 45;
$blah = false;
[/code]
Thanks in advance. -
It looks fine to me. Personally i always have a capital L in Location, but i'm not sure if that makes a difference.
-
One of my include paths by default is /usr/share/pear which is my pear directory, and the file i am including is /usr/share/pear/HTML/BBCodeParser.php
I've been battling with this for days and treid almost everything so i think it must be something to do with configuration. -
I'm having some problems trying to use PEAR packages. Whenever i try to use anything from the pear directory i get an error about an open_basedir restriction.
Here is the error:
Warning: require_once() [function.require-once]: open_basedir restriction in effect. File(/HTML/BBCodeParser.php) is not within the allowed path(s): (/tmp:/home/***) in /home/***/testbb.php on line 7
The pear directory is one of my include paths so it's no that.
I am the root user so i have access to everything, could anyone suggest anything i could try to get it to work?
Thanks in advance. -
I'm pretty sure it cannot be done by means of any conventional method, or by using a php script.
-
$blah = file_get_contents("url here");
-
Another thing, if $rec_num is more than 0 you don't need the further check. Try this:
[code]<?php session_start(); session_register("session");
error_reporting(E_ALL);
?>
<?php require("includes/connect/members.php"); ?>
<?php
$username = $_POST['username'];
$password = md5($_POST['password']);
$rec_check = mysql_query("SELECT * FROM profile WHERE userid='$username' AND password = '$password'");
$rec_num = mysql_numrows($rec_check);
if($rec_num > 0) {
$_SESSION['id']=session_id();
$_SESSION['username']=$username;
echo "<meta http-equiv='refresh' content='0;url(http://www.eliteguards.us/index.php)'>";
header("Location: index.php");
}
else {
session_unset();
echo "<meta http-equiv='refresh' content='0;url(http://www.eliteguards.us/login_false.php'>";
header("Location: login_false.php");
}
?>[/code]
I also set error reporting to E_ALL so you should get some errors if something is wrong. -
Try this code:
[code]
$email = "email address here";
$subject = "subject here";
$message = "Message Here";
$headers = "From: blah@blah.com\r\n";
mail($email, $subject, $message, $headers)or die('There has been an error, please try again.');[/code] -
That code is defining functions, not calling them. And since those functions are already reserved by php i don't think that can be done anyway.
Do this:
[code]$conn = mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db('db_name', $conn) or die(mysql_error());[/code]
but of course replace the information with your own. -
You don't need quotes for the number, and parentheses for the include.
[code]<?php
if ($result == 1){
include "result.php";
}
?>
<a href="<? echo $PHP_SELF?>?result=1">Click here to see page 2[/url][/code]
There is nothing "hackable" about it though. -
Errors?
Alternatives to image captcha's?
in PHP Coding Help
Posted
I have a form on my website, where the more a person submits a form the more credits they get for there account. They can only submit it every 2 minutes, but i had to introduce a captcha to stop people scripting and auto-reloading.
I was thinking of a system where every 5-10 minutes, instead of the form, a checkbox appears, and they have to check it and submit that before they can do the form, but if any of the post data is being sent when it isn't needed, such as would be done by an auto-reload, then the form doesn't process. But a could scripter could get around it quite easily however.
Anyway, yeah. As the first question says, anyone know any alternatives to captchas that display an image that you have to write into the box etc?