Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sending a response header to php script

Posted on 2006-05-21
7
Medium Priority
?
262 Views
Last Modified: 2013-12-25
Hi, 'sperts!

I have inherited a subscription based site that uses both php and perl/cgi for user management. I have a php script that will post to a cgi/perl script that searches for a specific username. The current perl script simply prints out the results. What do I add to the perl script so that it sends the result variable back to my php script?

The perl script is:

$name = `cat /path/to/my/list|grep -i "(results from form)"`;
$name =~ s/\n/<br>/ig;
print $name;

What do I need to change the "print $name" so that the result is sent (GET is fine) to a php script? Something like in php:

header("Location: http://www.mysite.com?name=results/");
0
Comment
Question by:admash
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:Perl_Diver
ID: 16730529
$name = `cat /path/to/my/list|grep -i "(results from form)"`;
$name =~ s/\n/<br>/ig;
print "Location: http://www.mysite.com?name=$name\n\n";

does $name really contain html code in it?
0
 

Author Comment

by:admash
ID: 16730589
No, there is no html present in $name, obviously there is a lot of cleaning up I need to do to the code. I am inexperienced with perl, however. I have been using php for a while now.

What I am getting is:

Location: http://www.mysite.com?name=all of the results

in my browser now. what do I need to do to actually send the url?
0
 

Author Comment

by:admash
ID: 16730696
Let me be a little more specific:

This is what needs to happen:

checkuser.php
    This script checks current sales and finds expired accounts
    When it finds expired account, I need to see if the username is still active.
    This php script sends form info via post to findthisuser.cgi written in perl for a search
findthisuser.cgi
    Takes the POST info and searches (the script is above).
     I need this script to either return the search results to checkuser.php, OR
    send a yes or no variable to checkuser.php to let me know that the username is there or not.

Maybe that will help make some sense. This is a convoluted way to handle this, but I am working with some tight requirements as to what I am allowed to change.

All of this works great so far, but I need to change the last part of the perl script so that it sends the appropriate response back to my php script.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 8

Expert Comment

by:Perl_Diver
ID: 16730733
if you are seeing the literal words:

Location: http://www.mysite.com?name=all of the results

in the browser this means you have already printed an http header before executing the print "Location:....\n\n" command.

You may also need to uri encode $name before sending it out in the URI string.

print "Location:....\n\n";

is the same as the php function:

header("Location: http://www.mysite.com?name=results/");



 
0
 
LVL 8

Accepted Solution

by:
Perl_Diver earned 2000 total points
ID: 16730745
if this is all the perl script does:

 $name = `cat /path/to/my/list|grep -i "(results from form)"`;

you could just do that in your php program using the appropiate php syntax for capturing output back from the shell. The above line is doing just that:, returning the value from the operating systems cat and grep functions.
0
 

Author Comment

by:admash
ID: 16730789
(slaps self on forehead)

$name = shell_exec('cat /path/to/my/list|grep -i "(name I am looking for)"');

It works like a charm.

That's why I like EE. You guys always take seemingly complicated things and make them so simple. I hope some of this rubs off on me!

Thanks Perl Diver for your patience, knowledge and willingness to share!

Aaron
0
 
LVL 8

Expert Comment

by:Perl_Diver
ID: 16731570
You're welcome.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses
Course of the Month20 days, 19 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question