Sponsored Content
Homework and Emergencies Homework & Coursework Questions Passing shell variables to a webpage Post 302581283 by Corona688 on Monday 12th of December 2011 03:30:57 PM
Old 12-12-2011
Quote:
Originally Posted by ChedWick
Ideally I'm just looking to have the variable set and retrieved when the page is loaded or refreshed.
Just thought of a potentially much simpler way. PHP has a built-in facility which lets you carry around variables between PHP calls. You might just be able to cram it into the $SESSION variable, which PHP stores either on the server or on the user machine with cookies.

See session basic examples

Code:
<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
  $_SESSION['count'] = 0;
} else {
  $_SESSION['count']++;
}

printf("You have accessed this page %d times\n", $_SESSION['count']); ?>

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing shell variables to awk program..

Hello, Can we pass shell variables like $PATH etc. to a awk program part for example, awk ' { fieldValue=$PATH .... }' file (1 Reply)
Discussion started by: Vishnu
1 Replies

2. Shell Programming and Scripting

passing two variables into a shell script?

Hello all, i have a infile.txt text file which contains such variables: aaa 123 asds 1323 asdsd 13434 lkjlkj 324324 23432 lkjlkj 24324 ljlkj 3j4lk 234kj3 and i want to pass them to my script such as: ./myscript $1 $2 where $1 is the first value in the first row and $2 is the second... (2 Replies)
Discussion started by: Bashar
2 Replies

3. Shell Programming and Scripting

Passing Shell Variables in ISQL

Hi.. I am passing a variable in my shell function. I need to access it for an isql comand in the shell script. However the isql o/p gives no results if i pass a variable in the command. The isql command works perfectly fine if i hardcore the table name. My script is : ... (0 Replies)
Discussion started by: dikki
0 Replies

4. Shell Programming and Scripting

Passing the nawk variables to the shell

nawk '($1 ~ "1000") && ($1 ~ "5665" ) { sub ($6,"89");flag =1;print }' old.txt >> new.txt I want to set a flag in awk , if the both conditions are met. I want to pass this flag to shell Can anyone please help me on this (1 Reply)
Discussion started by: prav076
1 Replies

5. Shell Programming and Scripting

Passing shell variables to a rsh command

I noticed my script is not passing the value of variable alert to the rsh command. I need some assistance, please. This is a solaris environement. Thanks! :confused: #!/bin/sh echo -n "Alert number:" read alert rsh rhost_name 'egrep $alert /opt/var/log/*.logs' (2 Replies)
Discussion started by: lopus
2 Replies

6. Shell Programming and Scripting

Passing gnuplot variables to shell script

Hi, I need to pass a gnuplot value to a shell script. I have a main shell script (Main.sh) that has a bunch of gnuplot commands. Main.sh calls another gnuplot script (Child.gnu). A part of the code in Child.gnu is as follows: sp '</data/src/scripts/results/plot_data.sh $col' u (A):2:3 w pm3d... (8 Replies)
Discussion started by: annazpereira
8 Replies

7. UNIX for Dummies Questions & Answers

Passing Shell Variables to an awk command

Hello, I have two files File1 & File2. File1 76 135 136 200 250 345 .... File2 1 24 1 35 1 36 1 72 .... I want to get all the values form File2 corresponding to the range in File 1 and feed it to a program. Is the code below right? Can I pass shell variables to awk in this... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

8. Shell Programming and Scripting

Passing awk variables to shell

Hi. I need to parse file and assign some values to variables, right now i do like below MYHOMEDIR=`awk '/Home/ {print $NF}' output.txt` MYSHELL=`awk '/Shell/ {print $NF}' output.txt` PRGRP=`awk '/Primary/ {print $NF}' output.txt` SECGRP=`awk '/Second/ {print $NF}' output.txt` In this... (10 Replies)
Discussion started by: urello
10 Replies

9. UNIX for Dummies Questions & Answers

Passing Global Shell variables to awk

Hi All, Iam trying to pass global shell variables and is not working Main script is like below CYEAR=`date +"%y"` CFYEAR=`date +"%Y"` CMONTH=`date +"%m"` if then PMONTH=12 PYEAR=`expr $CYEAR - 1` PFYEAR=`expr $CFYEAR - 1` else PMONTH=`expr... (6 Replies)
Discussion started by: baanprog
6 Replies

10. Shell Programming and Scripting

Passing information to a file on webpage

ok so I have a file on a website. this file is a plain text file i need to be able to update the contents of this file from any internet enabled unix box. does anyone have ideas on how it can be done, without using scp/ftp? i know wget can be used to download the file: wget... (3 Replies)
Discussion started by: SkySmart
3 Replies
SESSION_START(3)							 1							  SESSION_START(3)

session_start - Start new or resume existing session

SYNOPSIS
bool session_start (void ) DESCRIPTION
session_start(3) creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie. When session_start(3) is called or when a session auto starts, PHP will call the open and read session save handlers. These will either be a built-in save handler provided by default or by PHP extensions (such as SQLite or Memcached); or can be custom handler as defined by ses- sion_set_save_handler(3). The read callback will retrieve any existing session data (stored in a special serialized format) and will be unserialized and used to automatically populate the $_SESSION superglobal when the read callback returns the saved session data back to PHP session handling. To use a named session, call session_name(3) before calling session_start(3). When session.use_trans_sid is enabled, the session_start(3) function will register an internal output handler for URL rewriting. If a user uses ob_gzhandler or similar with ob_start(3), the function order is important for proper output. For example, ob_gzhandler must be registered before starting the session. RETURN VALUES
This function returns TRUE if a session was successfully started, otherwise FALSE. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | If a session fails to start, then FALSE is | | | returned. Previously TRUE was returned. | | | | | 4.3.3 | | | | | | | As of PHP 4.3.3, calling session_start(3) after | | | the session was previously started will result in | | | an error of level E_NOTICE. Also, the second ses- | | | sion start will simply be ignored. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 A session example: page1.php <?php // page1.php session_start(); echo 'Welcome to page #1'; $_SESSION['favcolor'] = 'green'; $_SESSION['animal'] = 'cat'; $_SESSION['time'] = time(); // Works if session cookie was accepted echo '<br /><a href="page2.php">page 2</a>'; // Or maybe pass along the session id, if needed echo '<br /><a href="page2.php?' . SID . '">page 2</a>'; ?> After viewing page1.php, the second page page2.php will magically contain the session data. Read the session reference for information on propagating session ids as it, for example, explains what the constant SID is all about. Example #2 A session example: page2.php <?php // page2.php session_start(); echo 'Welcome to page #2<br />'; echo $_SESSION['favcolor']; // green echo $_SESSION['animal']; // cat echo date('Y m d H:i:s', $_SESSION['time']); // You may want to use SID here, like we did in page1.php echo '<br /><a href="page1.php">page 1</a>'; ?> NOTES
Note To use cookie-based sessions, session_start(3) must be called before outputing anything to the browser. Note Use of zlib.output_compression is recommended instead of ob_gzhandler(3) Note This function sends out several HTTP headers depending on the configuration. See session_cache_limiter(3) to customize these head- ers. SEE ALSO
$_SESSION, The session.auto_start configuration directive , session_id(3). PHP Documentation Group SESSION_START(3)
All times are GMT -4. The time now is 08:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy