Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    58
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Unset PHP session variable, weird issue...

    PHP Code:

    if(isset($_SESSION['searchstring']))
    {
    $searchString $_SESSION['searchstring'];
    unset(
    $_SESSION['searchstring']);
    }else{
      
    $searchString "Click here to search...";

    If I include the unset command, it causes it to always show "Click here to search..." even if a session variable is set.

    Its as if the unset command:

    PHP Code:
    unset($_SESSION['searchstring']); 
    has been placed before if statement... but it hasnt?

    Any Ideas?
    Last edited by CalumK; 07-17-2013 at 09:47 AM. Reason: Quick Re-phrasing

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    what does this show?

    PHP Code:
    session_start();
    if(isset(
    $_SESSION['searchstring']))
    {
    echo 
    $_SESSION['searchstring'];


    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Could it be possible that your if-statement is executed twice (so you pass it by calling the function again or a reload happens)?

    It could explain that behaviour, but some more information to actually find the real reason would be nice.

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Now, think about this. It's only doing exactly what you're telling it to do.
    PHP Code:
    session_start();
    if(!isset(
    $_SESSION['searchstring'])) 
    {
    $_SESSION['searchstring'] = "Click here to search..."// assigns a default value.

    You can put that on the main index page.
    And don't unset the variable, just make it "" or "Click here to search..." or the form input, according to the need, depending on the search form input.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •