how to post already posted variables!?!?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

how to post already posted variables!?!?

Post by Nik »

<?php
ob_start(); error_reporting(E_ALL); $i=0;
echo "<body background=pics/anemos.bmp>";

if (@mysql_connect('localhost', 'nik', 'macgyver'));
else @mysql_connect('localhost', 'root');
mysql_select_db('db_nik');

$sql=mysql_query("SELECT * FROM member");
while ($row = mysql_fetch_array($sql))
if (($_SERVER['PHP_AUTH_USER']==$row['user']) && ($_SERVER['PHP_AUTH_PW']==$row['pass']))
$i=1;
else
$i=1;

if ($i==1)
{
header('WWW-Authenticate: Basic realm="Ðïéüò åßóáé?"');
die ("<font size=5 color=Cyan> Äåí åßóáé ìÝëïò ôçò ÁôæÝíôáò...ðñÝðåé ðñþôá íá ãñáöôåßò êáé ìåôÜ íá îáíÜñèåéò!!");
}
else
{
$onoma = $_POST['onoma'];
$eponymo = $_POST['eponymo'];
$til = $_POST['til'];
$email = $_POST['email'];
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];

if (isset($_POST['kataxorisi'])) header("Refresh: 1; URL=http://localhost/kataxorisi.php");
if (isset($_POST['emfanisi'])) header("Refresh: 1; URL=http://localhost/emfanisi.php");
if (isset($_POST['metavoli'])) header("Refresh: 1; URL=http://localhost/metavoli.php");
if (isset($_POST['diagrafi'])) header("Refresh: 1; URL=http://localhost/diagrafi.php");
}
?>

How am i gonna be able to give the variables to the selected php scripts?
User avatar
cwcollins
Forum Commoner
Posts: 79
Joined: Thu May 16, 2002 3:51 pm
Location: Milwaukee, WI, USA

Post by cwcollins »

You may be able to send a POST header with the header() function, but I'm not sure. I'd check out the HTTP1.1 RFC and the POST Section specifically.

also, this looks like a pretty reasonable solution: POSTing without a form

c.collins
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

Is there a way that i can redirect a php script usinfg the header command to another php script and then after the other php script finishes to return control tou the next line from the caller script? i want this because i have a code in one script that i use to often that i want to return a value its time like a function but in another php script so that i cant paste this code to evry other php script!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you put the script you want to use often into a function in its own file then you can just include() this file into other scripts and gain access to the function. For what you are trying to do this would probably be the way I would go about it.

Mac
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

Well that look s very good idea bu i tried it and it didint work!

tha a script posts to b script and i have in c script the include 'b.php'
but it dosent get the varibles that b has

ehay is that?
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

i also get this from my remote web server when i use htaccess by a header command

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webadmin-uk@lycos-europe.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log


:(
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Nik wrote:Well that look s very good idea bu i tried it and it didint work!
The concept does work - perhaps there's a problem with your implementation.
Nik wrote:tha a script posts to b script and i have in c script the include 'b.php'
but it dosent get the varibles that b has

ehay is that?
Normally you would have a script posting to b script and b script including c script in order to use a function in c.

Mac
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

My index.php posts to post.php ehich is the following

<?php
ob_start(); error_reporting(E_ALL); $i=0;
echo "<body background=pics/anemos.bmp>";

$onoma = $_POST['onoma'];
$eponymo = $_POST['eponymo'];
$til = $_POST['til'];
$email = $_POST['email'];
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];

if (@mysql_connect('localhost', 'nik', 'macgyver'));
else @mysql_connect('localhost', 'root');
mysql_select_db('nikosgr_uk_db');

$sql=mysql_query("SELECT * FROM member");
while ($row = mysql_fetch_array($sql))
if (($_SERVER['PHP_AUTH_USER']==$row['user']) && ($_SERVER['PHP_AUTH_PW']==$row['pass']))
$i=1;
else
$i=0;

if ($i==0)
{
header('WWW-Authenticate: Basic realm="Ðïéüò åßóáé?"');
die ("<font size=5 color=Grey> Äåí åßóáé ìÝëïò ôçò ÁôæÝíôáò...ðñÝðåé ðñþôá íá ãñáöôåßò êáé ìåôÜ íá îáíÜñèåéò!!");
}
else
{
if (isset($_POST['kataxorisi'])) header("Refresh: 1; URL=http://localhost/kataxorisi.php");
if (isset($_POST['emfanisi'])) header("Refresh: 1; URL=http://localhost/emfanisi.php");
if (isset($_POST['metavoli'])) header("Refresh: 1; URL=http://localhost/metavoli.php");
if (isset($_POST['diagrafi'])) header("Refresh: 1; URL=http://localhost/diagrafi.php");
if (isset($_POST['eggrafi'])) header("Refresh: 1; URL=http://localhost/eggrafi.php");
}
?>

my kataxorisi.php is this but it seems that it dosent see the vars inside post.php even if i have include post.php in it!

<?php
include "post.php";
ob_start(); error_reporting(E_ALL); $i=0;
echo "<body background=pics/anemos.bmp>";
echo "<font size=5 color=Yellow>";

if (@mysql_connect('localhost', 'nik', 'macgyver'));
else @mysql_connect('localhost', 'root');
mysql_select_db('nikosgr_uk_db');

if (empty($onoma)) {echo "Äåí óõìðëÞñùóåò ôï ¼íïìá ôïõ ößëïõ óïõ!<p>"; $i=1;}
if (empty($eponymo)) {echo "Äåí óõìðëÞñùóåò ôï Åðþíõìï ôïõ ößëïõ óïõ!<p>"; $i=1;}
if (empty($til)) {echo "Äåí óõìðëÞñùóåò ôï ÔçëÝöùíï ôïõ ößëïõ óïõ!<p>"; $i=1;}
if (empty($email)) {echo "Äåí óõìðëÞñùóåò ôï E-mail ôïõ ößëïõ óïõ!<p>"; $i=1;}
if ($i!=0) exit;

mysql_query("INSERT INTO member_data VALUES ('$onoma', '$eponymo', '$til', '$email', '$user')");

$sql=mysql_query("SELECT * FROM member_data WHERE user='$user'");
$rows = mysql_num_rows($sql);

echo "<font size=5 color=Grey> Ç åããñáöÞ êáôá÷ùñÞèçêå <font color=Yellow> $user <br>";
echo "<font size=5 color=Grey> ÅðáöÝò ìÝ÷ñé óôéãìÞò: <font color=Yellow> $rows";

mail ("nik0s@mycosmos.gr", "Ï $user ìüëéò Ýêáíå êáôá÷þñçóç! ÅðáöÝò: $rows", "", "From: 007@spy.gr");
?>

Do u see the problem?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

$_POST is a superglobal. Try this:

Omit the line with include post.php in kataxorisi.php (etc).

Replace with:

$var1 = $_POST['var1'];
$var2 = ..etc.


Or, as was mentioned above, include kataxorisi.php (etc) rather than sending headers for them.
Last edited by McGruff on Sat Feb 22, 2003 12:01 pm, edited 1 time in total.
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

I know this already! but the problem is that i want to have all my vars in post.php and from there to give it to the others php scripts instead of in every one php file write them again! i have a lot of files....why not read the vars from post.php?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Did you try INCLUDING instead of HEADERING?
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

I use include 'post.php' in my othjer 4 php scripts so that thay ara able to get post's.php variables...is that what u mean?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

No - can you include kataxorisi.php (etc) rather than make header calls?
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

u mean to do the opposite thing of what i jus did

include('c.php')
include('d.php')
include('e.php')
include('f.php')

in b.php?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

OPEN EYES ENGAGE BRAIN

I just told you something to try. This was also explained way back in the sixth reply.

I like to help but you've got to help yourself a bit too.
Post Reply