PDA

View Full Version : PHP help



Faraz
February 25th, 2006, 03:14
The following code executes perfectly on the apache server installed on my PC, but it doesn't work when I upload to a webhost. I mean the page with the following code doesn't load up at all. Can you help?


<?
session_start();
session_register( "session" );
session_register( "hits" );
session_register( "codenumber" );
$session=session_id();
if ($code==$codenumber)
{
if ($HTTP_---------="http://localhost/ute/main.php")
{
if ($B1=="Next Site")
{
$hits++;
}
}
else
{
header("Location: main.php");
}
}
?>
<html>

<head>
<title>New Page 1</title>
<SCRIPT>
var interval = "";
var i = 20;
var cn=<? print $codenumber=rand(1,1000);?>;
function EnableSubmit(whichButton)
{
if (document.getElementById)
{
// this is the way the standards work
document.getElementById(whichButton).disabled = false;
}
else if (document.all)
{
// this is the way old msie versions work
document.all[whichButton].disabled = false;
}
else if (document.layers)
{
// this is the way nn4 works
document.layers[whichButton].disabled = false;
}
}

function startInterval()
{
interval = window.setInterval("tTimer()",1000);
}
function stopInterval()
{
window.clearInterval (interval);
interval="";
}
function tTimer()
{
document.f.display.value = i--;
if (i == -1)
{
stopInterval();
EnableSubmit('mFormSubmit');
f.code.value=cn;
}
}
</script>
</head>

<body>

<form name="f" action="main.php" method=post>
<p><input type="text" name="display" value size="2"><?print " Hits registered: $hits";?>
<p><input type="submit" value="Next Site" id="mFormSubmit" name="B1" disabled>
<input type="hidden" name="code">
</form>
<script>
startInterval();
</script>
<form method="POST" action="done.php">
<p><input type="submit" value="Done" name="B2"></p>
</form>
<p align="center"><IFRAME src="frame.php" height="500" width="800">
</IFRAME></p>

</body>
</html>

Sorry, if you find it scattered and messy. :rolleyes2

themoose
February 25th, 2006, 04:05
Not all servers support <?. Try changing that to <?php.

Otherwise, it could be php version. Check for differences.

talence
February 25th, 2006, 04:06
i think if you change the HTTP refferer then it may work.

Find this:


http://localhost/ute/main.php


Change it to :


http://www.yourdomain.com/ute/main.php


As its a condition there it might get your script work. I m not sure as not all the things can understand from this script only.

Regards

Faraz
February 25th, 2006, 04:09
Yeah, you are right. It's a php version. :(

Could you tell me how can I register variables in PHP 4.4.1 with register_globals off. session_register doesn't seem to work. Also how could I get the value of $HTTP_REFERER?

talence
February 25th, 2006, 04:13
($HTTP_---------="http://localhost/ute/main.php")

Here is the value of HTTP_REFFERER

And about the register_globals Off you may contact with your hosters to enable it. Just need to edit the php.ini file and need to set the value of $register_globals to "on".

regards

Faraz
February 25th, 2006, 04:22
No, I mean when I type print $HTTP_REFERER; it doesn't give anything in PHP 4.4.1.

I found the way to register variables with register_globals off though.

talence
February 25th, 2006, 11:13
No, I mean when I type print $HTTP_REFERER; it doesn't give anything in PHP 4.4.1.

Untill there are any refferer how the http_referer will print a value?? Use the following script:



<?php
if ($HTTP_REFERER) {
echo $HTTP_REFERER;
} else {
echo "No Referer";
}
?>


This will echo no referer if there are no referer of you page.

Regards

egomac
February 26th, 2006, 15:43
you might wanna try inserting this code on top of your page:



if(!empty($_GET)) extract($_GET);
if(!empty($_POST)) extract($_POST);

Works for me when register globals is set to off...

Canuckkev
February 26th, 2006, 15:47
Not all servers will grab the $HTTP_REFERER . So, if your server doesn't...out of luck.

BeIIy
February 26th, 2006, 16:22
Try $_SERVER['HTTP_REFERER'] instead.

talence
February 28th, 2006, 11:12
you might wanna try inserting this code on top of your page:



if(!empty($_GET)) extract($_GET);
if(!empty($_POST)) extract($_POST);

Works for me when register globals is set to off...
This will not generate the value of referer. Only extract the get and post informations before getting into the script. Therefore it requires no register global enabling.