重定向PHP后的变量

时间:2014-03-03 03:22:16

标签: php redirect web

重定向后有没有办法继承变量?

例如在projects.php

foreach ($projects as $key=>$project) : ?>
    <li class="">
        <a href="<?= root_url('project/'.$project->url_title) ?>/" title="<?= $project->name ?>">
            <? if ( isset($project->images[0]) ) :
                $thumb_image_path = $project->images[0]->getThumbnailPath(310, 276, true, array('mode'=>'fit'));
            else :
                $thumb_image_path = '//placehold.it/320x285/ffffff/000000';
            endif ?>
            <? // echo $thumb_image_path; ?> 
            <img src="<?= $thumb_image_path ?>" alt="<?= $project->name ?>">
            <div class="caption">
                <h4><?= $project->name ?></h4>
                <h5 class="hide-for-small-only">Not dynamic</h5>
                <p class="hide-for-small-only"><?= $project->description ?></p>
            </div> 
        </a>
    </li>
<? endforeach ?>

当重定向到project / nameofheproject时,有没有办法仍然可以访问变量$ project?所以我可以用它来做$ project-&gt; title

感谢您的回答

1 个答案:

答案 0 :(得分:2)

要扩展@MarcB,您可以将变量添加到查询字符串中:

your_url?variable=foo

或将其添加到会话

$_SESSION['variable'] = 'foo';

或cookie(mmmm)

$_COOKIE['variable'] = 'foo'; setcookie('variable', 'foo');