I have a form/page that seems to submit the form data when the page loads. If you click "add record" it loads the page and creates a new entry into the database without entering any information. If you complete the form it works as desired but creates and additional record. What would cause the form to submit "on load"? Also I use this same form for other areas of the site with no issue but the data is stored into a different table.
My Code
<?
if(isset($_POST['title'])) {
if(isset($_POST['gallery_1'])) {
$gallery_1 = $_POST['gallery_1'];
}
if(isset($_POST['gallery_2'])) {
$gallery_2 = $_POST['gallery_2'];
}
if(isset($_POST['gallery_3'])) {
$gallery_3 = $_POST['gallery_3'];
}
if(isset($_POST['gallery_4'])) {
$gallery_4 = $_POST['gallery_4'];
}
if(isset($_POST['gallery_5'])) {
$gallery_5 = $_POST['gallery_5'];
}
if(isset($_POST['download_1'])) {
$download_1 = $_POST['download_1'];
}
if(isset($_POST['download_2'])) {
$download_2 = $_POST['download_2'];
}
if(isset($_POST['download_3'])) {
$download_3 = $_POST['download_3'];
}
$title = $_POST['title'];
$title_gallery = $_POST['title_gallery'];
$date = $_POST['date'];
$introduction = $_POST['introduction'];
$download_1_title = $_POST['download_1_title'];
$download_2_title = $_POST['download_2_title'];
$download_3_title = $_POST['download_3_title'];
$dropbox_title = $_POST['dropbox_title'];
$dropbox_info = $_POST['dropbox_info'];
$dropbox_link = $_POST['dropbox_link'];
$video_title = $_POST['video_title'];
$video = $_POST['video'];
$handle = new Upload($_FILES['gallery_1']);
if ($handle->uploaded) {
$handle->file_max_size = 4000000;
$handle->image_resize = true;
$handle->image_ratio = true;
$handle->image_ratio_crop = true;
$handle->image_y = 407;
$handle->image_x = 460;
$handle->allowed = array('image/pjpeg','image/jpeg', 'image/jpg');
$handle->Process($dir_dest);
if ($handle->processed) {
echo 'issue image 1 uploaded ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB<br /><br />';
$gallery_1 = $dir_pics.'/' . $handle->file_dst_name ;
} else {
echo ' the following error occurred while uploading image 1<br />';
echo ' Error: ' . $handle->error . '<br /><br />';
}
$handle-> Clean();
}
$handle2 = new Upload($_FILES['gallery_2']);
if ($handle2->uploaded) {
$handle2->file_max_size = 4000000;
$handle2->image_resize = true;
$handle2->image_ratio = true;
$handle2->image_ratio_crop = true;
$handle2->image_y = 307;
$handle2->image_x = 460;
$handle2->allowed = array('image/pjpeg','image/jpeg', 'image/jpg');
$handle2->Process($dir_dest);
if ($handle2->processed) {
echo 'issue image 2 uploaded ' . round(filesize($handle2->file_dst_pathname)/256)/4 . 'KB<br /><br />';
$gallery_2 = $dir_pics.'/' . $handle2->file_dst_name ;
} else {
echo ' the following error occurred while uploading image 2<br />';
echo ' Error: ' . $handle2->error . '<br /><br />';
}
$handle2-> Clean();
}
$handle3 = new Upload($_FILES['gallery_3']);
if ($handle3->uploaded) {
$handle3->file_max_size = 4000000;
$handle3->image_resize = true;
$handle3->image_ratio = true;
$handle3->image_ratio_crop = true;
$handle3->image_y = 307;
$handle3->image_x = 460;
$handle3->allowed = array('image/pjpeg','image/jpeg', 'image/jpg');
$handle3->Process($dir_dest);
if ($handle3->processed) {
echo 'issue image 3 uploaded ' . round(filesize($handle3->file_dst_pathname)/256)/4 . 'KB<br /><br />';
$gallery_3 = $dir_pics.'/' . $handle3->file_dst_name ;
} else {
echo ' the following error occurred while uploading image 3<br />';
echo ' Error: ' . $handle3->error . '<br /><br />';
}
$handle3-> Clean();
}
$handle4 = new Upload($_FILES['gallery_4']);
if ($handle4->uploaded) {
$handle4->file_max_size = 4000000;
$handle4->image_resize = true;
$handle4->image_ratio = true;
$handle4->image_ratio_crop = true;
$handle4->image_y = 307;
$handle4->image_x = 460;
$handle4->allowed = array('image/pjpeg','image/jpeg', 'image/jpg');
$handle4->Process($dir_dest);
if ($handle4->processed) {
echo 'main image for issue uploaded ' . round(filesize($handle4->file_dst_pathname)/256)/4 . 'KB<br /><br />';
$gallery_4 = $dir_pics.'/' . $handle4->file_dst_name ;
} else {
echo ' the following error occurred while uploading the main image<br />';
echo ' Error: ' . $handle4->error . '<br /><br />';
}
$handle4-> Clean();
}
$handle5 = new Upload($_FILES['gallery_5']);
if ($handle5->uploaded) {
$handle5->file_max_size = 4000000;
$handle5->image_resize = true;
$handle5->image_ratio = true;
$handle5->image_ratio_crop = true;
$handle5->image_y = 307;
$handle5->image_x = 460;
$handle5->allowed = array('image/pjpeg','image/jpeg', 'image/jpg');
$handle5->Process($dir_dest);
if ($handle5->processed) {
echo 'map image for issue uploaded ' . round(filesize($handle5->file_dst_pathname)/256)/4 . 'KB<br /><br />';
$gallery_5 = $dir_pics.'/' . $handle5->file_dst_name ;
} else {
echo ' the following error occurred while uploading the map image<br />';
echo ' Error: ' . $handle5->error . '<br /><br />';
}
$handle5-> Clean();
}
$handle6 = new Upload($_FILES['download_1']);
if ($handle6->uploaded) {
$handle6->file_max_size = 4000000;
$handle6->allowed = array('application/*', 'image/*');
$handle6->Process($dir_dest);
if ($handle6->processed) {
echo 'download one uploaded' . round(filesize($handle6->file_dst_pathname)/256)/4 . 'KB<br /><br />';
$download_1 = $dir_pics.'/' . $handle6->file_dst_name ;
} else {
echo ' the following error occurred while uploading download one<br />';
echo ' Error: ' . $handle6->error . '<br /><br />';
}
$handle6-> Clean();
}
$handle7 = new Upload($_FILES['download_2']);
if ($handle7->uploaded) {
$handle->file_max_size = 4000000;
$handle->allowed = array('application/*', 'image/*');
$handle7->Process($dir_dest);
if ($handle7->processed) {
echo 'download two uploaded' . round(filesize($handle7->file_dst_pathname)/256)/4 . 'KB<br /><br />';
$download_2 = $dir_pics.'/' . $handle7->file_dst_name ;
} else {
echo ' the following error occurred while uploading download two<br />';
echo ' Error: ' . $handle7->error . '<br /><br />';
}
$handle7-> Clean();
}
$handle8 = new Upload($_FILES['download_3']);
if ($handle8->uploaded) {
$handle->file_max_size = 4000000;
$handle->allowed = array('application/*', 'image/*');
$handle8->Process($dir_dest);
if ($handle8->processed) {
echo 'download three uploaded' . round(filesize($handle8->file_dst_pathname)/256)/4 . 'KB<br /><br />';
$download_3 = $dir_pics.'/' . $handle8->file_dst_name ;
} else {
echo ' the following error occurred while uploading download three<br />';
echo ' Error: ' . $handle8->error . '<br /><br />';
}
$handle8-> Clean();
}
}
$query = mysql_query("INSERT INTO news (
id ,
title ,
title_gallery ,
date ,
introduction ,
gallery_1 ,
gallery_2 ,
gallery_3 ,
gallery_4 ,
gallery_5 ,
download_1 ,
download_2 ,
download_3 ,
download_1_title ,
download_2_title ,
download_3_title ,
dropbox_title ,
dropbox_info ,
dropbox_link ,
video_title ,
video
) VALUES
(NULL,
'$title',
'$title_gallery',
'$date',
'$introduction',
'$gallery_1',
'$gallery_2',
'$gallery_3',
'$gallery_4',
'$gallery_5',
'$download_1',
'$download_2',
'$download_3',
'$download_1_title',
'$download_2_title',
'$download_3_title',
'$dropbox_title',
'$dropbox_info',
'$dropbox_link',
'$video_title',
'$video');");
if($query) {
$message = $title . " has been added";
}else{
$message = "an error occurred while updating this entry";
}
?>
</p>
<? if(isset($_POST['title'])) { ?>
<div id="content_holder">
<p style="text-align:center;padding-top:20px;">
<strong><? echo $message; ?></strong><br/>
<span class="error"><? if($error_message) { echo $error_message; } ?></span>
Add another Record/Item</p>
<!-- end content_holder -->
</div>
<? }else{ ?>
The form... and Closing brackets...
Your INSERT query is outside your if(isset($_POST['title'])) statement. A row is inserted on every page load with empty values.
Is it possible on the php side of things you do not check if the form was submited and just blindly create a new record from empty data every time the page loads?
edit: exactly. The mysql query runs no mather what. Put a if around it to make sure a form was submited.
Related
when i set some cron jobs for loading a php file cron doesn't work and it seams some php function have problem with cron job.
i know my cron command is true because i tested my cron job working true with simple php code that put date to a text file so my cron command is true i tested all ways of command like : wget, crul , cd, php , /user/local/bin/php and another but i don't know why my php code doesn't work and too i test that codes working very well when i loading php files with my browser.
my php file code:
<?php
header('Content-Type: text/html; charset=utf-8');
include ('simple_html_dom.php');
$mycache_url = 'http://example3.com';
$mybziran_url = 'http://example2.com';
function addhttp($url)
{
if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
global $mybziran_url;
$url = ltrim($url, '/');
$url = $mybziran_url . '/' . $url;
}
return $url;
}
function urlencodeproblem($badurl)
{
$badurl = urlencode($badurl);
$badchar = array('%3A', '%2F');
$truechar = array(':', '/');
$badurl = str_replace($badchar, $truechar, $badurl);
return $badurl;
}
$url_html = #file_get_html($mycache_url);
$bziran_url = '';
$bziran_title = '';
foreach (#$url_html->find('a') as $elements) {
$bziran_url[] = urlencodeproblem($elements->href);
$bziran_title[] = $elements->innertext;
}
$myi = count($bziran_url);
for ($i = 0; $i < $myi; ++$i) {
$post_title = $bziran_title[$i];
$post_url = $bziran_url[$i];
$html = #file_get_html($post_url);
foreach ($html->find('div.price') as $myhtml_price_adelete) {
echo '######' . $myhtml_price_adelete->innertext . '######';
}
$bad_title_my = '';
foreach ($html->find('h1 a') as $myhtml_price_adelete) {
$bad_title_my .= $myhtml_price_adelete->innertext;
}
if (empty($bad_title_my)) {
echo $post_url;
echo 'prob';
} else {
$kalame = urlencode($post_title);
$A2_html = 'ok';
foreach ($html->find('a') as $myhtml_a_code) {
$e_ahref = addhttp($myhtml_a_code->href);
$myhtml_a_code->href = $e_ahref;
$myhtml_a_code->target = '_blank';
}
$html->save();
foreach ($html->find('img') as $myhtml_img_code) {
if (strpos($myhtml_img_code->src, 'base64') === false) {
$e_imgsrc = addhttp($myhtml_img_code->src);
$myhtml_img_code->src = $e_imgsrc;
}
}
$html->save();
$mymeta_keyword = '';
foreach ($html->find('meta[name=keywords]') as $myhtml_keyword) {
$mymeta_keyword[] = $myhtml_keyword->content;
}
foreach ($html->find('p') as $mytagdelete) {
if (strpos($mytagdelete->innertext, 'tag :') !== false) {
$mytagdelete->outertext = '';
}
}
$html->save();
foreach ($html->find('h1 a') as $myadelete) {
$myadelete->outertext = $myadelete->innertext;
}
$html->save();
$a3_href = '';
$a2_href = $html->find("img[alt=buy]");
foreach ($a2_href as $a2_href) {
$a2_href->outertext =
'<br><p align="center"><img alt="pay-download" src="http://exam.com/tmp_files/01-pay-download.png"></p>';
}
$html->save();
echo '<br>buy : ' . $a3_href . '<br>';
$myhtmlcode3 = '';
foreach ($html->find('div.prod') as $myhtmlcode) {
$myhtmlcode3 .= $myhtmlcode->outertext;
}
$html->save();
echo '<br>*** title ***' . $post_title . '<br>';
echo $post_url . '<br>';
$i_t = mt_rand(1, 34);
$mysaier_mahsolat = '<br>
<a target="_blank" href="http://ayta.ir/index.php?page=' . $i_t . '"> click </a>
<br>';
echo $mysaier_mahsolat;
echo $A2_html . $myhtmlcode3 . '<br>';
echo 'keyword :' . $mymeta_keyword[0];
}
}
?>
<?
$crontest = date("Y-m-d - h:i:s") . "\n" . file_get_contents(dirname(__file__) .
DIRECTORY_SEPARATOR . "cron.txt");
echo $crontest;
file_put_contents("cron.txt", $crontest);
?>
I want to get the episode number and Released from
http://www.omdbapi.com/?t=the+walking+dead&season=6&r=json
but I don't know how to extract arrays from the api.
Can someone help me?
My code is:
$title = 'the+walking+dead';
$title2 = urlencode($title);
$json=file_get_contents("http://www.omdbapi.com/?t=$title2&season=6&r=json");
$details=json_decode($json);
if($details->Response=='True')
{
$episodios=$details->Episodes;
}
$title = 'the+walking+dead';
$title2 = urlencode($title);
$json = file_get_contents("http://www.omdbapi.com/?t=$title2&season=6&r=json");
$details = json_decode($json);
if ($details->Response == 'True') {
echo 'There are ' . count($details->Episodes) . ' episodes<br />';
foreach ($details->Episodes as $key => $episode) {
echo 'Episode criteria number is ' . ($key + 1) . '<br />';
echo 'Episode Number: ' . $episode->Episode . '<br />';
echo 'Released: ' . $episode->Released . '<br />';
}
}
<?php
$title = 'the+walking+dead';
$title2 = urlencode($title);
$json=file_get_contents("http://www.omdbapi.com/t=$title2&season=6&r=json");
$details=json_decode($json);
if($details->Response=='True')
{
$episodios=$details->Episodes;
foreach ($episodios as $episode) {
echo 'Episode Number: ' . $episode->Episode . '<br />';
echo 'Released Date: ' . $episode->Released . '<br />';
}
}
?>
I have a block of code thats working perfectly to pull data about different office locations.
What I would like to do is be able to make the last iteration of this loop change the div class to something else so I can apply a different set of css styles.
$fields = get_group('Offices');
foreach($fields as $field){
echo'<div class="oloc">';
if($locationVar==NULL || $locationVar!=$field['office-location'][1]) {
echo '<a name="' . strtolower(str_replace(' ', '-', $field['office-location'][1])) . '"></a><h3>' . $field['office-location'][1] . '</h3>';
$locationVar = $field['office-location'][1];
} else {
echo "<br />";
}
if($field['office-gm'][1]){
echo '<div class="gm"><img src="http://maps.googleapis.com/maps/api/staticmap?center=' . $field['office-gm'][1] . '&zoom=9&size=250x250&markers=color:blue|label:A|' . $field['office-gm'][1] . '&sensor=false"></div>';
}
if($field['office-name'][1]){
echo '<strong>' . $field['office-name'][1] . '</strong><br /><br />';
}
if($field['office-phone'][1]){
echo 'Phone: ' . $field['office-phone'][1] . '<br />';
}
if($field['office-fax'][1]){
echo 'Fax: ' . $field['office-fax'][1] . '<br />';
}
if($field['office-address'][1]){
echo '<br />Address:<br />' . strip_tags($field['office-address'][1], '<br><br />') . '<br />';
}
if($field['office-webpage'][1]){
echo 'Web: ' . 'Office Webpage<br />';
}
if($field['office-email'][1]){
echo 'Email: ' . 'Office Email<br />';
}
if($field['office-emp'][1]){
echo 'Jobs: ' . 'Employment Application<br />';
}
if($field['office-fb'][1]){
echo 'Facebook: ' . 'Facebook<br />';
}
if($field['office_office_twitter'][1]){
echo 'Twitter: ' . 'Twitter<br />';
}
echo '</div>';
}
For cases like these you can use a CachingIterator and the hasNext() method:
$fields = get_group('Offices');
$it = new CachingIterator(new ArrayIterator($fields));
foreach($it as $field)
{
...
if (!$it->hasNext()) echo 'Last:';
...
}
Put every echo in a var, this class definition in a other var. Then at the end of your foreach you check like so:
$i = 0;
foreach(...
if( $i == count($fields) ) { // change class }
Try this
$i = 0;
$total = count($fields);
$final = false;
foreach($fields as $field){
$i++;
$final = ($i + 1 == $total)? true : false;
if($final)
echo'<div class="NEW_CLASS">';
else
echo'<div class="oloc">';
....
}
First you should get the total count of the offices so that when you are on the last iteration, you can do something about it.
$fields = get_group('Offices');
$fields_count = count($fields);
$i = 0;
foreach ($fields as $field) {
$is_final = ++$i == $fields_count;
echo '<div class="oloc' . ($is_final ? ' oloc-final' : '') . '">';
[...]
}
I have used to the Rackspace API to upload files to the RackSpace cloud. But this method seems to be a little on the slow side. Is there a better or faster way to upload a file to the cloud(curl, http adapters, etc)?
I am currently uploading with PHP and using the provided API.
Here is my solution how to make it fast:
I'm uploading only missing files using simple PHP script below. Thanks to it I do it in just one click and in just a few seconds.
PHP source code:
function UploadMissingFilesToRackFileCDN($file_paths_to_upload, $b_force_upload = false)
{
include_once("cloudfiles.php");
// Connect to Rackspace
$username = cloudfile_username; // username
echo "Connecting to CDN..." . date("H:i:s") . "<br>"; ob_flush();
$key = cloudfile_api_key; // api key
$auth = new CF_Authentication($username, $key);
$auth->authenticate();
$conn = new CF_Connection($auth);
echo " Connected!" . date("H:i:s") . "<br>"; ob_flush();
// Get the container we want to use
$container_name = 'vladonai';//'test_container';
echo "Obtaining container $container_name..." . date("H:i:s") . "<br>"; ob_flush();
$container = $conn->get_container($container_name);
echo " The container is obtained." . date("H:i:s") . "<br>"; ob_flush();
if (!$b_force_upload)
{
echo "Receiving container objects list..." . date("H:i:s") . "<br>"; ob_flush();
$existing_object_names = $container->list_objects();
$existing_files_count = count($existing_object_names);
echo " Objects list obtained: $existing_files_count." . date("H:i:s") . "<br>"; ob_flush();
$existing_object_names_text .= "\r\n";
foreach ($existing_object_names as $obj_name)
{
$existing_object_names_text .= $obj_name . "\r\n";
}
}
// upload files to Rackspace
$uploaded_file_n = 0;
$skipped_file_n = 0;
$errors_count = 0;
foreach ($file_paths_to_upload as $localfile_path => $file_info)
{
$filename = basename($localfile_path);
if (!file_exists($localfile_path))
{
echo "<font color=red>Error! File $localfile_path doesn't exists!</font>" . date("H:i:s") . "<br>"; ob_flush();
$errors_count ++;
} else
if (is_dir($localfile_path))
{
//simply skip it
} else
if (strpos($existing_object_names_text, "\r\n" . $filename . "\r\n") !== false)
{
//file is already uploaded to CDN (at least file name is present there). Would be good to have date/size checked, but CDN api has no such feature
//echo "<font color=gray>Skipped file $localfile_path - it already exists!</font><br>"; ob_flush();
$skipped_file_n ++;
} else
{
echo "<font color=green>Uploading file $localfile_path (file #$uploaded_file_n)..." . date("H:i:s") . "</font><br>"; ob_flush();
try
{
$object = $container->create_object($filename);
$object->load_from_filename($localfile_path);
$uploaded_file_n ++;
}
catch (Exception $e)
{
echo "<font color=red>Error! Caught exception: ", $e->getMessage(), " on uploading file <strong>$localfile_path</strong>!</font>" . date("H:i:s") . "<br>"; ob_flush();
$errors_count ++;
}
}
// if ($uploaded_file_n >= 10)
// break;
}
echo "Done! $uploaded_file_n files uploaded. Disconnecting :)" . date("H:i:s") . "<br>"; ob_flush();
echo "Skipped files: $skipped_file_n<br>"; ob_flush();
if ($errors_count > 0)
echo "<font color=red>Erorrs: $errors_count</font><br>"; ob_flush();
}
function UploadChangedImagesToRackFileCDN($b_force_upload = false)
{
$exclude = array
(
'.',
'..',
'*.html',
'*.htm',
'*.php',
'*.csv',
'*.log',
'*.txt',
'*.cfg',
//'*sub/forum/files/*',
);
$files_array_images = get_dirlist("/var/www/html/vladonai.com/images/", '*', $exclude, false);
$files_array = array_merge(get_dirlist("/var/www/html/vladonai.com/js/", '*', $exclude, false), $files_array_images);
UploadMissingFilesToRackFileCDN($files_array, $b_force_upload);
}
function get_dirlist($path, $match = '*', $exclude = array( '.', '..' ), $b_short_path = true)
{
$result = array();
if (($handle = opendir($path)))
{
while (false !== ($fname = readdir($handle)))
{
$skip = false;
if (!empty($exclude))
{
if (!is_array($exclude))
{
$skip = fnmatch($exclude, $fname) || fnmatch($exclude, $path . $fname);
} else
{
foreach ($exclude as $ex)
{
if (fnmatch($ex, $fname) || fnmatch($ex, $path . $fname))
$skip = true;
}
}
}
if (!$skip && (empty($match) || fnmatch($match, $fname)))
{
$file_full_path_and_name = $path . $fname;
//echo "$file_full_path_and_name<br>";
$b_dir = is_dir($file_full_path_and_name);
$b_link = is_link($file_full_path_and_name);
$file_size = ($b_dir || $b_link) ? 0 : filesize($file_full_path_and_name);
$file_mod_time = ($b_dir || $b_link) ? 0 : filemtime($file_full_path_and_name);
$new_result_element = array();
if ($b_short_path)
$file_name = str_replace("/var/www/html/vladonai.com/", "", $file_full_path_and_name);//'[' . str_replace("/var/www/html/vladonai.com/", "", $file_full_path_and_name) . ']';
else
$file_name = $file_full_path_and_name;
$result[$file_name] = array();
$result[$file_name]['size'] = $file_size;
$result[$file_name]['modtime'] = $file_mod_time;
if ($b_dir && !$b_link)
{
//recursively enumerate files in sub-directories
$result = array_merge(get_dirlist($file_full_path_and_name . "/", $match, $exclude, $b_short_path), $result);
}
}
}
closedir($handle);
}
return $result;
}
I have this web service http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Social/Login?Token=210029242357724|fd4eef8a839f24db2a9fedcd.1-100001001235070|Nro7dAY411DJRn7E8zB6MOXHjq8
And I'm having problems catching some values like:
clubId, clubName, clubLogo, relationType, and dateAdded.
I just don't know how to handle the array.
My code:
<?php
function getUserInfo() {
$json = file_get_contents('http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Social/Login?Token=210029242357724|fd4eef8a839f24db2a9fedcd.1-100001001235070|Nro7dAY411DJRn7E8zB6MOXHjq8');
$data = json_decode($json, TRUE);
$v= $data['data'];
$_SESSION['userinfid'][] = $v['id'];
$_SESSION['userinfnickname'][] = $v['nickname'];
$_SESSION['userinfvisibility'][] = $v['visibility'];
$_SESSION['userinffirstname'][] = $v['first_name'];
$_SESSION['userinflastname'][] = $v['last_name'];
$_SESSION['userinfgender'][] = $v['gender'];
$_SESSION['userinfdialect'][] = $v['dialect'];
$_SESSION['userinfstatus'][] = $v['status'];
$_SESSION['userinfadmissiondate'][] = $v['admission_date'];
$_SESSION['userinflastaccess'][] = $v['last_access'];
$_SESSION['userinfusername'][] = $v['username'];
$_SESSION['userinfpoints'][] = $v['points'];
$_SESSION['userinfranking'][] = $v['ranking'];
$_SESSION['userinfsessionID'][] = $v['sessionID'];
$_SESSION['userinfpublicProfile'][] = $v['publicProfile'];
$_SESSION['userinfemail'][] = $v['email'];
$_SESSION['userinfmobile'][] = $v['mobile'];
$_SESSION['userinfimageURL'][] = $v['imageURL'];
$_SESSION['userinfclubURL'][] = $v['clubURL'];
$_SESSION['userinfcontact'][] = $v['contacts']['contact'];
$_SESSION['userinfcontactType'][] = $v['contacts']['contactType'];
$_SESSION['userinfisdefault'][] = $v['contacts']['is_default'];
$_SESSION['userinfclubId'][] = $v['clubs']['clubId'];
$_SESSION['userinfclubName'][] = $v['clubs']['clubName'];
$_SESSION['userinfclubLogo'][] = $v['clubs']['clubLogo'];
$_SESSION['userinfrelationType'][] = $v['clubs']['relationType'];
$_SESSION['userinfdateAdded'][] = $v['clubs']['dateAdded'];
}
getUserInfo();
echo 'IDClube: ' . $_SESSION['userinfclubId'][0] . '<br />';
echo 'NomeClube: ' . $_SESSION['userinfclubName'][0] . '<br />';
echo 'LogoClube: ' . $_SESSION['userinfclubLogo'][0] . '<br />';
echo 'RelationType: ' . $_SESSION['userinfrelationType'][0] . '<br />';
echo 'DataAdicionado: ' . $_SESSION['userinfdateAdded'][0] . '<br />';
?>
And if there is only one value for each key of session then
<?php
function getUserInfo() {
$json = file_get_contents('http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Social/Login?Token=210029242357724|fd4eef8a839f24db2a9fedcd.1-100001001235070|Nro7dAY411DJRn7E8zB6MOXHjq8');
$data = json_decode($json, TRUE);
$v= $data['data'];
foreach($v as $key => $value)
{
$_SESSION['userinf'.$key] = $value;
}
}
getUserInfo();
echo 'IDClube: ' . $_SESSION['userinfclubs']['clubId'] . '<br />';
echo 'NomeClube: ' . $_SESSION['userinfclubs']['clubName'] . '<br />';
echo 'LogoClube: ' . $_SESSION['userinfclubs']['clubLogo'] . '<br />';
echo 'RelationType: ' . $_SESSION['userinfclubs']['relationType'] . '<br />';
echo 'DataAdicionado: ' . $_SESSION['userinfclubs']['dateAdded'] . '<br />';
Be careful,there's more than one club in clubs, so you'll need to do something like this :
foreach ($v['clubs'] as $value) {
$_SESSION['userinfclubId'][] = $value['clubId'];
$_SESSION['userinfclubName'][] = $value['clubName'];
$_SESSION['userinfclubLogo'][] = $value['clubLogo'];
$_SESSION['userinfrelationType'][] = $value['relationType'];
$_SESSION['userinfdateAdded'][] = $value['dateAdded'];
}