Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-25-2008, 11:20 AM   PM User | #1
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,513
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
does session_start() reset the session vars ?

Hello,

Am a bit new to using sessions and I have got a bit confused.

I am passing a session variable for the captha image.


My index.php starts off with:
PHP Code:
<?php 
/*
*  index.php
*

*  calls my_functions.php
*  and  first_page_fm.php
*  and  a_client_chk.php
*  and  b_email_act.php
*  and  confirm_disp.php
*
*  
*/
session_start()

require_once(
"my_functions.php");

now later on it includes a form script:

PHP Code:
require_once("first_page_fm.php");    // run BIG FORM
exit(); 
Inside the form the captcha script is run with the image
like this:

PHP Code:
<span class="tab-cell-right"  style="height: 40px; "><img src="captcha.php"> </a></span
Inside captcha.php

the session var is set:

PHP Code:
$_SESSION['key'] = md5($string); 

Now the form script re-runs index.php
which processes the form data.

i.e.
PHP Code:
<form name="main_fm1" action ='index.php' method 'POST'
So when the index re-runs (from the form) and the "session_start()" is encountered again, does the $_SESSION['key'] variable get lost ?

or does the "session_start()" pass it on ?

If passed on, this code should display it:

PHP Code:
$keytxt =$_SESSION['key'];

ECHO 
"Keytext: $keytxt"
But it shows up as empty

Any ideas on what I am doing wrong ?

Thanks for any input.
__________________
If you want to attract and keep more clients, then offer great customer support.

Support-Focus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
jeddi is offline   Reply With Quote
Old 02-25-2008, 11:53 AM   PM User | #2
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,711
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
Each page that sets or uses any session variable must contain a session_start() (how else do you suppose it works?). If captcha.php does not have a session_start() add one.
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is offline   Reply With Quote
Old 02-25-2008, 01:03 PM   PM User | #3
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,513
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
OK - thanks

I am going to put session_start() into the capctha.php

but I thought if it goes in there I will get those "headers already used" type error as this capctha.php is being called in the middle of my html form (after I've already sent lots of stuff to the browser) with the image statement like this:

PHP Code:
<span class="tab-cell-right"  style="height: 40px; "><img src="captcha.php"> </a></span
If it doesn't error - why not ?

( just want to understand it better )

Thanks again
__________________
If you want to attract and keep more clients, then offer great customer support.

Support-Focus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
jeddi is offline   Reply With Quote
Old 02-25-2008, 01:11 PM   PM User | #4
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,711
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
The URL listed in the <img src="..." alt=""> tag is fetched separately by the browser.

Here is how images on web pages work.

The browser requests a web page (such as your form.) The HTML code on that page is output to the browser. In your case you have an image and the HTML code is - <img src="captcha.php">. The browser sees the src="..." parameter and generates a http request to the web server to fetch the image. Any php code in captcha.php is not executed until the browser fetches the image.
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is offline   Reply With Quote
Old 10-12-2009, 07:35 AM   PM User | #5
tspiderus
New to the CF scene

 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
tspiderus is an unknown quantity at this point
Quote:
Originally Posted by CFMaBiSmAd View Post
The URL listed in the <img src="..." alt=""> tag is fetched separately by the browser.

Here is how images on web pages work.

The browser requests a web page (such as your form.) The HTML code on that page is output to the browser. In your case you have an image and the HTML code is - <img src="captcha.php">. The browser sees the src="..." parameter and generates a http request to the web server to fetch the image. Any php code in captcha.php is not executed until the browser fetches the image.
I'm also trying to create a Captcha for a form. Inside "captcha.php" i try to register/store the code that is randomly generated: $_SESSION["captcha"] = 'xxx'; However, nothing is written in the session file.

The session_start() command is present at the begining of both files (captcha.php and .html).

What can I do?

Any help would be really apreciated since this issue has been driving me crazy for the past three days.
tspiderus is offline   Reply With Quote
Old 10-12-2009, 11:55 AM   PM User | #6
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,711
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
Quote:
and .html
By default, php code is only parsed within .php files. Have you configured your web server so that it also parses php code in .html files? If not, you need to use .php files.
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:54 PM.


Advertisement
Log in to turn off these ads.