Log in

View Full Version : Who can help me with a script ???



escalador
04-21-2007, 11:00 PM
I have a webpage... in the index is a submission button that leaves to the "true index" page. I want a script that after a visitor press the submission button, always when he will enter on my site, he will be redirected on the "true index" page. i think it's with cookies this script that i need.
Someone can help me ? i wait an anser. Thank's:D

thetestingsite
04-22-2007, 01:37 AM
You could accomplish this using javascript and cookies, but it will only work if the user has a Javascript enabled browser (or if they did not turn it off). Not sure of the exact code in Javascript, but pretty sure someone will.

Hope this helps.

djr33
04-22-2007, 02:11 AM
Or with PHP. That's more reliable, in that PHP, if you have it available, will work no matter what the user has enabled (as long as cookies are enabled, but there is no other way, other than using a server side database storing each person as a user or IP).

Use this form:


<form action="next.php" method="post">
<input type="submit" name="submit" value="agree">
</form>


Put this code on the top of the page that points to (form action="this.php")

<?php
if ($_POST['submit']=='agree') {
setcookie('agree',1);
}
?>


And for the index page, use this code (at the top) to check if they have agreed:


<?php
if ($_COOKIE['agree']==1) {
header('Location: http://my.com/full/path/realindex.htm');
}


You may also want an else statement in one or the other, to redirect if that fails, but I'm not sure how you want to handle that.