Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

header problem

Status
Not open for further replies.

jartse

Programmer
Apr 10, 2002
15
FI
so i want this code work like when user clik link it
check if it's allready click if not it write $user file
$advertise code and jump page continue.php if user
have click link it jump warnign.php

code works fine when user clicks first time it creates
($user).txt file and add $advertise code

<?php
$advertise = $HTTP_GET_VARS['A'];
$user = $HTTP_GET_VARS['I'].&quot;.txt&quot;;
$setok = &quot;0&quot;;

if (file_exists($user))
{
$fp = fopen($user, &quot;r&quot;);
echo &quot;File : $user<br>&quot;;
while ($line = fgets($fp,255))
{
if (stristr($line, $advertise))
{
$setok = &quot;1&quot;;
echo $line;
}
}
fclose($fp);
}

else
{
$fp = fopen ($user, &quot;aw&quot;);
fputs($fp, $advertise.&quot;\n&quot;);
fclose($fp);
}

if ($setok == '0'){header(&quot;LOCATION: continue.php&quot;);}
elseif ($setok == '1'){header(&quot;LOCATION: warnign.php&quot;);}
?>
 
Here you go!

fopen($user, &quot;r+&quot;) opens the file and if it doesn't exist it creates it.
Main problem was you never added a new entry once the file existed.

<?php
$advertise = $HTTP_GET_VARS['A'];
$user = $HTTP_GET_VARS['I'].&quot;.txt&quot;;
$setok = &quot;0&quot;;

$fp = fopen($user, &quot;r+&quot;);
echo &quot;File : $user<br>&quot;;
while ($line = fgets($fp,255))
{
if (stristr($line, $advertise))
{
$setok = &quot;1&quot;;
echo $line;
}
}
}
// read to end of file anyway
if (setok==&quot;0&quot;)
{
fputs($fp, $advertise.&quot;\n&quot;);
fclose($fp);
header(&quot;LOCATION: continue.php&quot;);
}
else
{
fclose($fp);
header(&quot;LOCATION: warnign.php&quot;);
}
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top