Πρόβλημα με το session_start();!

Σε αυτή την περιοχή μπορείτε να βρείτε ή να αναζητήσετε πληροφορίες σχετικές με την PHP

Συντονιστές: WebDev Moderators, Super-Moderators, PHP Moderators

Απάντηση
geo87
Δημοσιεύσεις: 79
Εγγραφή: 16 Ιουν 2008 05:25
Τοποθεσία: Αθήνα

Πρόβλημα με το session_start();!

Δημοσίευση από geo87 » 02 Φεβ 2009 18:54

Γεια σας παιδιά και πάλι! Νέο πρόβλημα και νέες ερωτήσεις. Βασικά δεν μπορώ να κάνω κάτι στην συγκεκριμένη περίπτωση χωρίς να πάρω σφάλμα..
Έχω αυτόν τον κώδικα..

Κώδικας: Επιλογή όλων

<?php
class Securimage &#123;
function Securimage&#40;&#41;
  &#123;
    if &#40; session_id&#40;&#41; == '' &#41; &#123; // no session has been started yet, which is needed for validation
	session_start&#40;&#41;;
    &#125;
  &#125;
  /**........... bla bla bla
Μου βγάζει όμως σφάλμα καθώς το

Κώδικας: Επιλογή όλων

  function Securimage&#40;&#41;
 &#123;
    if &#40; session_id&#40;&#41; == '' &#41; &#123; // no session has been started yet, which is needed for validation
	session_start&#40;&#41;;
    &#125;
  &#125;


πρέπει να μπει πρώτο μετά το <?php. Έλα όμως που όταν μπαίνει δεν δουλεύει το captcha.. :lol: :roll: .. ok ok λογικό θα μου πείτε. Τι μπορώ να κάνω όμως για να είναι το άλλο πρώτο ώστε να μην έχω σφάλμα και να δουλεύει κιόλας;; Plz τα φώτα σας φίλοι!

Άβαταρ μέλους
soteres2002
S. & H. Moderator
Δημοσιεύσεις: 1524
Εγγραφή: 05 Μαρ 2004 22:17
Τοποθεσία: Ιωάννινα

Πρόβλημα με το session_start();!

Δημοσίευση από soteres2002 » 03 Φεβ 2009 07:21

Το δεύτερο block δεν είναι ανάγκη να μπεί στην πρώτη γραμμή. Κατ αρχάς, αμα το δοκιμάσεις πάλι δεν θα δουλεύει. Στην πρώτη γραμμή πρέπει να βάλεις

Κώδικας: Επιλογή όλων

session_start&#40;&#41;;
Μετά μπορείς να διαχειρίζεσαι το session από τον κώδικα σου παρακάτω, αλλά δεν χρειάζεται πάλι session_start(). Μια δεύτερη κλήση οδηγεί σε php warning...

geo87
Δημοσιεύσεις: 79
Εγγραφή: 16 Ιουν 2008 05:25
Τοποθεσία: Αθήνα

Πρόβλημα με το session_start();!

Δημοσίευση από geo87 » 13 Φεβ 2009 20:15

Γεια σου φίλε μου. Σε ευχαριστώ πολύ για την απάντηση. Το πρόβλημα είναι πως όπως έδωσα τον κώδικα (τον 1ο) δουλεύει αλλά με php warning.

Βάζοντας το session_start(); στην αρχή τότε δεν μου βγάζει τίποτα...:(

Βάζοντας τον 2ο κώδικα πάνω πάνω τότε δουλεύει ο κώδικας χωρίς Php warning έλα όμως που συμπληρώνεις το captcha και σου βγάζει πως τον έχεις βάλει λάθος;; :(:(

Καμιά ιδέα για να το λύσω ( ; ) διότι δεν ξέρω άριστα την php.

Άβαταρ μέλους
ThyClub
Honorary Member
Δημοσιεύσεις: 5312
Εγγραφή: 17 Νοέμ 2003 00:21
Τοποθεσία: Hell's Kitchen
Επικοινωνία:

Πρόβλημα με το session_start();!

Δημοσίευση από ThyClub » 13 Φεβ 2009 20:38

Που ορίζεις το session var με τον κωδικό της εικόνας?

geo87
Δημοσιεύσεις: 79
Εγγραφή: 16 Ιουν 2008 05:25
Τοποθεσία: Αθήνα

Πρόβλημα με το session_start();!

Δημοσίευση από geo87 » 13 Φεβ 2009 20:58

Δεν κατάλαβα ακριβώς την ερώτηση σου.. :lol: Sorry έτσι απλά δεν ξέρω την php καλά μόνος την δουλεύω. Θα μπορούσες να μου εξηγήσεις τι ακριβώς εννοείς;

Άβαταρ μέλους
ThyClub
Honorary Member
Δημοσιεύσεις: 5312
Εγγραφή: 17 Νοέμ 2003 00:21
Τοποθεσία: Hell's Kitchen
Επικοινωνία:

Πρόβλημα με το session_start();!

Δημοσίευση από ThyClub » 13 Φεβ 2009 21:17

Δεν ελέγχεις κάπου αν ο κώδικας που δίνει ο χρήστης είναι σωστός ή όχι? Αυτή την ρουτίνα θέλω να δω.

geo87
Δημοσιεύσεις: 79
Εγγραφή: 16 Ιουν 2008 05:25
Τοποθεσία: Αθήνα

Πρόβλημα με το session_start();!

Δημοσίευση από geo87 » 17 Φεβ 2009 23:06

ThyClub έγραψε:Δεν ελέγχεις κάπου αν ο κώδικας που δίνει ο χρήστης είναι σωστός ή όχι? Αυτή την ρουτίνα θέλω να δω.
To url της σελίδας θες? Να σου το δώσω εδώ ή θα θεωρηθεί spam?

Άβαταρ μέλους
fafos
Script Master
Δημοσιεύσεις: 6231
Εγγραφή: 30 Νοέμ 2004 03:09

Πρόβλημα με το session_start();!

Δημοσίευση από fafos » 17 Φεβ 2009 23:13

geo87 έγραψε:
ThyClub έγραψε:Δεν ελέγχεις κάπου αν ο κώδικας που δίνει ο χρήστης είναι σωστός ή όχι? Αυτή την ρουτίνα θέλω να δω.
To url της σελίδας θες? Να σου το δώσω εδώ ή θα θεωρηθεί spam?
ennoei ton kodika poy xrhsimopoieis..oxi to url...
Οι πάνες και οι πολιτικοί πρέπει να αλλάζονται συχνά για τον ίδιο λόγο...

geo87
Δημοσιεύσεις: 79
Εγγραφή: 16 Ιουν 2008 05:25
Τοποθεσία: Αθήνα

Πρόβλημα με το session_start();!

Δημοσίευση από geo87 » 17 Φεβ 2009 23:28

Είναι τεράστιος να τον κάνω copy paste ή θα με πάρετε με τις κλωτσιές?

geo87
Δημοσιεύσεις: 79
Εγγραφή: 16 Ιουν 2008 05:25
Τοποθεσία: Αθήνα

Πρόβλημα με το session_start();!

Δημοσίευση από geo87 » 17 Φεβ 2009 23:35

Κώδικας: Επιλογή όλων

<?php
class Securimage &#123;
function Securimage&#40;&#41;
  &#123;
    if &#40; session_id&#40;&#41; == '' &#41; &#123; // no session has been started yet, which is needed for validation
	session_start&#40;&#41;;
    &#125;
  &#125;
  /**
   * Generate a code and output the image to the browser.
   *
   * <code>
   *   <?php
   *   include 'securimage.php';
   *   $securimage = new Securimage&#40;&#41;;
   *   $securimage->show&#40;'bg.jpg'&#41;;
   *   ?>
   * </code>
   *
   * @param string $background_image  The path to an image to use as the background for the CAPTCHA
   */

  /**
   * The desired width of the CAPTCHA image.
   *
   * @var int
   */
  var $image_width = 175;

  /**
   * The desired width of the CAPTCHA image.
   *
   * @var int
   */
  var $image_height = 45;

  /**
   * The image format for output.<br />
   * Valid options&#58; SI_IMAGE_PNG, SI_IMAGE_JPG, SI_IMAGE_GIF
   *
   * @var int
   */
  var $image_type = SI_IMAGE_PNG;

  /**
   * The length of the code to generate.
   *
   * @var int
   */
  var $code_length = 4;

  /**
   * The character set for individual characters in the image.<br />
   * Letters are converted to uppercase.<br />
   * The font must support the letters or there may be problematic substitutions.
   *
   * @var string
   */
  var $charset = 'ABCDEFGHKLMNPRSTUVWYZ23456789';
  //var $charset = '0123456789';

  /**
   * Create codes using this word list
   *
   * @var string  The path to the word list to use for creating CAPTCHA codes
   */
  var $wordlist_file = '../words/words.txt';

  /**
   * True to use a word list file instead of a random code
   *
   * @var bool
   */
  var $use_wordlist  = true;

  /**
   * Whether to use a GD font instead of a TTF font.<br />
   * TTF offers more support and options, but use this if your PHP doesn't support TTF.<br />
   *
   * @var boolean
   */
  var $use_gd_font = false;

  /**
   * The GD font to use.<br />
   * Internal gd fonts can be loaded by their number.<br />
   * Alternatively, a file path can be given and the font will be loaded from file.
   *
   * @var mixed
   */
  var $gd_font_file = 'gdfonts/bubblebath.gdf';

  /**
   * The approximate size of the font in pixels.<br />
   * This does not control the size of the font because that is determined by the GD font itself.<br />
   * This is used to aid the calculations of positioning used by this class.<br />
   *
   * @var int
   */
  var $gd_font_size = 20;

  // Note&#58; These font options below do not apply if you set $use_gd_font to true with the exception of $text_color

  /**
   * The path to the TTF font file to load.
   *
   * @var string
   */
  var $ttf_file = "./elephant.ttf";

  /**
   * The font size.<br />
   * Depending on your version of GD, this should be specified as the pixel size &#40;GD1&#41; or point size &#40;GD2&#41;<br />
   *
   * @var int
   */
  var $font_size = 24;

  /**
   * The minimum angle in degrees, with 0 degrees being left-to-right reading text.<br />
   * Higher values represent a counter-clockwise rotation.<br />
   * For example, a value of 90 would result in bottom-to-top reading text.
   *
   * @var int
   */
  var $text_angle_minimum = -20;

  /**
   * The minimum angle in degrees, with 0 degrees being left-to-right reading text.<br />
   * Higher values represent a counter-clockwise rotation.<br />
   * For example, a value of 90 would result in bottom-to-top reading text.
   *
   * @var int
   */
  var $text_angle_maximum = 20;

  /**
   * The X-Position on the image where letter drawing will begin.<br />
   * This value is in pixels from the left side of the image.
   *
   * @var int
   */
  var $text_x_start = 8;

  /**
   * Letters can be spaced apart at random distances.<br />
   * This is the minimum distance between two letters.<br />
   * This should be <i>at least</i> as wide as a font character.<br />
   * Small values can cause letters to be drawn over eachother.<br />
   *
   * @var int
   */
  var $text_minimum_distance = 30;

  /**
   * Letters can be spaced apart at random distances.<br />
   * This is the maximum distance between two letters.<br />
   * This should be <i>at least</i> as wide as a font character.<br />
   * Small values can cause letters to be drawn over eachother.<br />
   *
   * @var int
   */
  var $text_maximum_distance = 33;

  /**
   * The background color for the image.<br />
   * This should be specified in HTML hex format.<br />
   * Make sure to include the preceding # sign!
   *
   * @var string
   */
  var $image_bg_color = "#e3daed";

  /**
   * The text color to use for drawing characters.<br />
   * This value is ignored if $use_multi_text is set to true.<br />
   * Make sure this contrasts well with the background color.<br />
   * Specify the color in HTML hex format with preceding # sign
   *
   * @see Securimage&#58;&#58;$use_multi_text
   * @var string
   */
  var $text_color = "#ff0000";

  /**
   * Set to true to use multiple colors for each character.
   *
   * @see Securimage&#58;&#58;$multi_text_color
   * @var boolean
   */
  var $use_multi_text = true;

  /**
   * String of HTML hex colors to use.<br />
   * Separate each possible color with commas.<br />
   * Be sure to precede each value with the # sign.
   *
   * @var string
   */
  var $multi_text_color = "#0a68dd,#f65c47,#8d32fd";

  /**
   * Set to true to make the characters appear transparent.
   *
   * @see Securimage&#58;&#58;$text_transparency_percentage
   * @var boolean
   */
  var $use_transparent_text = true;

  /**
   * The percentage of transparency, 0 to 100.<br />
   * A value of 0 is completely opaque, 100 is completely transparent &#40;invisble&#41;
   *
   * @see Securimage&#58;&#58;$use_transparent_text
   * @var int
   */
  var $text_transparency_percentage = 15;


  // Line options
  /**
   * Draw vertical and horizontal lines on the image.
   *
   * @see Securimage&#58;&#58;$line_color
   * @see Securimage&#58;&#58;$line_distance
   * @see Securimage&#58;&#58;$line_thickness
   * @see Securimage&#58;&#58;$draw_lines_over_text
   * @var boolean
   */
  var $draw_lines = true;

  /**
   * The color of the lines drawn on the image.<br />
   * Use HTML hex format with preceding # sign.
   *
   * @see Securimage&#58;&#58;$draw_lines
   * @var string
   */
  var $line_color = "#80BFFF";

  /**
   * How far apart to space the lines from eachother in pixels.
   *
   * @see Securimage&#58;&#58;$draw_lines
   * @var int
   */
  var $line_distance = 5;

  /**
   * How thick to draw the lines in pixels.<br />
   * 1-3 is ideal depending on distance
   *
   * @see Securimage&#58;&#58;$draw_lines
   * @see Securimage&#58;&#58;$line_distance
   * @var int
   */
  var $line_thickness = 1;

  /**
   * Set to true to draw angled lines on the image in addition to the horizontal and vertical lines.
   *
   * @see Securimage&#58;&#58;$draw_lines
   * @var boolean
   */
  var $draw_angled_lines = false;

  /**
   * Draw the lines over the text.<br />
   * If fales lines will be drawn before putting the text on the image.<br />
   * This can make the image hard for humans to read depending on the line thickness and distance.
   *
   * @var boolean
   */
  var $draw_lines_over_text = false;

  /**
   * For added security, it is a good idea to draw arced lines over the letters to make it harder for bots to segment the letters.<br />
   * Two arced lines will be drawn over the text on each side of the image.<br />
   * This is currently expirimental and may be off in certain configurations.
   *
   * @var boolean
   */
  var $arc_linethrough = true;

  /**
   * The colors or color of the arced lines.<br />
   * Use HTML hex notation with preceding # sign, and separate each value with a comma.<br />
   * This should be similar to your font color for single color images.
   *
   * @var string
   */
  var $arc_line_colors = "#8080ff";

  /**
   * Full path to the WAV files to use to make the audio files, include trailing /.<br />
   * Name Files  &#91;A-Z0-9&#93;.wav
   *
   * @since 1.0.1
   * @var string
   */
  var $audio_path = './audio/';


  //END USER CONFIGURATION
  //There should be no need to edit below unless you really know what you are doing.

  /**
   * The gd image resource.
   *
   * @access private
   * @var resource
   */
  var $im;

  /**
   * The background image resource
   *
   * @access private
   * @var resource
   */
  var $bgimg;

  /**
   * The code generated by the script
   *
   * @access private
   * @var string
   */
  var $code;

  /**
   * The code that was entered by the user
   *
   * @access private
   * @var string
   */
  var $code_entered;

  /**
   * Whether or not the correct code was entered
   *
   * @access private
   * @var boolean
   */
  var $correct_code;

  /**
   * Class constructor.<br />
   * Because the class uses sessions, this will attempt to start a session if there is no previous one.<br />
   * If you do not start a session before calling the class, the constructor must be called before any
   * output is sent to the browser.
   *
   * <code>
   *   $securimage = new Securimage&#40;&#41;;
   * </code>
   *
   */
  function show&#40;$background_image = ""&#41;
  &#123;
    if&#40;$background_image != "" && is_readable&#40;$background_image&#41;&#41; &#123;
      $this->bgimg = $background_image;
    &#125;

    $this->doImage&#40;&#41;;
  &#125;

  /**
   * Validate the code entered by the user.
   *
   * <code>
   *   $code = $_POST&#91;'code'&#93;;
   *   if &#40;$securimage->check&#40;$code&#41; == false&#41; &#123;
   *     die&#40;"Sorry, the code entered did not match."&#41;;
   *   &#125; else &#123;
   *     $valid = true;
   *   &#125;
   * </code>
   * @param string $code  The code the user entered
   * @return boolean  true if the code was correct, false if not
   */
  function check&#40;$code&#41;
  &#123;
    $this->code_entered = $code;
    $this->validate&#40;&#41;;
    return $this->correct_code;
  &#125;

  /**
   * Generate and output the image
   *
   * @access private
   *
   */
  function doImage&#40;&#41;
  &#123;
    if&#40;$this->use_transparent_text == true || $this->bgimg != ""&#41; &#123;
      $this->im = imagecreatetruecolor&#40;$this->image_width, $this->image_height&#41;;
      $bgcolor = imagecolorallocate&#40;$this->im, hexdec&#40;substr&#40;$this->image_bg_color, 1, 2&#41;&#41;, hexdec&#40;substr&#40;$this->image_bg_color, 3, 2&#41;&#41;, hexdec&#40;substr&#40;$this->image_bg_color, 5, 2&#41;&#41;&#41;;
      imagefilledrectangle&#40;$this->im, 0, 0, imagesx&#40;$this->im&#41;, imagesy&#40;$this->im&#41;, $bgcolor&#41;;
    &#125; else &#123; //no transparency
      $this->im = imagecreate&#40;$this->image_width, $this->image_height&#41;;
      $bgcolor = imagecolorallocate&#40;$this->im, hexdec&#40;substr&#40;$this->image_bg_color, 1, 2&#41;&#41;, hexdec&#40;substr&#40;$this->image_bg_color, 3, 2&#41;&#41;, hexdec&#40;substr&#40;$this->image_bg_color, 5, 2&#41;&#41;&#41;;
    &#125;

    if&#40;$this->bgimg != ""&#41; &#123; $this->setBackground&#40;&#41;; &#125;

    $this->createCode&#40;&#41;;

    if &#40;!$this->draw_lines_over_text && $this->draw_lines&#41; $this->drawLines&#40;&#41;;

    $this->drawWord&#40;&#41;;

    if &#40;$this->arc_linethrough == true&#41; $this->arcLines&#40;&#41;;

    if &#40;$this->draw_lines_over_text && $this->draw_lines&#41; $this->drawLines&#40;&#41;;

    $this->output&#40;&#41;;

  &#125;

  /**
   * Set the background of the CAPTCHA image
   *
   * @access private
   *
   */
  function setBackground&#40;&#41;
  &#123;
    $dat = @getimagesize&#40;$this->bgimg&#41;;
    if&#40;$dat == false&#41; &#123; return; &#125;

    switch&#40;$dat&#91;2&#93;&#41; &#123;
      case 1&#58;  $newim = @imagecreatefromgif&#40;$this->bgimg&#41;; break;
      case 2&#58;  $newim = @imagecreatefromjpeg&#40;$this->bgimg&#41;; break;
      case 3&#58;  $newim = @imagecreatefrompng&#40;$this->bgimg&#41;; break;
      case 15&#58; $newim = @imagecreatefromwbmp&#40;$this->bgimg&#41;; break;
      case 16&#58; $newim = @imagecreatefromxbm&#40;$this->bgimg&#41;; break;
      default&#58; return;
    &#125;

    if&#40;!$newim&#41; return;

    imagecopy&#40;$this->im, $newim, 0, 0, 0, 0, $this->image_width, $this->image_height&#41;;
  &#125;

  /**
   * Draw arced lines over the text
   *
   * @access private
   *
   */
  function arcLines&#40;&#41;
  &#123;
    $colors = explode&#40;',', $this->arc_line_colors&#41;;
    imagesetthickness&#40;$this->im, 3&#41;;

    $color = $colors&#91;rand&#40;0, sizeof&#40;$colors&#41; - 1&#41;&#93;;
    $linecolor = imagecolorallocate&#40;$this->im, hexdec&#40;substr&#40;$color, 1, 2&#41;&#41;, hexdec&#40;substr&#40;$color, 3, 2&#41;&#41;, hexdec&#40;substr&#40;$color, 5, 2&#41;&#41;&#41;;

    $xpos   = $this->text_x_start + &#40;$this->font_size * 2&#41; + rand&#40;-5, 5&#41;;
    $width  = $this->image_width / 2.66 + rand&#40;3, 10&#41;;
    $height = $this->font_size * 2.14 - rand&#40;3, 10&#41;;

    if &#40; rand&#40;0,100&#41; % 2 == 0 &#41; &#123;
      $start = rand&#40;0,66&#41;;
      $ypos  = $this->image_height / 2 - rand&#40;5, 15&#41;;
      $xpos += rand&#40;5, 15&#41;;
    &#125; else &#123;
      $start = rand&#40;180, 246&#41;;
      $ypos  = $this->image_height / 2 + rand&#40;5, 15&#41;;
    &#125;

    $end = $start + rand&#40;75, 110&#41;;

    imagearc&#40;$this->im, $xpos, $ypos, $width, $height, $start, $end, $linecolor&#41;;

    $color = $colors&#91;rand&#40;0, sizeof&#40;$colors&#41; - 1&#41;&#93;;
    $linecolor = imagecolorallocate&#40;$this->im, hexdec&#40;substr&#40;$color, 1, 2&#41;&#41;, hexdec&#40;substr&#40;$color, 3, 2&#41;&#41;, hexdec&#40;substr&#40;$color, 5, 2&#41;&#41;&#41;;

    if &#40; rand&#40;1,75&#41; % 2 == 0 &#41; &#123;
      $start = rand&#40;45, 111&#41;;
      $ypos  = $this->image_height / 2 - rand&#40;5, 15&#41;;
      $xpos += rand&#40;5, 15&#41;;
    &#125; else &#123;
      $start = rand&#40;200, 250&#41;;
      $ypos  = $this->image_height / 2 + rand&#40;5, 15&#41;;
    &#125;

    $end = $start + rand&#40;75, 100&#41;;

    imagearc&#40;$this->im, $this->image_width * .75, $ypos, $width, $height, $start, $end, $linecolor&#41;;
  &#125;

  /**
   * Draw lines on the image
   *
   * @access private
   *
   */
  function drawLines&#40;&#41;
  &#123;
    $linecolor = imagecolorallocate&#40;$this->im, hexdec&#40;substr&#40;$this->line_color, 1, 2&#41;&#41;, hexdec&#40;substr&#40;$this->line_color, 3, 2&#41;&#41;, hexdec&#40;substr&#40;$this->line_color, 5, 2&#41;&#41;&#41;;
    imagesetthickness&#40;$this->im, $this->line_thickness&#41;;

    //vertical lines
    for&#40;$x = 1; $x < $this->image_width; $x += $this->line_distance&#41; &#123;
      imageline&#40;$this->im, $x, 0, $x, $this->image_height, $linecolor&#41;;
    &#125;

    //horizontal lines
    for&#40;$y = 11; $y < $this->image_height; $y += $this->line_distance&#41; &#123;
      imageline&#40;$this->im, 0, $y, $this->image_width, $y, $linecolor&#41;;
    &#125;

    if &#40;$this->draw_angled_lines == true&#41; &#123;
      for &#40;$x = -&#40;$this->image_height&#41;; $x < $this->image_width; $x += $this->line_distance&#41; &#123;
        imageline&#40;$this->im, $x, 0, $x + $this->image_height, $this->image_height, $linecolor&#41;;
      &#125;

      for &#40;$x = $this->image_width + $this->image_height; $x > 0; $x -= $this->line_distance&#41; &#123;
        imageline&#40;$this->im, $x, 0, $x - $this->image_height, $this->image_height, $linecolor&#41;;
      &#125;
    &#125;
  &#125;

  /**
   * Draw the CAPTCHA code over the image
   *
   * @access private
   *
   */
  function drawWord&#40;&#41;
  &#123;
    if &#40;$this->use_gd_font == true&#41; &#123;
      if &#40;!is_int&#40;$this->gd_font_file&#41;&#41; &#123; //is a file name
        $font = @imageloadfont&#40;$this->gd_font_file&#41;;
        if &#40;$font == false&#41; &#123;
          trigger_error&#40;"Failed to load GD Font file &#123;$this->gd_font_file&#125; ", E_USER_WARNING&#41;;
          return;
        &#125;
      &#125; else &#123; //gd font identifier
        $font = $this->gd_font_file;
      &#125;

      $color = imagecolorallocate&#40;$this->im, hexdec&#40;substr&#40;$this->text_color, 1, 2&#41;&#41;, hexdec&#40;substr&#40;$this->text_color, 3, 2&#41;&#41;, hexdec&#40;substr&#40;$this->text_color, 5, 2&#41;&#41;&#41;;
      imagestring&#40;$this->im, $font, $this->text_x_start, &#40;$this->image_height / 2&#41; - &#40;$this->gd_font_size / 2&#41;, $this->code, $color&#41;;

    &#125; else &#123; //ttf font
      if&#40;$this->use_transparent_text == true&#41; &#123;
        $alpha = intval&#40;$this->text_transparency_percentage / 100 * 127&#41;;
        $font_color = imagecolorallocatealpha&#40;$this->im, hexdec&#40;substr&#40;$this->text_color, 1, 2&#41;&#41;, hexdec&#40;substr&#40;$this->text_color, 3, 2&#41;&#41;, hexdec&#40;substr&#40;$this->text_color, 5, 2&#41;&#41;, $alpha&#41;;
      &#125; else &#123; //no transparency
        $font_color = imagecolorallocate&#40;$this->im, hexdec&#40;substr&#40;$this->text_color, 1, 2&#41;&#41;, hexdec&#40;substr&#40;$this->text_color, 3, 2&#41;&#41;, hexdec&#40;substr&#40;$this->text_color, 5, 2&#41;&#41;&#41;;
      &#125;

      $x = $this->text_x_start;
      $strlen = strlen&#40;$this->code&#41;;
      $y_min = &#40;$this->image_height / 2&#41; + &#40;$this->font_size / 2&#41; - 2;
      $y_max = &#40;$this->image_height / 2&#41; + &#40;$this->font_size / 2&#41; + 2;
      $colors = explode&#40;',', $this->multi_text_color&#41;;

      for&#40;$i = 0; $i < $strlen; ++$i&#41; &#123;
        $angle = rand&#40;$this->text_angle_minimum, $this->text_angle_maximum&#41;;
        $y = rand&#40;$y_min, $y_max&#41;;
        if &#40;$this->use_multi_text == true&#41; &#123;
          $idx = rand&#40;0, sizeof&#40;$colors&#41; - 1&#41;;
          $r = substr&#40;$colors&#91;$idx&#93;, 1, 2&#41;;
          $g = substr&#40;$colors&#91;$idx&#93;, 3, 2&#41;;
          $b = substr&#40;$colors&#91;$idx&#93;, 5, 2&#41;;
          if&#40;$this->use_transparent_text == true&#41; &#123;
            $font_color = imagecolorallocatealpha&#40;$this->im, "0x$r", "0x$g", "0x$b", $alpha&#41;;
          &#125; else &#123;
            $font_color = imagecolorallocate&#40;$this->im, "0x$r", "0x$g", "0x$b"&#41;;
          &#125;
        &#125;
        @imagettftext&#40;$this->im, $this->font_size, $angle, $x, $y, $font_color, $this->ttf_file, $this->code&#123;$i&#125;&#41;;

        $x += rand&#40;$this->text_minimum_distance, $this->text_maximum_distance&#41;;
      &#125; //for loop
    &#125; //else ttf font
  &#125; //function

  /**
   * Create a code and save to the session
   *
   * @since 1.0.1
   *
   */
  function createCode&#40;&#41;
  &#123;
    $this->code = false;

    if &#40;$this->use_wordlist && is_readable&#40;$this->wordlist_file&#41;&#41; &#123;
      $this->code = $this->readCodeFromFile&#40;&#41;;
    &#125;

    if &#40;$this->code == false&#41; &#123;
      $this->code = $this->generateCode&#40;$this->code_length&#41;;
    &#125;

    $this->saveData&#40;&#41;;
  &#125;

  /**
   * Generate a code
   *
   * @access private
   * @param int $len  The code length
   * @return string
   */
  function generateCode&#40;$len&#41;
  &#123;
    $code = '';

    for&#40;$i = 1, $cslen = strlen&#40;$this->charset&#41;; $i <= $len; ++$i&#41; &#123;
      $code .= strtoupper&#40; $this->charset&#123;rand&#40;0, $cslen - 1&#41;&#125; &#41;;
    &#125;
    return $code;
  &#125;

  /**
   * Reads a word list file to get a code
   *
   * @access private
   * @since 1.0.2
   * @return mixed  false on failure, a word on success
   */
  function readCodeFromFile&#40;&#41;
  &#123;
    $fp = @fopen&#40;$this->wordlist_file, 'rb'&#41;;
    if &#40;!$fp&#41; return false;

    $fsize = filesize&#40;$this->wordlist_file&#41;;
    if &#40;$fsize < 32&#41; return false; // too small of a list to be effective

    if &#40;$fsize < 128&#41; &#123;
      $max = $fsize; // still pretty small but changes the range of seeking
    &#125; else &#123;
      $max = 128;
    &#125;

    fseek&#40;$fp, rand&#40;0, $fsize - $max&#41;, SEEK_SET&#41;;
    $data = fread&#40;$fp, 128&#41;; // read a random 128 bytes from file
    fclose&#40;$fp&#41;;
    $data = preg_replace&#40;"/\r?\n/", "\n", $data&#41;;

    $start = strpos&#40;$data, "\n", rand&#40;0, 100&#41;&#41; + 1; // random start position
    $end   = strpos&#40;$data, "\n", $start&#41;;           // find end of word

    return strtolower&#40;substr&#40;$data, $start, $end - $start&#41;&#41;; // return substring in 128 bytes
  &#125;

  /**
   * Output image to the browser
   *
   * @access private
   *
   */
  function output&#40;&#41;
  &#123;
    header&#40;"Expires&#58; Sun, 1 Jan 2000 12&#58;00&#58;00 GMT"&#41;;
    header&#40;"Last-Modified&#58; " . gmdate&#40;"D, d M Y H&#58;i&#58;s"&#41; . "GMT"&#41;;
    header&#40;"Cache-Control&#58; no-store, no-cache, must-revalidate"&#41;;
    header&#40;"Cache-Control&#58; post-check=0, pre-check=0", false&#41;;
    header&#40;"Pragma&#58; no-cache"&#41;;

    switch&#40;$this->image_type&#41;
    &#123;
      case SI_IMAGE_JPEG&#58;
        header&#40;"Content-Type&#58; image/jpeg"&#41;;
        imagejpeg&#40;$this->im, null, 90&#41;;
        break;

      case SI_IMAGE_GIF&#58;
        header&#40;"Content-Type&#58; image/gif"&#41;;
        imagegif&#40;$this->im&#41;;
        break;

      default&#58;
        header&#40;"Content-Type&#58; image/png"&#41;;
        imagepng&#40;$this->im&#41;;
        break;
    &#125;

    imagedestroy&#40;$this->im&#41;;
  &#125;

  /**
   * Get WAV file data of the spoken code.<br />
   * This is appropriate for output to the browser as audio/x-wav
   *
   * @since 1.0.1
   * @return string  WAV data
   *
   */
  function getAudibleCode&#40;&#41;
  &#123;
    $letters = array&#40;&#41;;
    $code    = $this->getCode&#40;&#41;;

    if &#40;$code == ''&#41; &#123;
      $this->createCode&#40;&#41;;
      $code = $this->getCode&#40;&#41;;
    &#125;

    for&#40;$i = 0; $i < strlen&#40;$code&#41;; ++$i&#41; &#123;
      $letters&#91;&#93; = $code&#123;$i&#125;;
    &#125;

    return $this->generateWAV&#40;$letters&#41;;
  &#125;

  /**
   * Save the code in the session
   *
   * @access private
   *
   */
  function saveData&#40;&#41;
  &#123;
    $_SESSION&#91;'securimage_code_value'&#93; = strtolower&#40;$this->code&#41;;
  &#125;

  /**
   * Validate the code to the user code
   *
   * @access private
   *
   */
  function validate&#40;&#41;
  &#123;
    if &#40; isset&#40;$_SESSION&#91;'securimage_code_value'&#93;&#41; && !empty&#40;$_SESSION&#91;'securimage_code_value'&#93;&#41; &#41; &#123;
      if &#40; $_SESSION&#91;'securimage_code_value'&#93; == strtolower&#40;trim&#40;$this->code_entered&#41;&#41; &#41; &#123;
        $this->correct_code = true;
        $_SESSION&#91;'securimage_code_value'&#93; = '';
      &#125; else &#123;
        $this->correct_code = false;
      &#125;
    &#125; else &#123;
      $this->correct_code = false;
    &#125;
  &#125;

  /**
   * Get the captcha code
   *
   * @since 1.0.1
   * @return string
   */
  function getCode&#40;&#41;
  &#123;
    if &#40;isset&#40;$_SESSION&#91;'securimage_code_value'&#93;&#41; && !empty&#40;$_SESSION&#91;'securimage_code_value'&#93;&#41;&#41; &#123;
      return $_SESSION&#91;'securimage_code_value'&#93;;
    &#125; else &#123;
      return '';
    &#125;
  &#125;

  /**
   * Check if the user entered code was correct
   *
   * @access private
   * @return boolean
   */
  function checkCode&#40;&#41;
  &#123;
    return $this->correct_code;
  &#125;

  /**
   * Generate a wav file by concatenating individual files
   * @since 1.0.1
   * @access private
   * @param array $letters  Array of letters to build a file from
   * @return string  WAV file data
   */
  function generateWAV&#40;$letters&#41;
  &#123;
    $first = true; // use first file to write the header...
    $data_len    = 0;
    $files       = array&#40;&#41;;
    $out_data    = '';

    foreach &#40;$letters as $letter&#41; &#123;
      $filename = $this->audio_path . strtoupper&#40;$letter&#41; . '.wav';

      $fp = fopen&#40;$filename, 'rb'&#41;;

      $file = array&#40;&#41;;

      $data = fread&#40;$fp, filesize&#40;$filename&#41;&#41;; // read file in

      $header = substr&#40;$data, 0, 36&#41;;
      $body   = substr&#40;$data, 44&#41;;


      $data = unpack&#40;'NChunkID/VChunkSize/NFormat/NSubChunk1ID/VSubChunk1Size/vAudioFormat/vNumChannels/VSampleRate/VByteRate/vBlockAlign/vBitsPerSample', $header&#41;;

      $file&#91;'sub_chunk1_id'&#93;   = $data&#91;'SubChunk1ID'&#93;;
      $file&#91;'bits_per_sample'&#93; = $data&#91;'BitsPerSample'&#93;;
      $file&#91;'channels'&#93;        = $data&#91;'NumChannels'&#93;;
      $file&#91;'format'&#93;          = $data&#91;'AudioFormat'&#93;;
      $file&#91;'sample_rate'&#93;     = $data&#91;'SampleRate'&#93;;
      $file&#91;'size'&#93;            = $data&#91;'ChunkSize'&#93; + 8;
      $file&#91;'data'&#93;            = $body;

      if &#40; &#40;$p = strpos&#40;$file&#91;'data'&#93;, 'LIST'&#41;&#41; !== false&#41; &#123;
        // If the LIST data is not at the end of the file, this will probably break your sound file
        $info         = substr&#40;$file&#91;'data'&#93;, $p + 4, 8&#41;;
        $data         = unpack&#40;'Vlength/Vjunk', $info&#41;;
        $file&#91;'data'&#93; = substr&#40;$file&#91;'data'&#93;, 0, $p&#41;;
        $file&#91;'size'&#93; = $file&#91;'size'&#93; - &#40;strlen&#40;$file&#91;'data'&#93;&#41; - $p&#41;;
      &#125;

      $files&#91;&#93; = $file;
      $data    = null;
      $header  = null;
      $body    = null;

      $data_len += strlen&#40;$file&#91;'data'&#93;&#41;;

      fclose&#40;$fp&#41;;
    &#125;

    $out_data = '';
    for&#40;$i = 0; $i < sizeof&#40;$files&#41;; ++$i&#41; &#123;
      if &#40;$i == 0&#41; &#123; // output header
        $out_data .= pack&#40;'C4VC8', ord&#40;'R'&#41;, ord&#40;'I'&#41;, ord&#40;'F'&#41;, ord&#40;'F'&#41;, $data_len + 36, ord&#40;'W'&#41;, ord&#40;'A'&#41;, ord&#40;'V'&#41;, ord&#40;'E'&#41;, ord&#40;'f'&#41;, ord&#40;'m'&#41;, ord&#40;'t'&#41;, ord&#40;' '&#41;&#41;;

        $out_data .= pack&#40;'VvvVVvv',
                          16,
                          $files&#91;$i&#93;&#91;'format'&#93;,
                          $files&#91;$i&#93;&#91;'channels'&#93;,
                          $files&#91;$i&#93;&#91;'sample_rate'&#93;,
                          $files&#91;$i&#93;&#91;'sample_rate'&#93; * &#40;&#40;$files&#91;$i&#93;&#91;'bits_per_sample'&#93; * $files&#91;$i&#93;&#91;'channels'&#93;&#41; / 8&#41;,
                          &#40;$files&#91;$i&#93;&#91;'bits_per_sample'&#93; * $files&#91;$i&#93;&#91;'channels'&#93;&#41; / 8,
                          $files&#91;$i&#93;&#91;'bits_per_sample'&#93; &#41;;

        $out_data .= pack&#40;'C4', ord&#40;'d'&#41;, ord&#40;'a'&#41;, ord&#40;'t'&#41;, ord&#40;'a'&#41;&#41;;

        $out_data .= pack&#40;'V', $data_len&#41;;
      &#125;

      $out_data .= $files&#91;$i&#93;&#91;'data'&#93;;
    &#125;

    return $out_data;
  &#125;
&#125; /* class Securimage */

/**
 * Project&#58;     Securimage&#58; A PHP class for creating and managing form CAPTCHA images<br />
 * File&#58;        securimage.php<br />
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.<br /><br />
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.<br /><br />
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA<br /><br />
 *
 * Any modifications to the library should be indicated clearly in the source code
 * to inform users that the changes are not a part of the original software.<br /><br />
 *
 * If you found this script useful, please take a quick moment to rate it.<br />
 * http&#58;//www.hotscripts.com/rate/49400.html  Thanks.
 *
 * @link http&#58;//www.phpcaptcha.org Securimage PHP CAPTCHA
 * @link http&#58;//www.phpcaptcha.org/latest.zip Download Latest Version
 * @link http&#58;//www.phpcaptcha.org/Securimage_Docs/ Online Documentation
 * @copyright 2007 Drew Phillips
 * @author drew010 <drew@drew-phillips.com>
 * @version 1.0.3.1 &#40;March 24, 2008&#41;
 * @package Securimage
 *
 */

/**
  ChangeLog

  1.0.3.1
  - Error reading from wordlist in some cases caused words to be cut off 1 letter short

  1.0.3
  - Removed shadow_text from code which could cause an undefined property error due to removal from previous version

  1.0.2
  - Audible CAPTCHA Code wav files
  - Create codes from a word list instead of random strings

  1.0
  - Added the ability to use a selected character set, rather than a-z0-9 only.
  - Added the multi-color text option to use different colors for each letter.
  - Switched to automatic session handling instead of using files for code storage
  - Added GD Font support if ttf support is not available.  Can use internal GD fonts or load new ones.
  - Added the ability to set line thickness
  - Added option for drawing arced lines over letters
  - Added ability to choose image type for output

*/

/**
 * Output images in JPEG format
 */
define&#40;'SI_IMAGE_JPEG', 1&#41;;
/**
 * Output images in PNG format
 */
define&#40;'SI_IMAGE_PNG',  2&#41;;
/**
 * Output images in GIF format
 * Must have GD >= 2.0.28!
 */
define&#40;'SI_IMAGE_GIF',  3&#41;;

/**
 * Securimage CAPTCHA Class.
 *
 * @package    Securimage
 * @subpackage classes
 *
 */


?>
Εδώ είναι αν έκανα βλακεία να μου το πείτε να τον σβήσω οκ??:):):)

Άβαταρ μέλους
fafos
Script Master
Δημοσιεύσεις: 6231
Εγγραφή: 30 Νοέμ 2004 03:09

Πρόβλημα με το session_start();!

Δημοσίευση από fafos » 17 Φεβ 2009 23:54

kane ena echo $_SESSION['securimage_code_value']; na doume ti pairneis... pantos o kodikas einai ypervolikos gia ena aplo captcha..
Οι πάνες και οι πολιτικοί πρέπει να αλλάζονται συχνά για τον ίδιο λόγο...

geo87
Δημοσιεύσεις: 79
Εγγραφή: 16 Ιουν 2008 05:25
Τοποθεσία: Αθήνα

Πρόβλημα με το session_start();!

Δημοσίευση από geo87 » 18 Φεβ 2009 00:00

fafos πρώτα από όλα σε ευχαριστώ πολύ φίλε μου! Επειδή μόνος μου τα δουλεύω και δεν έχω την γνώση θα μπορούσες να μου πεις που ακριβώς να το βάλω αυτό που μου λες;

*Ο κώδικας είναι ένα από ένα mod κι είχε κι άλλα σφάλματα τα οποία όμως κατάφερα και τα έλυσα. Αυτό είναι το τελευταίο και μέχρι τώρα δεν έχω παρατηρήσει άλλο.

Άβαταρ μέλους
fafos
Script Master
Δημοσιεύσεις: 6231
Εγγραφή: 30 Νοέμ 2004 03:09

Πρόβλημα με το session_start();!

Δημοσίευση από fafos » 18 Φεβ 2009 00:02

geo87 έγραψε:fafos πρώτα από όλα σε ευχαριστώ πολύ φίλε μου! Επειδή μόνος μου τα δουλεύω και δεν έχω την γνώση θα μπορούσες να μου πεις που ακριβώς να το βάλω αυτό που μου λες;

*Ο κώδικας είναι ένα από ένα mod κι είχε κι άλλα σφάλματα τα οποία όμως κατάφερα και τα έλυσα. Αυτό είναι το τελευταίο και μέχρι τώρα δεν έχω παρατηρήσει άλλο.
kato apo thn eikona pou sou emfanizei sthn forma..
Οι πάνες και οι πολιτικοί πρέπει να αλλάζονται συχνά για τον ίδιο λόγο...

geo87
Δημοσιεύσεις: 79
Εγγραφή: 16 Ιουν 2008 05:25
Τοποθεσία: Αθήνα

Πρόβλημα με το session_start();!

Δημοσίευση από geo87 » 18 Φεβ 2009 00:05

Ωπ οκ! Πάω να το δοκιμάσω και θα πω νέα εντός ολίγου! Σορρυ για το πρήξιμο εντάξει; :lol: :oops: Ευχαριστώ πολύ!

geo87
Δημοσιεύσεις: 79
Εγγραφή: 16 Ιουν 2008 05:25
Τοποθεσία: Αθήνα

Πρόβλημα με το session_start();!

Δημοσίευση από geo87 » 18 Φεβ 2009 00:27

Εδώ είναι το σημείο που έπρεπε να το βάλω.

Κώδικας: Επιλογή όλων

if&#40;get_option&#40;'wplinkdir_captcha'&#41;=='Securimage'&#41;&#123;

			$page.='<tr valign="top">
			<td><b>'.__&#40;'Captcha&#58;',$WPLD_Domain&#41;.'</b></td><td>
			<img src="'.get_bloginfo&#40;'url'&#41;.'/wp-content/plugins/wordpress-link-directory/securimage_show.php?sid='.md5&#40;uniqid&#40;time&#40;&#41;&#41;&#41;.'">
			<sup><a href="'.get_bloginfo&#40;'url'&#41;.'/wp-content/plugins/wordpress-link-directory/securimage_play.php">Audio</a> <a href="#" onclick="document.getElementById&#40;\'image\'&#41;.src = \''.get_bloginfo&#40;'url'&#41;.'/wp-content/plugins/wordpress-link-directory/securimage_show.php?sid=\' + Math.random&#40;&#41;; return false">Reload Image</a></sup>
			</td></tr>
			<tr><td><b>'.__&#40;'Enter Code&#58;',$WPLD_Domain&#41;.'</b></td><td><input name="code" /></td></tr>';
Το έβαλα αλλά μου έβγαζε πως κάνω λάθος το captcha και μετά το domain. Κάποια ιδέα?? :D

Απάντηση

Επιστροφή στο “PHP Προγραμματισμός”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες