/    Sign up×
Community /Pin to ProfileBookmark

echo values from header

Hi Below is code the uses a header to redirect to another page. How can I use my variables in another page. If I use include the variable values echo the message.

[code=php]
header(“Location: “. $MM_redirectLoginFailed );
$msg .= ‘<div style=”width:200px” id= “formmessage”>’;
$msg .= ‘Enter ALL login information!’;
$msg .= ‘</div>’;
}
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@pcthugOct 26.2006 — I'd suggest setting a Global Superglobal Variable. Although you may use the Session, Cookie or Post arrays, the simplest to implement would be use of the Get variable array.

In the query-string of the redirect header, send the error message as well:
[code=php]
$msg .= '<div style="width:200px" id= "formmessage">';
$msg .= 'Enter ALL login information!';
$msg .= '</div>';

// encode variable for use within a URL
urlencode($msg);

// append our variable to our redirect page
header("Location: $MM_redirectLoginFailed?msg=$msg");
[/code]

Now on the page that is to display the [font=Courier New]$msg[/font] variable, we will retrieve and decode our message from the query string and then we will display it:
[code=php]
$msg = isset($_GET['msg']) && !empty($_GET['msg']) ? urldecode($msg) : '';
echo $msg;
[/code]
Copy linkTweet thisAlerts:
@kprocauthorNov 14.2006 — HI

I have this kinda working but the formating does not follow throw


when I view source I get

<div style="width:350px" id= "formmessage">You cannot add yourself to your buddy list</div>

the test displays but the id is not working. I think its becasue of the that has been added

any help is great

the code that generates this is

[code=php]
$msg .= '<div style="width:350px" id= "formmessage">';
$msg .= 'You cannot add yourself to your buddy list';
$msg .= '</div>';

urlencode($msg);

header("Location: mybuddies.php?msg=$msg");

exit();

[/code]
Copy linkTweet thisAlerts:
@pcthugNov 14.2006 — Use this php instead:
[code=php]
$msg = isset($_GET['msg']) && !empty($_GET['msg']) ? urldecode($msg) : ''
if(get_magic_quotes_gpc())
$msg = stripslashes($msg);

echo $msg;[/code]
Copy linkTweet thisAlerts:
@kprocauthorNov 20.2006 — I tried your last post and I get

Parse error: parse error, unexpected T_IF in C:Program Filesxampphtdocsfamilyclickmybuddies.php on line 33

cannot really see the error
Copy linkTweet thisAlerts:
@pcthugNov 20.2006 — Sorry, a missing semicolon and an invalid variable reference. Try this code instead:
[code=php]
$msg = isset($_GET['msg']) && !empty($_GET['msg']) ? urldecode($_GET['msg']) : '';
if(get_magic_quotes_gpc())
$msg = stripslashes($msg);

echo $msg;[/code]
×

Success!

Help @kproc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...