HOW to pass php variable from one page to other

Discussion in 'PHP' started by psyphil, May 9, 2008.

  1. #1
    I have 3 pages a.php ,b.php and c.php .How can I use the variable of b.php in c.php


    a.php
    
    <script type="text/javascript">
    var width;
    width = screen.width;
    if (width > 0) {
    location.href = "b.php?width=" + width;
    } else 
        exit();
    </script>
    
    <script type="text/javascript"> var width; width = screen.width;
     if (width > 0) { location.href = "b.php?width=" + width; }
     else exit(); </script>
    Code (markup):

    b.php

    <?php
    
    if($_GET['width'])
    {
    public $screen_width;
    $screen_width=$_GET['width'];
    }
    
    else
    {
    include("a.php");
    }
    ?>
    
    <?php if($_GET['width']) { public $screen_width;
     $screen_width=$_GET['width'];
     }
     else { include("a.php"); } ?>
    
    PHP:
    c.php

    
    <?php 
    global $screen_width;
    
     if($screen_width>1024)
    {
    .....
    }
    
    else
    
    {...
    
    }
    
    ?>
    
    <?php global $screen_width;
     if($screen_width>1024) { ..... } 
    else {... } ?>
    
    PHP:
    Help me guys,I can't use include() since a.php has js that keeps reloading everytime and c.php will be redirected to c.php?width=...
     
    psyphil, May 9, 2008 IP
  2. ksamir2004

    ksamir2004 Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi..

    you can use cookie to store value..

     
    ksamir2004, May 9, 2008 IP
  3. psyphil

    psyphil Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    When a visitor visits c.php I want php to go to b.php and send the variable to c.php ,Is that possible using cookies
     
    psyphil, May 9, 2008 IP
  4. ksamir2004

    ksamir2004 Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    As per my knowledge yu can use cookie to store value.
     
    ksamir2004, May 9, 2008 IP
  5. lanmonkey

    lanmonkey Active Member

    Messages:
    549
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #5
    use sessions, much simpler and your not sending your data across the net multiple times
     
    lanmonkey, May 9, 2008 IP