Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 21st, 2004, 07:52 AM
Registered User
 
Join Date: Jul 2004
Location: , , Ireland.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to joconnor Send a message via Yahoo to joconnor
Default passing variables from PHP to Perl

hi, i'm pretty new to PHP, only started learning it a couple of weeks ago because i'm doind an internship as part of my course in college.
my problem is that i need to pass to variables that get their values from textfields to a Perl file. i have absolutly no idea hhow to do it or even where to begin so ANY help would be greatly appreciated.
thanx in advance
james
Reply With Quote
  #2 (permalink)  
Old July 21st, 2004, 08:12 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Hmmmm... interesting challenge.

I dunno much about Perl.

At first glance one possibility is to store the necessary variables in a PHP session variable, then open and parse the PHP session data file with Perl... but that leaves the question of how to pass the session id to Perl. I would imagine that using request variables like GET, POST or COOKIE, that the PHP session id would be available that way, whereas you could open the sesison data file from Perl.

Then that leaves the question of how to execute the PERL script.

Well, one approach would be to use a simple redirect using the location header.. being sure to include that session id... then whaalah.. you have access to the PHP session data from within Perl.

It sounds like a feasible solution to me.

Does that make sense??

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
Reply With Quote
  #3 (permalink)  
Old July 21st, 2004, 08:24 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Ok.. here's a slightly more detailed answer...

Once your request variables are passed to PHP.. let's say via the POST method. Here is a very simple demonstration of what I was talking about.

<?php
    // This php script is the target of your form.

    // Begin the session
    session_start();

    // Transfer the POST variables to the SESSION variable, where they are stored in a session file.
    $_SESSION = $_POST;

    // Redirect to the Perl script, pass the session id via the GET method.
    location('header: perl_file.cgi?sid='.session_id());
?>

The location of the session data file varies depending on your OS. On Windows its commonly located at C:\PHP\sessiondata, on Linux its located at /tmp. You have to make sure you have the proper read permissions set to access the data.

The session file is named:
sess_232c53fe64de1a5e30df280db6095006

Where that long string of random numbers and letters is the session id.

Then the inners of the session data file looks like this:
user_id|s:2:"58";user_name|s:5:"richy";email|s:22: "me@mydomain.net";password|s:8:"mypassword";contro l|s:5:"index";

Each portion of this relates to a SESSION variable.

I dunno the required Perl.. but it shouldn't be too complicated to parse.




Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
Reply With Quote
  #4 (permalink)  
Old July 21st, 2004, 08:49 AM
Registered User
 
Join Date: Jul 2004
Location: , , Ireland.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to joconnor Send a message via Yahoo to joconnor
Default

thanx for your help rich but unfortunately since i only started learning PHP about 2 weeks ago i have no idea what you mean about sessions, i've heard of them but thats about as far as my knowledge goes. if you know of any exmples on the net that i could look at then that would be great.
thanx again
james
Reply With Quote
  #5 (permalink)  
Old July 21st, 2004, 09:13 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I assume you have some background in programming??

The first place to start is the PHP manual.
http://www.php.net/session

That's the technical, and very dry explaination of each session function.

Sessions are a way to store and persist data between client connections. Its not a permenent storage receptical, like say a database is. Its a way to store data that's used while the visitor is using the website, once the user closes their browser, the session ends and at some point after that garbage collection happens, which is PHP's process of deleting outdated session files. Therefore, sessions are temporary.

In PHP every session is initiated with a call to session_start() at the very beginning of the PHP script. This function does the following:

1. It issues a cookie in the HTTP response headers to the client's browser. The cookie contains the session id, which associates the client with the session data that's stored on the server.
2. It creates a plain text file on the server, where session data is to be stored. (See previous post).
3. If a session already exists, it opens that session data file and populates session variables with the data contained in the plain text file. This data is contained in the $_SESSION superglobal variable.

Here is an explaination of special variables like $_SESSION..
http://www.php.net/manual/en/languag...predefined.php

$_SESSION is an array, therefore you use array syntax to create variables and to access them.

Here is a very simple demonstration of a session in action.

Code:
<?php

    // session.php
    // Any PHP script that requires access to session data 
    // must make a call to session_start().
    session_start();

    $_SESSION['foo'] = 'This data persists between connections.';

    echo "<a href='session_2.php?sid='".session_id()."'>Go to the next page.</a>\n";

?>
Then the second file...

Code:
<?php
    // session_2.php
    // start the session
    session_start();

    // This variable still exists!
    echo $_SESSION['foo'];
?>
Finally because session_start() alters the outgoing HTTP headers, it may not have output before it.


Code:
This causes an error
<?php

    echo "This also causes an error";

    session_start();

?>
You can also Google for more examples.
http://www.google.com/search?q=PHP+session+tutorial

HTH!

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
passing php variable to perl nriv08 PHP How-To 0 March 27th, 2008 11:38 AM
Passing variables from HTML to php manunair PHP How-To 9 April 10th, 2006 12:27 AM
Passing PHP variables to javascript wfrisch Pro PHP 10 April 5th, 2005 06:13 AM
Passing Variables from PHP to PHP brian3166 PHP How-To 4 January 31st, 2005 12:44 AM
PHP passing variables to .swf file Ashleek007 Flash (all versions) 4 December 15th, 2004 09:38 PM



All times are GMT -4. The time now is 11:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.