2 Replies - 1167 Views - Last Post: 14 August 2011 - 09:11 AM Rate Topic: -----

#1 sunjava1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 14-May 11

How to redirect after taking variable value in php?

Posted 14 August 2011 - 08:51 AM

How can we redirect to original link after taking value of variable. This is my code:



<?php

if (isset($_GET['action']) == 'increment')
{
    counter('increment');
}



echo 'Current count: ',counter('count'),' <a href="/count.php?action=increment?">add me</a>';

function counter($action)
{

if ($action == 'count')
    {
        return file_get_contents('./count.txt');
    }
    else
    {
        file_put_contents('./count.txt', (string) (((int) file_get_contents('./count.txt')) + 1));
    }
    return true;


}

?>





I am not finding way to set redirect to original page. i.e. after clicking the link, it should redirect to /counter.php.

Is This A Good Question/Topic? 0
  • +

Replies To: How to redirect after taking variable value in php?

#2 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 169
  • View blog
  • Posts: 606
  • Joined: 12-October 09

Re: How to redirect after taking variable value in php?

Posted 14 August 2011 - 09:02 AM

If you mean you want to go back to counter.php after someone has gone to counter.php?action=increment

Then just add in a redirect header:

function counter($action)
{
if ($action == 'count')
    {
        return file_get_contents('./count.txt');
    }
    else
    {
        file_put_contents('./count.txt', (string) (((int) file_get_contents('./count.txt')) + 1));
    }
    return true;
}


if (isset($_GET['action']) == 'increment')
{
counter('increment');
header('location:counter.php');
exit();
}

echo 'Current count: ',counter('count'),' <a href="/count.php?action=increment?">add me</a>';


Was This Post Helpful? 1
  • +
  • -

#3 sunjava1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 14-May 11

Re: How to redirect after taking variable value in php?

Posted 14 August 2011 - 09:11 AM

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1